Float division error

Juan Pablo Suarez <[email protected]> Wed, 16 Apr 2014 14:35:51 +0200
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <CAGT_hkvsWEXXC=HcM-L3i+050n-rc=wCuc0HR99T=Knm0h3QcA@mail.gmail.com>
Hi.

I think there's a bug in prolog for float division


Version :
Welcome to SWI-Prolog (Multi-threaded, 32 bits, Version 7.1.11-41-g4da729e)
Copyright (c) 1990-2014 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

Problem :

3 ?- Val1 = 39.2, MinV = 37.0, MaxV = 5.0, Val2 is ((Val1-MinV)/MaxV).
Val1 = 39.2,
MinV = 37.0,
MaxV = 5.0,
Val2 = 0.44000000000000056.


The answer should be 0.44 for Val2


I have the same problem with 64 bits Version

Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.1.11-41-g4da729e)
Copyright (c) 1990-2014 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

1 ?- Val1 = 39.2, MinV = 37.0, MaxV = 5.0, Val2 is ((Val1-MinV)/MaxV).
Val1 = 39.2,
MinV = 37.0,
MaxV = 5.0,
Val2 = 0.44000000000000056.

That does not change if I try
Val1 = 39.2, MinV = 37.0, MaxV = 5.0, Val2 is
float((float(Val1)-float(MinV))/float(MaxV)).

Is this behavior normal ?


Kind regards.
Pablo
-------------- next part --------------
HTML attachment scrubbed and removed