|
Posted by szr on April 2, 2008, 11:53 am
Please log in for more thread options RedGrittyBrick wrote:
> vivekanand.naik@gmail.com wrote:
>> printf("%.32g\n",0.99999999976716936);
>>
>> Perl 5.6.1 output:
>> 0.99999999976716936 --> GOOD
>>
>> Perl 5.8.6 output:
>> 0.99999999976716925 --> ERROR
>>
>>
>> Any reason for such mismatch ?
>> Please let me know how to avoid that or any alternative approach if
>> any.
>>
>
> print Math::BigFloat->new("0.99999999976716936")->bstr();
The version of Math::BigFloat that shipped with 5.6.1, which the op
seems to need, doesn't seem to support ->bstr()
$ perlall -MMath::BigFloat -e 'print
Math::BigFloat->new("0.99999999976716936")->bstr(), "\n";'
<perl5.10.0> 0.99999999976716936
<perl5.8.8 > 0.99999999976716936
<perl5.8.2 > 0.99999999976716936
<perl5.8.0 > 0.99999999976716936
Can't locate object method "bstr" via package "Math::BigFloat" (perhaps
you forgot to load "Math::BigFloat"?) at -e line 1.
<perl5.6.1 >
Perhaps ->ffround(17) could be used instead?
$ perl5.6.1 -MMath::BigFloat -e 'print
Math::BigFloat->new("0.99999999976716936")->ffround(-17), "\n";'
+99999999976716936E-17
You could always update your Math::* modules if you must use 5.6.1,
else, it would better to just install a newer Perl :-)
--
szr
|