[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Iteratively calling Prolog from C
From: |
Daniel Dudley |
Subject: |
Re: Iteratively calling Prolog from C |
Date: |
Thu, 17 Jul 2003 17:53:33 +0200 |
Lindsey Spratt wrote:
> 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
Yes, that's was my first impression, Lindsey. However, it
doesn't explain:
?- factorial(12,F).
F = -57869312
yes
A signed integer on a 32-bit platform is -2147483648 to
2147483647. Compare this with Win-Prolog and ECLiPSe:
?- factorial(12,F).
F = 479001600
?- factorial(12, F).
F = 479001600
Yes (0.00s cpu)
Daniel
- Re: Iteratively calling Prolog from C, (continued)
- Re: Iteratively calling Prolog from C, Manuel Carro, 2003/07/18
- Re: Iteratively calling Prolog from C, Daniel Dudley, 2003/07/16
- Re: Iteratively calling Prolog from C, Daniele Peri, 2003/07/17
- A note of belated politeness., tvetunge, 2003/07/17
- Re: Iteratively calling Prolog from C, Daniel Dudley, 2003/07/17
- Re: Iteratively calling Prolog from C, Daniele Peri, 2003/07/17
- Re: Iteratively calling Prolog from C, Daniel Dudley, 2003/07/17
- Re: Iteratively calling Prolog from C, Daniel Dudley, 2003/07/17
- Re: Iteratively calling Prolog from C, Daniel Dudley, 2003/07/17
- Re: Iteratively calling Prolog from C, Lindsey Spratt, 2003/07/17
- Re: Iteratively calling Prolog from C,
Daniel Dudley <=
- Re: Iteratively calling Prolog from C, Lindsey Spratt, 2003/07/17
- Re: Iteratively calling Prolog from C, Daniel Dudley, 2003/07/17
- Re: Iteratively calling Prolog from C, Lindsey Spratt, 2003/07/17
- Re: Iteratively calling Prolog from C, Alexandre Tessier, 2003/07/17
- Re: Iteratively calling Prolog from C, Daniele Peri, 2003/07/17
- Re: Iteratively calling Prolog from C, Daniel Dudley, 2003/07/17
- Re: Iteratively calling Prolog from C, Daniele Peri, 2003/07/17
- Re: Iteratively calling Prolog from C, Bartek Wilczynski, 2003/07/17
- Re: Iteratively calling Prolog from C, Daniel Dudley, 2003/07/17
- Re: Iteratively calling Prolog from C, Daniele Peri, 2003/07/18