Skip Menu |

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

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

People
Owner: TELS [...] cpan.org
Requestors: dmaki [...] cpan.org
Cc:
AdminCc:

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



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
Show quoted text
> 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?
Yes, please read the docs about upgrade: use Math::BigInt upgrade => 'Math::BigFloat'; After inserting this line into "test.pl": te@linux:~> perl test.pl Math::BigInt version => 1.74 Math::BigFloat version => 1.48 $zero => 0 $foo => 0.290847335782932 $zero + $foo => 0.290847335782932 $foo + $zero => 0.290847335782932 I am closing this a "notabug" :) Best wishes, Tels