Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Equality checking for strings AND numbers

by Moron (Curate)
on Jul 16, 2007 at 13:25 UTC ( #626838=note: print w/ replies, xml ) Need Help??


in reply to Equality checking for strings AND numbers

As halley indicated, an absolute Epsilon test doesn't work well for all kinds of data. What about fractional comparison? e.g,:

sub fromp { my ( $x, $y, $eps) = @_; ( abs( ($y - $x ) / ( $x || $y || return (1) ) ) < $eps ); }
$eps should be the fractional closeness e.g. 0.000000001 would invoke a fractional threshold of a billionth.

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!


Comment on Re: Equality checking for strings AND numbers
Download Code
Re^2: Equality checking for strings AND numbers
by Anonymous Monk on Jul 16, 2007 at 23:33 UTC
    Sorry halley, I missed your post on the absolute Epsilon test. Just throwing around ideas to use and didn't realize that one was already out on the table

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2014-10-23 00:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (122 votes), past polls