It's not a Perl problem, it's the problem of representing a non-terminating series for base 2 using a finite number of binary digits. You are accustomed to seeing it in base ten when you try to represent 1/3rd, yet I hear no complaints that your ten counting fingers are malfunctioning. Your calculator gets it right by rounding to the eight or ten significant digits that you see on its little LCD display. In other words, it really doesn't get it right; it just covers up the ugliness. And, in fact, I see a nearly identical question every day in reference to C, C++, PHP, and myriad other programming languages over on StackOverflow. It's not a problem unique to Perl.
I understand that the "What every computer scientist should know..." article is a little beyond what someone who just wants to get the job done might want to digest. That's fine, the article goes into painful details. Try this response (shameless plug, I wrote it), which tries to spell it out in less technical terms: Re: shocking imprecision.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
Outside of code tags, you may need to use entities for some characters:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||