summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTels <nospam-abuse@bloodgate.com>2007-07-12 21:11:01 +0200
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2007-07-13 13:45:35 +0000
commit7aa7e0aec39c88a32913c0e0416bf1cdcb3b02da (patch)
tree9e56695ddcb48eb60c24e0f7501e7939c7de733e
parente31720c4ca357f7b6cd857b0f23b053fc90ae78f (diff)
downloadperl-7aa7e0aec39c88a32913c0e0416bf1cdcb3b02da.tar.gz
BigInt v1.88 take 1 (fix from_hex, from_oct, from_bin)
Message-Id: <200707121911.02528@bloodgate.com> p4raw-id: //depot/perl@31609
-rw-r--r--lib/Math/BigInt.pm18
-rwxr-xr-xlib/Math/BigInt/t/bigintpm.t26
2 files changed, 34 insertions, 10 deletions
diff --git a/lib/Math/BigInt.pm b/lib/Math/BigInt.pm
index 475666fcf5..860b68f5e0 100644
--- a/lib/Math/BigInt.pm
+++ b/lib/Math/BigInt.pm
@@ -18,7 +18,7 @@ package Math::BigInt;
my $class = "Math::BigInt";
use 5.006002;
-$VERSION = '1.87';
+$VERSION = '1.88';
@ISA = qw(Exporter);
@EXPORT_OK = qw(objectify bgcd blcm);
@@ -2741,7 +2741,7 @@ sub from_hex
# create a bigint from a hexadecimal string
my ($self, $hs) = @_;
- my $rc = $self->__from_hex($hs);
+ my $rc = __from_hex($hs);
return $self->bnan() unless defined $rc;
@@ -2753,7 +2753,7 @@ sub from_bin
# create a bigint from a hexadecimal string
my ($self, $bs) = @_;
- my $rc = $self->__from_bin($bs);
+ my $rc = __from_bin($bs);
return $self->bnan() unless defined $rc;
@@ -2768,10 +2768,10 @@ sub from_oct
my $x = $self->bzero();
# strip underscores
- $os =~ s/([0-9a-fA-F])_([0-9a-fA-F])/$1$2/g;
- $os =~ s/([0-9a-fA-F])_([0-9a-fA-F])/$1$2/g;
+ $os =~ s/([0-7])_([0-7])/$1$2/g;
+ $os =~ s/([0-7])_([0-7])/$1$2/g;
- return $x->bnan() if $os !~ /^[\-\+]?0[0-9]+$/;
+ return $x->bnan() if $os !~ /^[\-\+]?0[0-7]+\z/;
my $sign = '+'; $sign = '-' if $os =~ /^-/;
@@ -3443,15 +3443,15 @@ See L<Input> for more info on accepted input formats.
=head2 from_oct()
- $x = Math::BigIn->from_oct("0775"); # input is octal
+ $x = Math::BigInt->from_oct("0775"); # input is octal
=head2 from_hex()
- $x = Math::BigIn->from_hex("0xcafe"); # input is hexadecimal
+ $x = Math::BigInt->from_hex("0xcafe"); # input is hexadecimal
=head2 from_bin()
- $x = Math::BigIn->from_oct("0x10011"); # input is binary
+ $x = Math::BigInt->from_oct("0x10011"); # input is binary
=head2 bnan()
diff --git a/lib/Math/BigInt/t/bigintpm.t b/lib/Math/BigInt/t/bigintpm.t
index 948f05b097..9442fbb796 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 => 3257;
+ plan tests => 3257 + 6;
}
use Math::BigInt lib => 'Calc';
@@ -19,4 +19,28 @@ use vars qw ($scale $class $try $x $y $f @args $ans $ans1 $ans1_str $setup $CL);
$class = "Math::BigInt";
$CL = "Math::BigInt::Calc";
+#############################################################################
+# from_hex(), from_bin() and from_oct() tests
+
+my $x = Math::BigInt->from_hex('0xcafe');
+ok ($x, "51966", 'from_hex() works');
+
+$x = Math::BigInt->from_hex('0xcafebabedead');
+ok ($x, "223195403574957", 'from_hex() works with long numbers');
+
+$x = Math::BigInt->from_bin('0b1001');
+ok ($x, "9", 'from_bin() works');
+
+$x = Math::BigInt->from_bin('0b1001100110011001100110011001');
+ok ($x, "161061273", 'from_bin() works with big numbers');
+
+$x = Math::BigInt->from_oct('0775');
+ok ($x, "509", 'from_oct() works');
+
+$x = Math::BigInt->from_oct('07777777777777711111111222222222');
+ok ($x, "9903520314281112085086151826", 'from_oct() works with big numbers');
+
+#############################################################################
+# all the other tests
+
require 'bigintpm.inc'; # all tests here for sharing