in reply to Equality checking for strings AND numbers
$eps should be the fractional closeness e.g. 0.000000001 would invoke a fractional threshold of a billionth.sub fromp { my ( $x, $y, $eps) = @_; ( abs( ($y - $x ) / ( $x || $y || return (1) ) ) < $eps ); }
The chain of ||s ensures that either the divisor is non-zero or division is prevented by returning 1 where both are 0 (therefore equal).
^M Free your mind!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Equality checking for strings AND numbers
by Anonymous Monk on Jul 16, 2007 at 23:33 UTC |