New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PATCH] Correct Math::BigInt -> new() for non-integer input. #14653
Comments
From @pjacklamCorrect Math::BigInt -> new() for non-integer input. The documentation in Math::BigInt says about input values that "Non-integer - All input values in the range (-1,1) written as a decimal number, e.g., - Input values with a large (absolute value) negative exponent, e.g., - This patch fixes CPAN RT #61887 and CPAN RT #63038. |
From @pjacklam0001-Correct-Math-BigInt-new-for-non-integer-input.patchFrom d54e1dead488e17ae4a5e02890795912e7654406 Mon Sep 17 00:00:00 2001
From: Peter John Acklam <pjacklam@online.no>
Date: Fri, 17 Apr 2015 21:28:37 +0200
Subject: [PATCH] Correct Math::BigInt -> new() for non-integer input.
The documentation in Math::BigInt says about input values that "Non-integer
values result in NaN." The actual behaviour doesn't comply with this.
- All input values in the range (-1,1) written as a decimal number, e.g.,
-0.75 and 0.5, now return NaN, not 0.
- Input values with a large (absolute value) negative exponent, e.g.,
1e-9999999, now return NaN. The former behaviour was to die with the
message "Quantifier in {,} bigger than 32766 in regex; marked by ..."
- This patch fixes CPAN RT #61887 and CPAN RT #63038.
---
dist/Math-BigInt/lib/Math/BigInt.pm | 16 +++++++++++-----
dist/Math-BigInt/t/bigintpm.inc | 4 ++--
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/dist/Math-BigInt/lib/Math/BigInt.pm b/dist/Math-BigInt/lib/Math/BigInt.pm
index 62f1be9..763b3f4 100644
--- a/dist/Math-BigInt/lib/Math/BigInt.pm
+++ b/dist/Math-BigInt/lib/Math/BigInt.pm
@@ -626,9 +626,13 @@ sub new
elsif ($e < 0)
{
# xE-y, and empty mfv
- #print "xE-y\n";
- $e = abs($e);
- if ($$miv !~ s/0{$e}$//) # can strip so many zero's?
+ # Split the mantissa at the decimal point. E.g., if
+ # $$miv = 12345 and $e = -2, then $frac = 45 and $$miv = 123.
+
+ my $frac = substr($$miv, $e); # $frac is fraction part
+ substr($$miv, $e) = ""; # $$miv is now integer part
+
+ if ($frac =~ /[^0]/)
{
if ($_trap_nan)
{
@@ -640,8 +644,10 @@ sub new
}
}
}
- $self->{sign} = '+' if $$miv eq '0'; # normalize -0 => +0
- $self->{value} = $CALC->_new($$miv) if $self->{sign} =~ /^[+-]$/;
+ unless ($self->{sign} eq $nan) {
+ $self->{sign} = '+' if $$miv eq '0'; # normalize -0 => +0
+ $self->{value} = $CALC->_new($$miv) if $self->{sign} =~ /^[+-]$/;
+ }
# if any of the globals is set, use them to round and store them inside $self
# do not round for new($x,undef,undef) since that is used by MBF to signal
# no rounding
diff --git a/dist/Math-BigInt/t/bigintpm.inc b/dist/Math-BigInt/t/bigintpm.inc
index c3e815c..fa320b0 100644
--- a/dist/Math-BigInt/t/bigintpm.inc
+++ b/dist/Math-BigInt/t/bigintpm.inc
@@ -1091,6 +1091,8 @@ E23:NaN
-1010E-2:NaN
-1.01E+1:NaN
-1.01E-1:NaN
+1E-999999:NaN
+0.5:NaN
&bnan
1:NaN
2:NaN
@@ -2409,8 +2411,6 @@ inf:-inf:NaN
15241:2:123
144:2:12
12:2:3
-0.49:2:0
-0.0049:2:0
# invalid ones
1:NaN:NaN
-1:NaN:NaN
--
2.1.4
|
From @tonycozOn Fri Apr 17 12:30:41 2015, pjacklam wrote:
Thanks, applied to blead as 8db2973. Tony |
The RT System itself - Status changed from 'new' to 'open' |
@tonycoz - Status changed from 'open' to 'resolved' |
@tonycoz - Status changed from 'resolved' to 'pending release' |
From @khwilliamsonThank you for submitting this report. You have helped make Perl better. Perl 5.24.0 may be downloaded via https://metacpan.org/release/RJBS/perl-5.24.0 |
@khwilliamson - Status changed from 'pending release' to 'resolved' |
Migrated from rt.perl.org#124325 (status was 'resolved')
Searchable as RT124325$
The text was updated successfully, but these errors were encountered: