Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: String comparison of numbers

by philcrow (Priest)
on Mar 09, 2006 at 15:21 UTC ( [id://535409]=note: print w/replies, xml ) Need Help??


in reply to String comparison of numbers

When comparing floating point numbers, you should either round them both to the same precision and compare or subtract one from the other and see if the abs of the result is small:
if ( abs( $number1 - $number2 ) < $something_tiny ) { print "all is well.\n"; }
Numerical analysts usually prefer the latter many programmers prefer the former.

Phil

Replies are listed 'Best First'.
Re^2: String comparison of numbers
by dsb (Chaplain) on Mar 10, 2006 at 20:14 UTC
    Well, the two arguements need to be exactly identical. So, if that means using a truncated version of the rand() value, then that's what I'll do. I'm more curious as to if my theory is correct.


    dsb
    This @ISA my( $cool ) %SIG

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-25 06:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found