Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: Math::FixedPrecision and bignum clash

by McA (Priest)
on Oct 08, 2014 at 14:41 UTC ( #1103180=note: print w/replies, xml ) Need Help??


in reply to Re^2: Math::FixedPrecision and bignum clash
in thread Math::FixedPrecision and bignum clash

Hi mje,

IMHO your assumption of rounding in Math::FixedPrecision is not true. When you have a look at the constructor of Math::FixedPrecision you'll see the the value 3.145 having 3 digits after the point will be rounded to two digits (what is given as second parameter) with ffround (line 80 of sources).

The effect you see is caused by mathematical (odd) rounding (default of Math::BigFloat) with your example. Have a look at these two examples:

#!/usr/bin/perl use strict; use warnings; use 5.010; use Math::FixedPrecision; my $b = Math::FixedPrecision->new(3.145, 2); say $b; # output: 3.14 my $c = Math::FixedPrecision->new(3.155, 2); say $c; # output 3.16

UPDATE: Added output for the reader.

Regards
McA

Replies are listed 'Best First'.
Re^4: Math::FixedPrecision and bignum clash
by mje (Curate) on Oct 08, 2014 at 15:16 UTC

    Yes, thanks. I was wrong and it is using bankers rounding. Looks at the last digit being kept and if odd rounds down and even rounds up so long as first digit beyond the precision is >= 5. That is another bug in the code we're using here which does not want bankers rounding.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1103180]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2021-01-24 13:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?