On 9/2/10 Thu  Sep 2, 2010  2:00 PM, "Jim" <j...@lowcarbfriends.com>
scribbled:

> On 9/2/2010 4:15 PM, Jim Gibson wrote:

>> My advice is to stay away from these modules unless you know what you are
>> doing. I find that double-precision floating-point arithmetic is always good
>> enough. I have been programming in scientific and technical fields for 40
>> years and have yet to need extended-precision arithmentic.
>> 
>> If, on the other hand, you are working with large, financial transactions or
>> cryptography, you may need these modules. If that is the case, however, you
>> probably shouldn't be looking for help on a Perl beginner's list.
>> 
>> I just do not want anybody to get the impression that these modules are
>> needed for accurate arithmetic in Perl and that standard Perl arithmetic
>> operations are inaccurate.
> 
> I'm open to more advice. How would you rewrite my original toy code?

I wouldn't. It doesn't contain any errors. What you are seeing is the
expected behavior. The internal representation of most floating-point
numbers is approximate. If you print out binary floating-point numbers at
enough precision you will see differences from decimal representations. If
you are using double-precision floating-point, the accuracy is about 16
decimal places. If you need more accuracy than that, then you need to use
extended precision. But those applications are rare.



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to