diff options
author | Peter John Acklam <pjacklam@online.no> | 2011-03-07 11:45:38 +0100 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2011-06-11 12:17:14 -0700 |
commit | fc3993133139f2c4cdcfb845ec86abc53fafa050 (patch) | |
tree | ae637220890a78adcc93a94fe82e14f36e8c0a35 /dist | |
parent | 66a0495875e8130c45cac4fabd5f8d05f2f4c372 (diff) | |
download | perl-fc3993133139f2c4cdcfb845ec86abc53fafa050.tar.gz |
Fix Math::BigFloat->numify().
Math::BigFloat->numify() shall, according to the documentation and to be
consistent with Math::BigInt->numify() and Math::BigRat->numify(),
return a Perl scalar number, not a string.
- dist/Math-BigInt/lib/Math/BigFloat.pm:
- Fix objectify().
- dist/Math-BigInt/t/bigfltpm.inc:
- Remove no longer relevant tests.
- Modify existing tests and add new tests to verify correct behaviour.
This fix closes RT #66732.
Diffstat (limited to 'dist')
-rw-r--r-- | dist/Math-BigInt/lib/Math/BigFloat.pm | 6 | ||||
-rw-r--r-- | dist/Math-BigInt/t/bigfltpm.inc | 23 |
2 files changed, 17 insertions, 12 deletions
diff --git a/dist/Math-BigInt/lib/Math/BigFloat.pm b/dist/Math-BigInt/lib/Math/BigFloat.pm index 06a6e48417..40881038d5 100644 --- a/dist/Math-BigInt/lib/Math/BigFloat.pm +++ b/dist/Math-BigInt/lib/Math/BigFloat.pm @@ -437,10 +437,10 @@ sub bsstr sub numify { - # Make a number from a BigFloat object - # simple return a string and let Perl's atoi()/atof() handle the rest + # Convert a Perl scalar number from a BigFloat object. + # Create a string and let Perl's atoi()/atof() handle the rest. my ($self,$x) = ref($_[0]) ? (undef,$_[0]) : objectify(1,@_); - $x->bsstr(); + return 0 + $x->bsstr(); } ############################################################################## diff --git a/dist/Math-BigInt/t/bigfltpm.inc b/dist/Math-BigInt/t/bigfltpm.inc index 743752e07e..d6885ac7c1 100644 --- a/dist/Math-BigInt/t/bigfltpm.inc +++ b/dist/Math-BigInt/t/bigfltpm.inc @@ -258,6 +258,14 @@ $x->bdiv(3,$y); is ($x,'0.0027'); ############################################################################### +# Verify that numify() returns a normalized value, and underflows and +# overflows when given "extreme" values. + +like($class->new("12345e67")->numify(), qr/^1\.2345e\+?0*71$/); +like($class->new("1e-9999")->numify(), qr/^\+?0$/); # underflow +unlike($class->new("1e9999")->numify(), qr/^1(\.0*)?e\+?9+$/); # overflow + +############################################################################### # fsqrt() with set global A/P or A/P enabled on $x, also a test whether fsqrt() # correctly modifies $x @@ -637,15 +645,12 @@ hexNaN:NaN -5:-0b101 &numify # uses bsstr() so 5 => 5e+0 to be compatible w/ Perls output -0:0e+1 -+1:1e+0 -1234:1234e+0 -NaN:NaN -+inf:inf --inf:-inf --5:-5e+0 -100:1e+2 --100:-1e+2 +0:0 ++1:1 +1234:1234 +-5:-5 +100:100 +-100:-100 &fnan abc:NaN 2:NaN |