Re: Addition of Float Bug

From: <wh_at_icparc.ic.ac.uk>
Date: Sun 22 May 2005 01:39:17 PM GMT
Message-ID: <20050522133917.GA26270@tempest.icparc.ic.ac.uk>
Hi Huy,

On Sun, May 22, 2005 at 05:50:02AM -0700, Huy wrote:
> Second, I found a weird bug when adding two float
> numbers. Below is my transcript:
> 
> ---------------------
> [metis:/home/hpham]$ eclipse
> ECLiPSe Constraint Logic Programming System [kernel]
> Kernel and basic libraries copyright Cisco Technology
> Inc
> Academic licensing through Imperial College London,
> see legal/licence_acad.txt
> GMP library copyright Free Software Foundation, see
> legal/lgpl.txt
> For other libraries see their individual copyright
> notices
> Version 5.8 #78, Sat Jan  8 00:10 2005
> [eclipse 1]: +(-0.2, -2.7, X).
> 
> X = -2.9000000000000004
> Yes (0.00s cpu)
> [eclipse 2]:

There is no bug here - this is floating point arithmetic.  Try the same
computation in C (or your other favourite language) and get it to print the
result at *full* precision (i.e. enough precision to be sure that when you
read it back in you'll get exactly the same floating point number).

The lack of precision for floating point arithmetic is mentioned in passing
in the User Manual -> Arithmetic Evaluation -> Numeric Types and Type
Conversions, in the sections on Floating Point Numbers and Bounded Real
Numbers - in passing because we generally assume users know about this.  It
is covered in a little more detail in the Tutorial, in Chapter 9, "Working
with real numbers and variables."

Cheers,
Warwick
Received on Sun May 22 14:41:48 2005

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:36 PM GMT GMT