Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^2: False positive on inequality comparison

by Nkuvu (Priest)
on Apr 06, 2009 at 17:21 UTC ( #755802=note: print w/replies, xml ) Need Help??

in reply to Re: False positive on inequality comparison
in thread False positive on inequality comparison

That's something I would never have thought of. But it worked perfectly. String comparison found no difference -- even when a numeric comparison did find a difference. Thanks for the idea.

  • Comment on Re^2: False positive on inequality comparison

Replies are listed 'Best First'.
Re^3: False positive on inequality comparison
by BrowserUk (Pope) on Apr 06, 2009 at 19:31 UTC

    Using string comparison on floats is dangerous, unless you don't care if the floats are actually different!

    As this shows in the last line, Perl's default stringification for floats will only show you 6 decimal places of precision, anything beyond that accuracy and you are just pretending the are the same.

    $first = unpack 'd', pack 'b64', '1001110001010011100010111001000010000101000001010110011000000010';; $second = unpack 'd', pack 'b64', '1010110001010011100010111001000010000101000001010110011000000010';; printf "%f %f :> %17.17f\n", $first, $second, $first - $second;; 181.019658 181.019658 :> 0.00000000000011369

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://755802]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2017-03-30 03:50 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (353 votes). Check out past polls.