users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Iteratively calling Prolog from C


From: Lindsey Spratt
Subject: Re: Iteratively calling Prolog from C
Date: Thu, 17 Jul 2003 10:33:47 -0500


On Thursday, July 17, 2003, at 10:15  AM, Daniel Dudley wrote:
It would appear that gprolog does have something seriously
wrong with its implementation. :-(

    Win-Prolog 4.320           ECLiPsE 5.6
    (no big number library)    (has big number library)
    -----------------------    ------------------------
    ?- factorial(17,F).        ?- factorial(17, F).
    F = 355687428096000        F = 355687428096000
                               Yes (0.00s cpu)

    ?- factorial(18,F).        ?- factorial(18, F).
    F = 6.402373705728E015     F = 6402373705728000
                               Yes (0.00s cpu)

    GNU Prolog
    ----------
    ?- factorial(17,F).
    F = 248348672
    yes

    ?- factorial(18,F).
    F = 175308800
    yes

This is an integer/float issue. If you force all of the factorial calculations to be done using floats, then you get the right answers in gprolog.

factorial(N, F) :-
        FN is float(N),
        factorial(FN, 1.0, F).


factorial(1.0, N, N) :- !.

factorial(N, J, F) :-
        N > 1,
        K is N - 1.0,
        L is N * J,
        factorial(K, L, F).

?- factorial(17, F)
Success
F = 355687428096000.0

Lindsey Spratt
http://homepage.mac.com/lspratt






reply via email to

[Prev in Thread] Current Thread [Next in Thread]