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