in reply to Re^5: Why am I losing accuracy?
in thread Why am I losing accuracy?

The maintainer of bigint replied to filing a bug:

Here is your problem: p=>1 specifies a precision of 1. See these for comparisation: $ perl -Mbignum=p,1 -wle '$i = 1; print $i + 123456788,"\n"' 123456790 $ perl -Mbignum=p,2 -wle '$i = 1; print $i + 123456788,"\n"' 123456800 $ perl -Mbignum=p,5 -wle '$i = 1; print $i + 123456788,"\n"' 123500000 Looks to me it works as designed. Here is the same with different accuracy values: $ perl -Mbignum=a,1 -wle '$i = 1; print $i + 123456788,"\n"' 100000000 $ perl -Mbignum=a,2 -wle '$i = 1; print $i + 123456788,"\n"' 120000000 $ perl -Mbignum=a,3 -wle '$i = 1; print $i + 123456788,"\n"' 123000000 and with negative values of p: $ perl -Mbignum=p,-3 -wle '$i = 1; print $i + 123456789.1,"\n"' 123456790.100 $ perl -Mbignum=p,-6 -wle '$i = 1; print $i + 123456789.1,"\n"' 123456790.100000 Best regards, Tels

Replies are listed 'Best First'.
Re^7: Why am I losing accuracy?
by bliako (Abbot) on Jan 12, 2020 at 11:31 UTC

    I am thinking to reply with maybe bignum should be put under the ACME tree? but holding back thinking I am too extreme. I still can't digest that forloop behaviour. Fair enough it's a design choice but the unawary, common-sense Perl user is in for a big surprise when trying to ... increase precision.

      Fair enough it's a design choice but the unawary, common-sense Perl user is in for a big surprise when trying to ... increase precision.

      I'm a little confused (about the whole subthread, actually, as well as this one) - isn't p=>1 explicitly asking for reduced precision?

        haukex:

        Yes, it's asking for reduced precision, but I think that bliako is surprised as I am by the sign of the precision argument. The various number formatting tools I've used have given me the expectation that a positive number indicates the number of digits I want to retain to the right of the decimal place, rather than to the left.

        ...roboticus

        When your only tool is a hammer, all problems look like your thumb.