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

Still, I would like to find out what's going on in that loop and gets stuck to 10 !!!!

Yes - we've glossed over that and we (I, at least) should not have done so.
My (pathetic) excuse is that Math::BigInt is low priority for me.

Can you reproduce the behaviour ?
I can - on Windows 7, perl-5.30.0.

It's the use bignum (p => 1); line that causes the problem.
Change that line to merely use bignum; and that particular problem goes away.

Cheers,
Rob

Replies are listed 'Best First'.
Re^5: Why am I losing accuracy?
by bliako (Abbot) on Jan 08, 2020 at 22:33 UTC

    I don't mean to put pressure - I just leave this here for anyone.

    both of these fail with an infinite loop printing i=10 on linux fedora 30, perl 5.28.2. 10 and 15 are the min numbers to do this.

    use bignum (p=>1); for(my $i = 1;$i->blt(15);$i->binc()){ print "i=$i\n"; }
    for(my $i = 1;$i<=10;$i++){ print "i=$i\n"; }

    this shows to me that it is not the loop or the overloaded increment but that when p=>1 it thinks that it's adding that value divided by 10 or something

    my $i = 10; print "1 i=$i\n"; $i++; print "2 i=$i\n"; $i = $i + 1; print "3 i=$i\n"; $i = $i + 2; print "4 i=$i\n"; $i = $i + 3; print "5 i=$i\n"; $i = $i + 4; print "6 i=$i\n"; $i = $i + 5; print "7 i=$i\n"; $i = $i + 6 ; print "8 i=$i\n";
    1 i=10 2 i=10 3 i=10 4 i=10 5 i=10 6 i=10 7 i=20 8 i=30

    I have filed a bug to bigint

      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

        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.