Rob.Svirskas at motorola.com
Wed Aug 1 16:43:10 CDT 2001
Your code is fine - the problem is just that numbers (floating point or otherwise) are stored in internal (binary) representation. The "extra digits" that you see tacked on the end are a consequence of how a floating point number is stored in binary format. The inconsistencies are compounded when you perform arithmetic operations. If you really need long floats, use Math::BigFloat. If it's precision you're worried about, check out Math::FixedPrecision. Both will be slow (compared to "straight math operations") due to overloading of arithmetic operators. Hope this helps.
From: Thomas Whitney [mailto:whitneyt at agcs.com]
Sent: Wednesday, August 01, 2001 2:16 PM
To: phoenix-pm-list at happyfunball.pm.org
Subject: Re: Phoenix.pm: Math
Here is the problem I was having last year. Just ran it again same problem. I am running on v5.6.0. I don't see anything wrong that I am doing.
Script started on Thu Aug 17 15:57:29 2000
peoblej at holodeck: cat bug.pl
my $result = 0.0;
$result = 0.07 * 10000.0;
printf "%40.35f\n", $result;
peoblej at holodeck: bug.pl
peoblej at holodeck: exit
script done on Thu Aug 17 15:57:44 2000
Scott Walters wrote:
> Hey Tom,
> Well, looking at Math::BigInt/BigFloat, they do everything in Perl by
> unpacking into an array from a string... something in C or Perl
> that minipulated it directly in its binary format would be much faster...
> what problems were you having with perls built in operators? Overflow?
> Precision? Don't know of anything offhand, and I assume you've searched
> CPAN... If you wanted to use a C library, Doug just did a demo on
> [what was that?] Embed, which makes it really easy to stick some C
> right in middle of your Perl.
> On Wed, 1 Aug 2001, Thomas Whitney wrote:
> > Hi All,
> > I am doing a lot of decimal arithmetic. I ran into problems using perl's standard arithmetic. Right now I am using Math::BigFloat, but it seems slow. Can anybody recommend a better module
> > Thanks
> > Tom
More information about the Phoenix-pm