Subject: | undef ARRAY ref in Calc.pm:235 doing BigRat == float if 'use bignum' exists in unrelated code |
This is strange. The presence of "use bignum" in a separate, never-reached scope makes == blow up when comparing a BigRat and a native float.
I'm running perl 5.20.2 on 64-bit Ubuntu.
#!/usr/bin/perl
use strict; use warnings; use diagnostics;
require Math::BigRat;
my $bigval = Math::BigRat->new("123456789876543212345678987654321");
my $float = 1.23456789876543e+32;
print "Not equivalent\n" unless ($float == $bigval); # dies here
# BUT... if this never-executed code is commented out, the problem goes away
{ die "Dave's not here"; use bignum; my $x = 42 }
And here is the resulting backtrace:
Can't use an undefined value as an ARRAY reference at /usr/share/perl/5.20/Math/BigInt/Calc.pm line 235.
Math::BigInt::Calc::_copy("Math::BigInt::Calc", undef) called at /usr/share/perl/5.20/Math/BigRat.pm line 92
Math::BigRat::_new_from_float(Math::BigRat=HASH(0x182e340), Math::BigInt=HASH(0x220b228)) called at /usr/share/perl/5.20/Math/BigRat.pm line 299
Math::BigRat::new("Math::BigRat", 1.23456789876543e+32) called at /usr/share/perl/5.20/Math/BigInt.pm line 2689
Math::BigInt::objectify(2, "Math::BigRat", 1.23456789876543e+32, Math::BigRat=HASH(0x17e70a0)) called at /usr/share/perl/5.20/Math/BigRat.pm line 1348
Math::BigRat::bcmp("Math::BigRat", 1.23456789876543e+32, Math::BigRat=HASH(0x17e70a0)) called at /usr/share/perl/5.20/Math/BigFloat.pm line 29
Math::BigFloat::__ANON__(Math::BigRat=HASH(0x17e70a0), 1.23456789876543e+32, 1) called at ./test.pl line 11