Re: (- 12.1 12) returns 0.0999999999999996

From: Bill Sommerfeld <sommerfeld_at_apollo.hp.com>
Date: Thu, 01 Jun 1995 13:16:05 -0400

   (- 4.1 4) => 0.0999999999999996
        but
   (- 3.1 3) => 0.1
   
   The answer is identical in STk/Snow 2.1.6 compiled under Linux or
   SunOS.

.. as well as on other languages & platforms using binary floating
point.

On HP-UX, gdb reports:

(gdb) p 4.1-4
$1 = 0.099999999999999645
(gdb) p 3.1-3
$2 = 0.10000000000000009

what's going on here is that 1/10 is a repeating fraction when
expressed in binary (just like 1/3 is in decimal) and therefore cannot
be expressed exactly.
   
   I haven't find nobody reporting this fenomena. Is this well known?

Very well known; it's a direct consequence of using binary
floating-point arithmetic. You'll see things like this if you ask to
see all the available digits of a number, regardless of the language.

                                                - Bill
Received on Thu Jun 01 1995 - 19:20:02 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST