bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with comparing and adding


From: Hans-Bernhard Broeker
Subject: Re: Problem with comparing and adding
Date: 7 Mar 2006 17:52:42 GMT

Lec Maj <address@hidden> wrote:
> I ran across a problem with comparing 2 numbers while adding. 

Not really.  You just ran into one of the oldest problems unsuspecting
newbies have with floating-point numbers on computers.  Somebody roll
the drums please, and then we'll all recite in chorus:

        In computing, 10.0 time 0.1 is hardly ever 1.0

[Say this a couple of times until it sinks in.]

> I am not sure if this is suppose to be like this or if it is a bug.

Neither.  It's allowed to be like this, but not strictly required to.

> As you will notice, either way the answer is 0.3, 

There's the core of your problem: the answer is *not* 0.3.  It's
hopefully quite close to 0.3, but not equal to it.  That's because 0.3
is not a number your computer can wrap its binary mind around any more
easily than you probably could wrap yours around 1/3=0.333333... back
then, in school.

-- 
Hans-Bernhard Broeker (address@hidden)
Even if all the snow were burnt, ashes would remain.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]