Skip Menu |

This queue is for tickets about the Math-BigInt CPAN distribution.

Report information
The Basics
Id: 22122
Status: resolved
Worked: 25 min
Priority: 0/
Queue: Math-BigInt

People
Owner: TELS [...] cpan.org
Requestors: leonerd-cpan [...] leonerd.org.uk
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.77
Fixed in: 1.78



Subject: Does not recognise octal constants
Consdier: use bigint; my $i = 0755; printf "%o oct, %d dec\n", $i, $i; This produces 1363 oct, 755 dec Rather than (without 'use bigint'): 755 oct, 493 dec I have determined this to be a bug in Math::BigInt's constructor: my $i = Math::BigInt->new( "0755" ); printf "%o oct, %d dec\n", $i, $i; 1363 oct, 755 dec Looking over the code, it appears that the "is this a decimal integer" regexp fails: if ((!ref $wanted) && ($wanted =~ /^([+-]?)[1-9][0-9]*\z/)) So the next thing it tries is the _split() function, which tries: return __from_hex($x) if $x =~ /^[\-\+]?0x/; # hex string return __from_bin($x) if $x =~ /^[\-\+]?0b/; # binary string Perhaps another line here should be added, return __from_oct($x) if $x =~ m/^[\-\+]?0/; # octal string and a suitable __from_oct function written? -- Paul Evans
I am sorry, but this cannot be implemented that way, because ->new("0123") must result in 123 for backwards compatibility reasons. However, one could add a from_octal() method. Would you write a patch for that?
Hm, after thinking about this, you are probably right: # perl -Mbignum -le 'print 0123 + 12' 135 # perl -le 'print 0123 + 12' 95 Best wishes, Tels
This issue has been fixed in the released v1.78. Thank you for your report, Tels