Just another Perl shrine | |
PerlMonks |
Re: what did I just see..?by ikegami (Patriarch) |
on Mar 22, 2021 at 08:05 UTC ( [id://11130079]=note: print w/replies, xml ) | Need Help?? |
1/10, 8/10 and 1/100 are all periodic numbers in binary just like 1/3 is a periodic number in decimal.
As such, they can't be accurately represented as floating-point numbers.
See What Every Computer Scientist Should Know About Floating-Point Arithmetic. Solution:
This will prevent error from accumulating, keeping it under the default rounding. You could also perform more forgiving rounding than the default. Or you could avoid floating point numbers entirely (e.g. using rational number libraries). Seeking work! You can reach me at ikegami@adaelis.com
In Section
Seekers of Perl Wisdom
|
|