RT ticket #62101: as_int() returns NaN for inf
authorPeter John Acklam <pjacklam@online.no>
Fri, 5 Nov 2010 10:52:14 +0000 (11:52 +0100)
committerFlorian Ragwitz <rafl@debian.org>
Sun, 7 Nov 2010 15:01:11 +0000 (16:01 +0100)
Math::BigFloat -> binf() -> as_int() returns NaN, but should return
inf. In other words, if $x is a Math::BigFloat, then $x -> as_int()
shall return the same as Math::BigInt -> new($x). The bug appears both
for +inf and -inf.

-lib/Math/BigFloat.pm: Add two lines to catch the cases when the input
 is +/-inf and NaN, respectively.

-t/bare_mbf.t: incremented test count by 3

-t/bigfltpm.inc: add 3 tests, for +inf, -inf, and NaN

-t/bigfltpm.t: incremented test count by 3

-t/sub_mbf.t: incremented test count by 3

-t/with_sub.t: incremented test count by 3

dist/Math-BigInt/lib/Math/BigFloat.pm
dist/Math-BigInt/t/bare_mbf.t
dist/Math-BigInt/t/bigfltpm.inc
dist/Math-BigInt/t/bigfltpm.t
dist/Math-BigInt/t/sub_mbf.t
dist/Math-BigInt/t/with_sub.t

index 0493442..668fca7 100644 (file)
@@ -3684,6 +3684,9 @@ sub as_number
     $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
     {
index 7fb1ff0..11b3222 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 use strict;
-use Test::More tests => 2316;
+use Test::More tests => 2319;
 
 BEGIN { unshift @INC, 't'; }
 
index e8801a5..059ebe1 100644 (file)
@@ -587,6 +587,9 @@ fnormNaN:NaN
 -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
index fa6f878..0423086 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 use strict;
-use Test::More tests => 2316
+use Test::More tests => 2319
     + 5;               # own tests
 
 
index 91b960c..ab7108a 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 use strict;
-use Test::More tests => 2316
+use Test::More tests => 2319
     + 6;       # + our own tests
 
 
index 16ebb20..d4baaec 100644 (file)
@@ -3,7 +3,7 @@
 # Test use Math::BigFloat with => 'Math::BigInt::SomeSubclass';
 
 use strict;
-use Test::More tests => 2316 + 1;
+use Test::More tests => 2319 + 1;
 
 use Math::BigFloat with => 'Math::BigInt::Subclass', lib => 'Calc';