Perl: the Markov chain saw | |
PerlMonks |
Re^2: int() functionby LanX (Saint) |
on Oct 24, 2020 at 16:05 UTC ( [id://11123122]=note: print w/replies, xml ) | Need Help?? |
> It does that for all floating point values - always to 15 decimal digits (unless perl's nvtype is other than "double") and always for a dubious reason. The mantissa of a double has 52 bits°, you need 50 bits to encode 15 decimal digits ( 2**10 =1024, so rule of thumb 10 bits for 3 decimals) So the last two bits are used for error correction, since they don't suffice to encode another decimal digit. Is it a good solution? Well I'd say appropriate for the era and not "for a dubious reason". Are there better approaches? Sure, but they are harder to implement and would have been quite slow back in the days. From my experience, >95% of the problems arise from calculating with currencies and the solution is obvious, calculate with integer cents and move the point only for output.
Cheers Rolf °) WP actually says 53 by using a spare bit redundancy , but tl;dr and this still fails to encode 16 decimals.
In Section
Seekers of Perl Wisdom
|
|