my $class = "Math::BigInt";
use 5.006002;
-$VERSION = '1.87';
+$VERSION = '1.88';
@ISA = qw(Exporter);
@EXPORT_OK = qw(objectify bgcd blcm);
# 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;
# 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;
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 =~ /^-/;
=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()
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';
$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