in reply to Strange (rounding?) problem

You need to define how much digits you count as significant. There are lots of examples where it's noted that you can't directly compare floats with each other. Do something along this lines:
print "The numbers $foo and $bar are significant different!" if (abs($foo - $bar) >= (10**-10));
Adjust the power to your likes.

Update: Of course it should be >=, thanks Eureka_sg. Somehow I seemed to have thought about using unless but wrote if instead...
--
use signature; signature(" So long\nAlfie");

Replies are listed 'Best First'.
Re: Re: Strange (rounding?) problem
by Eureka_sg (Monk) on May 02, 2001 at 14:30 UTC

    I believe what you are trying to say is:

    print "The numbers $foo and $bar are significant different!" if (abs($foo - $bar) >= (10**-10));

    Note the difference in the equality sign. : )

      The problem with this is that you have to know a priori what the range of your numbers is.

      suppose $foo = 1e-11 and $bar = 2e-11 your method will say they are not significantly different.

      Suppose $foo = 1.1e54 and $bar = 1.1e54 then you would want to say that they are not different, but it is quite possible that a stray bit would cause your method to say that they are different.

      iakobski