Re: Embarrassing Arithmetic behaviour

Michael Richter <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <CAGKutLtozAUzDPb0J=kBWX+XUhumkZwndTS+4i5kn8PxRZS4cQ@mail.gmail.com>
On 19 February 2014 18:04, j.gressier <[email protected]> wrote:
>
> XP 32 bits (Athlon 64 bits)  and W7 32 bits. Same behaviour on both PCs.
> Swi-Prolog 6.6.1
>
>
> 15 ?- A is 4.9 * 10000.
> A = 49000.0.
>
> -------------------------------------------
> 16 ?- A is 4.9 * 100000.
> A = 490000.00000000006.
> -------------------------------------------
>
> Whereas :
>
> 17 ?- A is 3.9 * 100000.
> A = 390000.0.
>
> and :
>
> 18 ?- A is 4.9 * 1000000.
> A = 4900000.0.
>
>
> (No problem with Swi-Prolog 5.8 under Linux or Windows)
>

http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

General conclusion: don't use floating point.  It doesn't ever behave the
way you expect unless you really know it inside and out.

-- 
"Perhaps people don't believe this, but throughout all of the discussions
of entering China our focus has really been what's best for the Chinese
people. It's not been about our revenue or profit or whatnot."
--Sergey Brin, demonstrating the emptiness of the "don't be evil" mantra.
-------------- next part --------------
HTML attachment scrubbed and removed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.