Skip Menu |

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

Report information
The Basics
Id: 62101
Status: resolved
Priority: 0/
Queue: Math-BigInt

People
Owner: Nobody in particular
Requestors: peter.john.acklam [...] gmail.com
Cc:
AdminCc:

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



Subject: Math::BigFloat -> binf() -> as_int() returns NaN
The cases below return BigInt objects, as documented. However, the values should be +inf and -inf, respectively, not NaNs: $ perl -MMath::BigFloat -wle 'print Math::BigFloat -> binf() -> as_int()' NaN $ perl -MMath::BigFloat -wle 'print Math::BigFloat -> binf("-") -> as_int()' NaN
as_int() is an alias for as_number(), and the bug was in the as_number() subroutine in Math::BigFloat. I have attached a patch that fixes the bug. Test are added that verify the behaviour. Hope you like it.
Subject: Math-BigInt-1.96-id-62101.txt
diff -ur Math-BigInt-1.96-orig/lib/Math/BigFloat.pm Math-BigInt-1.96/lib/Math/BigFloat.pm --- Math-BigInt-1.96-orig/lib/Math/BigFloat.pm 2010-09-28 06:34:04.000000000 +0200 +++ Math-BigInt-1.96/lib/Math/BigFloat.pm 2010-10-13 12:24:10.703125000 +0200 @@ -3684,6 +3684,9 @@ $x = $x->can('as_float') ? $x->as_float() : $self->new(0+"$x"); } + return Math::BigInt->binf($x->sign()) if $x->is_inf(); + return Math::BigInt->bnan() if $x->is_nan(); + my $z = $MBI->_copy($x->{_m}); if ($x->{_es} eq '-') # < 0 { diff -ur Math-BigInt-1.96-orig/t/bigfltpm.inc Math-BigInt-1.96/t/bigfltpm.inc --- Math-BigInt-1.96-orig/t/bigfltpm.inc 2010-09-13 16:28:42.000000000 +0200 +++ Math-BigInt-1.96/t/bigfltpm.inc 2010-10-13 12:26:25.265625000 +0200 @@ -587,6 +587,9 @@ -2:-2 -123.456:-123 -200:-200 +-inf:-inf +inf:inf +NaN:NaN # test for bug in brsft() not handling cases that return 0 0.000641:0 0.0006412:0 diff -ur Math-BigInt-1.96-orig/t/bigfltpm.t Math-BigInt-1.96/t/bigfltpm.t --- Math-BigInt-1.96-orig/t/bigfltpm.t 2010-09-13 16:28:42.000000000 +0200 +++ Math-BigInt-1.96/t/bigfltpm.t 2010-10-13 12:26:57.140625000 +0200 @@ -1,7 +1,7 @@ #!/usr/bin/perl -w use strict; -use Test::More tests => 2316 +use Test::More tests => 2319 + 5; # own tests
To be more precise: Another way to state the behaviour that I think is most consistent: If $x is a Math::BigFloat, then $x -> as_int() shall return the same as Math::BigInt -> new($x).