Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Strange (rounding?) problem

by alfie (Pilgrim)
on May 02, 2001 at 14:07 UTC ( #77279=note: print w/replies, xml ) Need Help??

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.


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://77279]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (1)
As of 2022-01-19 02:43 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (55 votes). Check out past polls.