in reply to Help me make a test case for Math::BigFloat
I don't think this is a bug, just an artifact of the transition between IEEE float constants and bignum objects:
c:\>perl -MMath::BigFloat -wle"print Math::BigFloat->new(1) - Math::BigFloat->new( .999999999999 +999 )" 0.000000000000001 c:\>perl -MMath::BigFloat -wle"print Math::BigFloat->new(1) - Math::BigFloat->new( .999999999999 +9999 )" 0 c:\>perl -MMath::BigFloat -wle"print Math::BigFloat->new(1) - Math::BigFloat->new('.999999999999 +9999')" 0.0000000000000001 c:\>perl -MMath::BigFloat -wle"print Math::BigFloat->new(1) - Math::BigFloat->new('.999999999999 +99999999999')" 0.00000000000000000000001
Notice how once you get beyond ~16 decimal places in the constant, the result is wrong. However, if you pass the constant as a string rather than allowing Perl to convert it to a IEEE float before passing it to bignum, the accuracy is retained.
So the answer is to use string constants to initialise your bignum objects.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Help me make a test case for Math::BigFloat
by fizbin (Chaplain) on Mar 07, 2006 at 02:37 UTC | |
by BrowserUk (Patriarch) on Mar 07, 2006 at 04:55 UTC | |
by spiritway (Vicar) on Mar 07, 2006 at 06:45 UTC | |
by fizbin (Chaplain) on Mar 07, 2006 at 07:01 UTC | |
by spiritway (Vicar) on Mar 07, 2006 at 07:09 UTC | |
|