From: Tels Date: Fri, 12 Jul 2002 08:38:45 +0000 (+0200) Subject: [PATCH9 BigInt v1.60 fix for "\n" X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=739c8b3a364622b7992851a224b3e6424e7e3b03;p=p5sagit%2Fp5-mst-13.2.git [PATCH9 BigInt v1.60 fix for "\n" Message-Id: <200207120634.g6C6YjG6742777@taku.hut.fi> p4raw-id: //depot/perl@17498 --- diff --git a/lib/Math/BigInt.pm b/lib/Math/BigInt.pm index 800a97f..5a1385d 100644 --- a/lib/Math/BigInt.pm +++ b/lib/Math/BigInt.pm @@ -18,6 +18,7 @@ package Math::BigInt; my $class = "Math::BigInt"; require 5.005; +# This is a patched v1.60, containing a fix for the "1234567890\n" bug $VERSION = '1.60'; use Exporter; @ISA = qw( Exporter ); @@ -406,7 +407,7 @@ sub new my $self = bless {}, $class; # shortcut for "normal" numbers - if ((!ref $wanted) && ($wanted =~ /^([+-]?)[1-9][0-9]*$/)) + if ((!ref $wanted) && ($wanted =~ /^([+-]?)[1-9][0-9]*\z/)) { $self->{sign} = $1 || '+'; my $ref = \$wanted; @@ -2523,7 +2524,7 @@ sub _split $$x =~ s/\s+$//g; # strip white space at end # shortcut, if nothing to split, return early - if ($$x =~ /^[+-]?\d+$/) + if ($$x =~ /^[+-]?\d+\z/) { $$x =~ s/^([+-])0*([0-9])/$2/; my $sign = $1 || '+'; return (\$sign, $x, \'', \'', \0); @@ -3896,11 +3897,6 @@ versions to a more sophisticated scheme): =over 2 -=item Input with trailing newlines - -Input with trailing newlines is handled wrong (e.g. lead to corrupted numbers) -in some cases, for instance "123\n" or "123456789\n". - =item Out of Memory! Under Perl prior to 5.6.0 having an C and diff --git a/lib/Math/BigInt/t/bare_mbi.t b/lib/Math/BigInt/t/bare_mbi.t index 8e53b63..c725e5a 100644 --- a/lib/Math/BigInt/t/bare_mbi.t +++ b/lib/Math/BigInt/t/bare_mbi.t @@ -26,7 +26,7 @@ BEGIN } print "# INC = @INC\n"; - plan tests => 2392; + plan tests => 2552; } use Math::BigInt lib => 'BareCalc'; diff --git a/lib/Math/BigInt/t/bigintpm.inc b/lib/Math/BigInt/t/bigintpm.inc index 7aa3627..fa5b6f0 100644 --- a/lib/Math/BigInt/t/bigintpm.inc +++ b/lib/Math/BigInt/t/bigintpm.inc @@ -736,6 +736,86 @@ NaN:inf: -inf:NaN: NaN:-inf: &bnorm +-0\n:0 +-123\n:-123 +-1234\n:-1234 +-12345\n:-12345 +-123456\n:-123456 +-1234567\n:-1234567 +-12345678\n:-12345678 +-123456789\n:-123456789 +-1234567890\n:-1234567890 +-12345678901\n:-12345678901 +0\n:0 +123\n:123 +1234\n:1234 +12345\n:12345 +123456\n:123456 +1234567\n:1234567 +12345678\n:12345678 +123456789\n:123456789 +1234567890\n:1234567890 +12345678901\n:12345678901 +\n0:0 +\n123:123 +\n1234:1234 +\n12345:12345 +\n123456:123456 +\n1234567:1234567 +\n12345678:12345678 +\n123456789:123456789 +\n1234567890:1234567890 +\n12345678901:12345678901 +\n0\n:0 +\n123\n:123 +\n1234\n:1234 +\n12345\n:12345 +\n123456\n:123456 +\n1234567\n:1234567 +\n12345678\n:12345678 +\n123456789\n:123456789 +\n1234567890\n:1234567890 +\n12345678901\n:12345678901 +\t0\n:0 +\t123\n:123 +\t1234\n:1234 +\t12345\n:12345 +\t123456\n:123456 +\t1234567\n:1234567 +\t12345678\n:12345678 +\t123456789\n:123456789 +\t1234567890\n:1234567890 +\t12345678901\n:12345678901 +\n0\t:0 +\n123\t:123 +\n1234\t:1234 +\n12345\t:12345 +\n123456\t:123456 +\n1234567\t:1234567 +\n12345678\t:12345678 +\n123456789\t:123456789 +\n1234567890\t:1234567890 +\n12345678901\t:12345678901 +0\n\n:0 +123\n\n:123 +1234\n\n:1234 +12345\n\n:12345 +123456\n\n:123456 +1234567\n\n:1234567 +12345678\n\n:12345678 +123456789\n\n:123456789 +1234567890\n\n:1234567890 +12345678901\n\n:12345678901 +\n\n0:0 +\n\n123:123 +\n\n1234:1234 +\n\n12345:12345 +\n\n123456:123456 +\n\n1234567:1234567 +\n\n12345678:12345678 +\n\n123456789:123456789 +\n\n1234567890:1234567890 +\n\n12345678901:12345678901 123:123 # binary input 0babc:NaN diff --git a/lib/Math/BigInt/t/bigintpm.t b/lib/Math/BigInt/t/bigintpm.t index 2d315cc..b4c4f11 100755 --- a/lib/Math/BigInt/t/bigintpm.t +++ b/lib/Math/BigInt/t/bigintpm.t @@ -10,7 +10,7 @@ BEGIN my $location = $0; $location =~ s/bigintpm.t//; unshift @INC, $location; # to locate the testing files chdir 't' if -d 't'; - plan tests => 2392; + plan tests => 2552; } use Math::BigInt; diff --git a/lib/Math/BigInt/t/sub_mbi.t b/lib/Math/BigInt/t/sub_mbi.t index 0c0cfa6..a68113d 100755 --- a/lib/Math/BigInt/t/sub_mbi.t +++ b/lib/Math/BigInt/t/sub_mbi.t @@ -26,7 +26,7 @@ BEGIN } print "# INC = @INC\n"; - plan tests => 2392 + plan tests => 2552 + 5; # +5 own tests }