Kent Fredric wrote: >Isn't this a moot point because doing "==" on floats is considered a >bad idea at best anyway? No, == can be used perfectly correctly on floating-point values. As with everything else around floating-point rounding, it does need some consideration of the specific algorithm being used. Note that where one side of the comparison is an integer, in the context of Perl programming it's quite likely that an exact comparison is required. > You generally want "within >tolerance X", for which stringification serves as a reasonable proxy, Stringification just gives you an incoherently reduced precision. The tolerance that's required has to be determined by consideration of the specific algorithm. String equality is not a good default tolerance; I think it's a worse default than numerical equality. >Yes, bignum is probably overkill here, but all I'm doing is using it >to make sure nextup(42) stringifies to its full precision. Actually it doesn't stringify the exact value. It's not even correct to the precision that it gives: $ perl -Mbignum -MData::Float=nextup -lwe 'print nextup(42); printf "%.50f\n", nextup(42)' 42.000000000000007105427357600992 42.00000000000000710542735760100185871124267578125000 (The printf output is exact.) >nextup(42) ~~ within( 42, sigfig => 20, ) That's a much better arrangement. -zeframThread Previous | Thread Next