Skip Menu |

This queue is for tickets about the bignum CPAN distribution.

Report information
The Basics
Id: 131399
Status: open
Priority: 0/
Queue: bignum

People
Owner: Nobody in particular
Requestors: andreashad2 [...] googlemail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: bug incrementing
Date: Thu, 9 Jan 2020 00:42:22 +0200
To: bug-bignum [...] rt.cpan.org
From: andreashad2 <andreashad2 [...] googlemail.com>
PLEASE see https://perlmonks.org/?node_id=11110997 for how this started and reported. 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"; prints: 1 i=10 2 i=10 3 i=10 4 i=10 5 i=10 6 i=10 7 i=20 8 i=30 PLEASE see 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"; prints: 1 i=10 2 i=10 3 i=10 4 i=10 5 i=10 6 i=10 7 i=20 8 i=30 PLEASE see https://perlmonks.org/?node_id=11110997 for how this started and reported. bw, bliako@cpan.org
Subject: Re: [rt.cpan.org #131399] bug incrementing
Date: Thu, 09 Jan 2020 19:31:45 +0100
To: bug-bignum [...] rt.cpan.org
From: Te <nospam-abuse [...] bloodgate.com>
On 2020-01-08 23:42, andreashad2 via RT wrote: Show quoted text
> Wed Jan 08 17:42:58 2020: Request 131399 was acted upon. > Transaction: Ticket created by andreashad2@googlemail.com > Queue: bignum > Subject: bug incrementing > Broken in: (no value) > Severity: (no value) > Owner: Nobody > Requestors: andreashad2@googlemail.com > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=131399 > > > > PLEASE see https://perlmonks.org/?node_id=11110997 > > for how this started and reported. > > 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);
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
to. 09. jan. 2020 13.40.39 skrev nospam-abuse@bloodgate.com: Show quoted text
> > 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
Note that this works differently when the value is represented internally as a Math::BigFloat rather than at Math::BigInt: $ perl -Mbignum=p,1 -wle '$i = 1; print $i + 123456788.001,"\n"' 123456789 $ perl -Mbignum=p,2 -wle '$i = 1; print $i + 123456788.001,"\n"' 123456790 I assume this is a bug. (I also find it odd and inconsistent that higher precision gives less accuracy, but that is a design decision that it is probably too late to change now.)
Subject: Re: [rt.cpan.org #131399] bug incrementing
Date: Fri, 21 Feb 2020 19:41:00 +0100
To: bug-bignum [...] rt.cpan.org
From: Te <nospam-abuse [...] bloodgate.com>
On 2020-01-25 08:53, Peter John Acklam via RT wrote: Show quoted text
> Queue: bignum > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=131399 > > > to. 09. jan. 2020 13.40.39 skrev nospam-abuse@bloodgate.com:
>> >> 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
> > Note that this works differently when the value is represented > internally as a Math::BigFloat rather than at Math::BigInt: > > $ perl -Mbignum=p,1 -wle '$i = 1; print $i + 123456788.001,"\n"' > 123456789 > > $ perl -Mbignum=p,2 -wle '$i = 1; print $i + 123456788.001,"\n"' > 123456790 > > I assume this is a bug. > > (I also find it odd and inconsistent that higher precision gives less > accuracy, but that is a design decision that it is probably too late > to change now.)
Well, "precision" and "accuracy" are not interchangable, but mutally exclusive concepts here. They both allow different round operations. In hindsight it might have been better to invent completely new terms, but to be fair, the original modules already had a certain concept included and I just extended it. Also, the documentation in Math::BigInt states: The string output (of floating point numbers) is padded with zeros: Initial value P A Result String ------------------------------------------------------------ 1234.01 -3 1000 1000 1234 -2 1200 1200 1234.5 -1 1230 1230 1234.001 1 1234 1234.0 1234.01 0 1234 1234 1234.01 2 1234.01 1234.01 1234.01 5 1234.01 1234.01000 (Which incidentily means higher P => higher accuracy) So, 1 + 123456788.001 with P=2 should result in "123456789.00", which is not what your example shows. The code seems to be exactly backwards: $ perl -Mbignum=p,-2 -wle '$i = 1; print $i + 123456788.001,"\n"' 123456789.00 $ perl -Mbignum=p,2 -wle '$i = 1; print $i + 123456788.001,"\n"' 123456790 That smells like something is buggy. Best wishes, Tels