diff options
author | Peter John Acklam <pjacklam@online.no> | 2010-11-05 11:52:14 +0100 |
---|---|---|
committer | Florian Ragwitz <rafl@debian.org> | 2010-11-07 16:01:11 +0100 |
commit | 3d6017f56e6b8f8227e1fd4570d7e7a67b7fc28a (patch) | |
tree | d0cae9560e492942bc3596b9e8ee6fcf75858c91 /dist/Math-BigInt | |
parent | 4f039b22bd6382064369066e22a0750cdd4976b1 (diff) | |
download | perl-3d6017f56e6b8f8227e1fd4570d7e7a67b7fc28a.tar.gz |
RT ticket #62101: as_int() returns NaN for inf
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
Diffstat (limited to 'dist/Math-BigInt')
-rw-r--r-- | dist/Math-BigInt/lib/Math/BigFloat.pm | 3 | ||||
-rw-r--r-- | dist/Math-BigInt/t/bare_mbf.t | 2 | ||||
-rw-r--r-- | dist/Math-BigInt/t/bigfltpm.inc | 3 | ||||
-rw-r--r-- | dist/Math-BigInt/t/bigfltpm.t | 2 | ||||
-rw-r--r-- | dist/Math-BigInt/t/sub_mbf.t | 2 | ||||
-rw-r--r-- | dist/Math-BigInt/t/with_sub.t | 2 |
6 files changed, 10 insertions, 4 deletions
diff --git a/dist/Math-BigInt/lib/Math/BigFloat.pm b/dist/Math-BigInt/lib/Math/BigFloat.pm index 049344255c..668fca75c5 100644 --- a/dist/Math-BigInt/lib/Math/BigFloat.pm +++ b/dist/Math-BigInt/lib/Math/BigFloat.pm @@ -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 { diff --git a/dist/Math-BigInt/t/bare_mbf.t b/dist/Math-BigInt/t/bare_mbf.t index 7fb1ff0006..11b3222ea1 100644 --- a/dist/Math-BigInt/t/bare_mbf.t +++ b/dist/Math-BigInt/t/bare_mbf.t @@ -1,7 +1,7 @@ #!/usr/bin/perl -w use strict; -use Test::More tests => 2316; +use Test::More tests => 2319; BEGIN { unshift @INC, 't'; } diff --git a/dist/Math-BigInt/t/bigfltpm.inc b/dist/Math-BigInt/t/bigfltpm.inc index e8801a51bf..059ebe1bf9 100644 --- a/dist/Math-BigInt/t/bigfltpm.inc +++ b/dist/Math-BigInt/t/bigfltpm.inc @@ -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 diff --git a/dist/Math-BigInt/t/bigfltpm.t b/dist/Math-BigInt/t/bigfltpm.t index fa6f878cc3..042308617a 100644 --- a/dist/Math-BigInt/t/bigfltpm.t +++ b/dist/Math-BigInt/t/bigfltpm.t @@ -1,7 +1,7 @@ #!/usr/bin/perl -w use strict; -use Test::More tests => 2316 +use Test::More tests => 2319 + 5; # own tests diff --git a/dist/Math-BigInt/t/sub_mbf.t b/dist/Math-BigInt/t/sub_mbf.t index 91b960c390..ab7108abec 100644 --- a/dist/Math-BigInt/t/sub_mbf.t +++ b/dist/Math-BigInt/t/sub_mbf.t @@ -1,7 +1,7 @@ #!/usr/bin/perl -w use strict; -use Test::More tests => 2316 +use Test::More tests => 2319 + 6; # + our own tests diff --git a/dist/Math-BigInt/t/with_sub.t b/dist/Math-BigInt/t/with_sub.t index 16ebb20342..d4baaecb27 100644 --- a/dist/Math-BigInt/t/with_sub.t +++ b/dist/Math-BigInt/t/with_sub.t @@ -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'; |