Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: Equality checking for strings AND numbersby mr_mischief (Monsignor) |
on Jul 16, 2007 at 01:47 UTC ( [id://626758]=note: print w/replies, xml ) | Need Help?? |
Is there a maximum precision which any of the numbers will ever be? If so, and you want any differences to be noted as you responded to BrowserUk, why not promote all things that look like numbers to some ridiculously high precision using sprintf() and then compare everything based on strings? (edit: fixed this sentence for grammar)
You'll end up with roundoff errors on reals from the precision boost, but for perfectly equivalent values in the first place you should get the same roundoff errors. It's not like you're accumulating the errors through arithmetic with the values, since you're just promoting them and then immediately doing the comparison. The old adage about not testing floats for equality doesn't really apply here, unless you do want to allow a range of difference in the original inputs. The main issue with this as I see it is that while you should be okay for a single environment, you'll potentially be dealing with different values for the floats if you try to take the promoted values as output from more than one software environment.
In Section
Seekers of Perl Wisdom
|
|