Subject: | BigInt + BigFloat downgrades BigFloat to BigInt |
Given this pice of code:
use strict;
use Math::BigInt;
use Math::BigFloat;
print "Math::BigInt version => ", $Math::BigInt::VERSION, "\n";
print "Math::BigFloat version => ", $Math::BigFloat::VERSION, "\n";
my $zero = Math::BigInt->new(0);
my $foo = Math::BigFloat->new(rand());
print '$zero => ', $zero, "\n";
print '$foo => ', $foo , "\n";
print '$zero + $foo => ', $zero + $foo, "\n";
print '$foo + $zero => ', $foo + $zero, "\n";
Doing BigInt + BigFloat disregards the BigFloat value, and the result
always turns out to be 0, but BigFloat + BigInt returns the expected
answer, as shown below.
Show quoted text
shell> perl test.pl
Math::BigInt version => 1.74
Math::BigFloat version => 1.48
$zero => 0
$foo => 0.972720372331427
$zero + $foo => 0
$foo + $zero => 0.972720372331427
This strikes to me as unintuitive... Can Math::BigInt automatically
upgrade the resulting value to be a BigFloat if it detects that what's
being added is a floating point number?
I'm using perl 5.8.5