No such thing as a small change | |
PerlMonks |
Re^2: Filtering array of strings and numbersby syphilis (Archbishop) |
on Apr 30, 2016 at 01:49 UTC ( [id://1161940]=note: print w/replies, xml ) | Need Help?? |
this assumes that neither $string_or_number nor any of the elements of @strings_or_numbers are ever undef It also makes other (corner case) assumptions. For example things get a bit dubious when the numbers (barewords) 1.4142135623730951, 1.4142135623730952 and 1.4142135623730953 (on a perl whose NV is double) are subjected to stringwise and numeric comparisons: So it makes the assumption that this behaviour is as wanted - which, if you look closely, is rather unlikely. Perhaps (not guaranteed) the first two results are as wanted - even though the two barewords are mathematically unequal they do convert to identical doubles and strings. But the last 2 results are just bizarre, imo. That perl should stringify two different NVs to the same string is rather pathetic - and it happens because perl by default stringifies doubles to only 14 decimal digits. (Update : make that 15, not 14 - the trailing zero for my example values was stripped.) If, like in python, the default was 17 decimal digits (as some believe it should be) then the discrepancy of the last 2 results would not arise. (We can, of course work around this stringification problem using sprintf, but that just makes it messy.) BTW, the same problem arises with perls whose NVs are 'long double' or '__float128'. Perl simply does not stringify floating point values to enough decimal digits. Cheers, Rob
In Section
Seekers of Perl Wisdom
|
|