diff options
author | Hugo van der Sanden <hv@crypt.org> | 2022-04-12 19:39:10 +0100 |
---|---|---|
committer | Ricardo Signes <rjbs@semiotic.systems> | 2022-04-17 10:18:13 -0400 |
commit | ca3af6c0082fbe7928ee529f3a1741c2ac0559ff (patch) | |
tree | 7b77f60d5edc70d618d33d7900676ab98dc428b8 /cpan | |
parent | e59cb199fea7032f0535b1a68c961674a477a99f (diff) | |
download | perl-ca3af6c0082fbe7928ee529f3a1741c2ac0559ff.tar.gz |
Update bignum to CPAN version 0.65
[DELTA]
* Restore the upgrading and downgrading in "bignum", with the exception
of upgrading from Math::BigFloat to Math::BigRat, which I couldn't make
sense of. Now, both integer literals and integers (and Infs and NaNs)
that are the result of a computation become Math::BigInt objects, and
both non-integer literals and non-integers that are as a result of a
computation become Math::BigFloat objects. The classes used for literal
integers and non-integers during compile-time are configurable, as well
as the classes used for downgrading and upgrading during runtime.
* Add the "bigfloat" pragma, which converts all numeric literals to
Math::BigFloat objects. This is consistent with the "bigint" pragma,
which converts all numeric literals to Math::BigInt objects, and the
"bigrat" pragma which converts all numeric literals to Math::BigRat
objects.
Diffstat (limited to 'cpan')
41 files changed, 2449 insertions, 413 deletions
diff --git a/cpan/bignum/gentest/backend.sh b/cpan/bignum/gentest/backend.sh index 18be622ad6..377a9e9418 100644 --- a/cpan/bignum/gentest/backend.sh +++ b/cpan/bignum/gentest/backend.sh @@ -2,9 +2,10 @@ modules=( bigint - bignum + bigfloat bigrat - ) + bignum +) backends=( #FastCalc diff --git a/cpan/bignum/gentest/scope-nested-const.sh b/cpan/bignum/gentest/scope-nested-const.sh index b54cd64600..116cab91ac 100644 --- a/cpan/bignum/gentest/scope-nested-const.sh +++ b/cpan/bignum/gentest/scope-nested-const.sh @@ -12,7 +12,7 @@ use warnings; use File::Basename; -my $outfile = "t/scope-nested-hex-oct.t"; +my $outfile = "t/scope-nested-const.t"; my $dirname = dirname(__FILE__); chdir $dirname @@ -28,9 +28,9 @@ open my($fh), ">", $outfile use Algorithm::Combinatorics 'permutations'; my $data = [ - ['bigint', 'Math::BigInt' ], - ['bignum', 'Math::BigFloat'], - ['bigrat', 'Math::BigRat' ], + ['bigint', 'Math::BigInt' ], + ['bigfloat', 'Math::BigFloat'], + ['bigrat', 'Math::BigRat' ], ]; print $fh <<'EOF' or die "$outfile: print failed: $!"; diff --git a/cpan/bignum/gentest/scope-nested-hex-oct.sh b/cpan/bignum/gentest/scope-nested-hex-oct.sh index b54cd64600..7bddecc8e7 100644 --- a/cpan/bignum/gentest/scope-nested-hex-oct.sh +++ b/cpan/bignum/gentest/scope-nested-hex-oct.sh @@ -28,9 +28,9 @@ open my($fh), ">", $outfile use Algorithm::Combinatorics 'permutations'; my $data = [ - ['bigint', 'Math::BigInt' ], - ['bignum', 'Math::BigFloat'], - ['bigrat', 'Math::BigRat' ], + ['bigint', 'Math::BigInt' ], + ['bigfloat', 'Math::BigFloat'], + ['bigrat', 'Math::BigRat' ], ]; print $fh <<'EOF' or die "$outfile: print failed: $!"; diff --git a/cpan/bignum/lib/Math/BigFloat/Trace.pm b/cpan/bignum/lib/Math/BigFloat/Trace.pm index cb76601368..8fc67e95c9 100644 --- a/cpan/bignum/lib/Math/BigFloat/Trace.pm +++ b/cpan/bignum/lib/Math/BigFloat/Trace.pm @@ -10,7 +10,7 @@ use Math::BigFloat; our @ISA = qw(Exporter Math::BigFloat); -our $VERSION = '0.64'; +our $VERSION = '0.65'; use overload; # inherit overload from Math::BigFloat diff --git a/cpan/bignum/lib/Math/BigInt/Trace.pm b/cpan/bignum/lib/Math/BigInt/Trace.pm index cb230b62ed..8808ee69b6 100644 --- a/cpan/bignum/lib/Math/BigInt/Trace.pm +++ b/cpan/bignum/lib/Math/BigInt/Trace.pm @@ -10,7 +10,7 @@ use Math::BigInt; our @ISA = qw(Exporter Math::BigInt); -our $VERSION = '0.64'; +our $VERSION = '0.65'; use overload; # inherit overload from Math::BigInt diff --git a/cpan/bignum/lib/Math/BigRat/Trace.pm b/cpan/bignum/lib/Math/BigRat/Trace.pm index f71e93e3d3..df6e998e72 100644 --- a/cpan/bignum/lib/Math/BigRat/Trace.pm +++ b/cpan/bignum/lib/Math/BigRat/Trace.pm @@ -10,7 +10,7 @@ use Math::BigRat; our @ISA = qw(Exporter Math::BigRat); -our $VERSION = '0.64'; +our $VERSION = '0.65'; use overload; # inherit overload from Math::BigRat diff --git a/cpan/bignum/lib/bigfloat.pm b/cpan/bignum/lib/bigfloat.pm new file mode 100644 index 0000000000..af26c57e1c --- /dev/null +++ b/cpan/bignum/lib/bigfloat.pm @@ -0,0 +1,851 @@ +package bigfloat; + +use strict; +use warnings; + +use Carp qw< carp croak >; + +our $VERSION = '0.65'; + +use Exporter; +our @ISA = qw( Exporter ); +our @EXPORT_OK = qw( PI e bpi bexp hex oct ); +our @EXPORT = qw( inf NaN ); + +use overload; + +my $obj_class = "Math::BigFloat"; + +############################################################################## + +sub accuracy { + my $self = shift; + $obj_class -> accuracy(@_); +} + +sub precision { + my $self = shift; + $obj_class -> precision(@_); +} + +sub round_mode { + my $self = shift; + $obj_class -> round_mode(@_); +} + +sub div_scale { + my $self = shift; + $obj_class -> div_scale(@_); +} + +sub upgrade { + my $self = shift; + $obj_class -> upgrade(@_); +} + +sub downgrade { + my $self = shift; + $obj_class -> downgrade(@_); +} + +sub in_effect { + my $level = shift || 0; + my $hinthash = (caller($level))[10]; + $hinthash->{bigfloat}; +} + +sub _float_constant { + my $str = shift; + + # See if we can convert the input string to a string using a normalized form + # consisting of the significand as a signed integer, the character "e", and + # the exponent as a signed integer, e.g., "+0e+0", "+314e-2", and "-1e+3". + + my $nstr; + + if ( + # See if it is an octal number. An octal number like '0377' is also + # accepted by the functions parsing decimal and hexadecimal numbers, so + # handle octal numbers before decimal and hexadecimal numbers. + + $str =~ /^0(?:[Oo]|_*[0-7])/ and + $nstr = Math::BigInt -> oct_str_to_dec_flt_str($str) + + or + + # See if it is decimal number. + + $nstr = Math::BigInt -> dec_str_to_dec_flt_str($str) + + or + + # See if it is a hexadecimal number. Every hexadecimal number has a + # prefix, but the functions parsing numbers don't require it, so check + # to see if it actually is a hexadecimal number. + + $str =~ /^0[Xx]/ and + $nstr = Math::BigInt -> hex_str_to_dec_flt_str($str) + + or + + # See if it is a binary numbers. Every binary number has a prefix, but + # the functions parsing numbers don't require it, so check to see if it + # actually is a binary number. + + $str =~ /^0[Bb]/ and + $nstr = Math::BigInt -> bin_str_to_dec_flt_str($str)) + { + return $obj_class -> new($nstr); + } + + # If we get here, there is a bug in the code above this point. + + warn "Internal error: unable to handle literal constant '$str'.", + " This is a bug, so please report this to the module author."; + return $obj_class -> bnan(); +} + +############################################################################# +# the following two routines are for "use bigfloat qw/hex oct/;": + +use constant LEXICAL => $] > 5.009004; + +# Internal function with the same semantics as CORE::hex(). This function is +# not used directly, but rather by other front-end functions. + +sub _hex_core { + my $str = shift; + + # Strip off, clean, and parse as much as we can from the beginning. + + my $x; + if ($str =~ s/ ^ ( 0? [xX] )? ( [0-9a-fA-F]* ( _ [0-9a-fA-F]+ )* ) //x) { + my $chrs = $2; + $chrs =~ tr/_//d; + $chrs = '0' unless CORE::length $chrs; + $x = $obj_class -> from_hex($chrs); + } else { + $x = $obj_class -> bzero(); + } + + # Warn about trailing garbage. + + if (CORE::length($str)) { + require Carp; + Carp::carp(sprintf("Illegal hexadecimal digit '%s' ignored", + substr($str, 0, 1))); + } + + return $x; +} + +# Internal function with the same semantics as CORE::oct(). This function is +# not used directly, but rather by other front-end functions. + +sub _oct_core { + my $str = shift; + + $str =~ s/^\s*//; + + # Hexadecimal input. + + return _hex_core($str) if $str =~ /^0?[xX]/; + + my $x; + + # Binary input. + + if ($str =~ /^0?[bB]/) { + + # Strip off, clean, and parse as much as we can from the beginning. + + if ($str =~ s/ ^ ( 0? [bB] )? ( [01]* ( _ [01]+ )* ) //x) { + my $chrs = $2; + $chrs =~ tr/_//d; + $chrs = '0' unless CORE::length $chrs; + $x = $obj_class -> from_bin($chrs); + } + + # Warn about trailing garbage. + + if (CORE::length($str)) { + require Carp; + Carp::carp(sprintf("Illegal binary digit '%s' ignored", + substr($str, 0, 1))); + } + + return $x; + } + + # Octal input. Strip off, clean, and parse as much as we can from the + # beginning. + + if ($str =~ s/ ^ ( 0? [oO] )? ( [0-7]* ( _ [0-7]+ )* ) //x) { + my $chrs = $2; + $chrs =~ tr/_//d; + $chrs = '0' unless CORE::length $chrs; + $x = $obj_class -> from_oct($chrs); + } + + # Warn about trailing garbage. CORE::oct() only warns about 8 and 9, but it + # is more helpful to warn about all invalid digits. + + if (CORE::length($str)) { + require Carp; + Carp::carp(sprintf("Illegal octal digit '%s' ignored", + substr($str, 0, 1))); + } + + return $x; +} + +{ + my $proto = LEXICAL ? '_' : ';$'; + eval ' +sub hex(' . $proto . ') {' . <<'.'; + my $str = @_ ? $_[0] : $_; + _hex_core($str); +} +. + + eval ' +sub oct(' . $proto . ') {' . <<'.'; + my $str = @_ ? $_[0] : $_; + _oct_core($str); +} +. +} + +############################################################################# +# the following two routines are for Perl 5.9.4 or later and are lexical + +my ($prev_oct, $prev_hex, $overridden); + +if (LEXICAL) { eval <<'.' } +sub _hex(_) { + my $hh = (caller 0)[10]; + return $$hh{bigfloat} ? bigfloat::_hex_core($_[0]) + : $$hh{bigrat} ? bigrat::_hex_core($_[0]) + : $$hh{bigint} ? bigint::_hex_core($_[0]) + : $prev_hex ? &$prev_hex($_[0]) + : CORE::hex($_[0]); +} + +sub _oct(_) { + my $hh = (caller 0)[10]; + return $$hh{bigfloat} ? bigfloat::_oct_core($_[0]) + : $$hh{bigrat} ? bigrat::_oct_core($_[0]) + : $$hh{bigint} ? bigint::_oct_core($_[0]) + : $prev_oct ? &$prev_oct($_[0]) + : CORE::oct($_[0]); +} +. + +sub _override { + return if $overridden; + $prev_oct = *CORE::GLOBAL::oct{CODE}; + $prev_hex = *CORE::GLOBAL::hex{CODE}; + no warnings 'redefine'; + *CORE::GLOBAL::oct = \&_oct; + *CORE::GLOBAL::hex = \&_hex; + $overridden = 1; +} + +sub unimport { + $^H{bigfloat} = undef; # no longer in effect + overload::remove_constant('binary', '', 'float', '', 'integer'); +} + +sub import { + my $class = shift; + + $^H{bigfloat} = 1; # we are in effect + $^H{bigint} = undef; + $^H{bigrat} = undef; + + # for newer Perls always override hex() and oct() with a lexical version: + if (LEXICAL) { + _override(); + } + + my @import = (); + my @a = (); # unrecognized arguments + my $ver; # version? + + while (@_) { + my $param = shift; + + # Accuracy. + + if ($param =~ /^a(ccuracy)?$/) { + push @import, 'accuracy', shift(); + next; + } + + # Precision. + + if ($param =~ /^p(recision)?$/) { + push @import, 'precision', shift(); + next; + } + + # Rounding mode. + + if ($param eq 'round_mode') { + push @import, 'round_mode', shift(); + next; + } + + # Backend library. + + if ($param =~ /^(l|lib|try|only)$/) { + push @import, $param eq 'l' ? 'lib' : $param; + push @import, shift() if @_; + next; + } + + if ($param =~ /^(v|version)$/) { + $ver = 1; + next; + } + + if ($param =~ /^(t|trace)$/) { + $obj_class .= "::Trace"; + eval "require $obj_class"; + die $@ if $@; + next; + } + + if ($param =~ /^(PI|e|bexp|bpi|hex|oct)\z/) { + push @a, $param; + next; + } + + croak("Unknown option '$param'"); + } + + eval "require $obj_class"; + die $@ if $@; + $obj_class -> import(@import); + + if ($ver) { + printf "%-31s v%s\n", $class, $class -> VERSION(); + printf " lib => %-23s v%s\n", + $obj_class -> config("lib"), $obj_class -> config("lib_version"); + printf "%-31s v%s\n", $obj_class, $obj_class -> VERSION(); + exit; + } + + $class -> export_to_level(1, $class, @a); # export inf, NaN, etc. + + overload::constant + + # This takes care each number written as decimal integer and within the + # range of what perl can represent as an integer, e.g., "314", but not + # "3141592653589793238462643383279502884197169399375105820974944592307". + + integer => sub { + #printf "Value '%s' handled by the 'integer' sub.\n", $_[0]; + my $str = shift; + return $obj_class -> new($str); + }, + + # This takes care of each number written with a decimal point and/or + # using floating point notation, e.g., "3.", "3.0", "3.14e+2" (decimal), + # "0b1.101p+2" (binary), "03.14p+2" and "0o3.14p+2" (octal), and + # "0x3.14p+2" (hexadecimal). + + float => sub { + #printf "# Value '%s' handled by the 'float' sub.\n", $_[0]; + _float_constant(shift); + }, + + # Take care of each number written as an integer (no decimal point or + # exponent) using binary, octal, or hexadecimal notation, e.g., "0b101" + # (binary), "0314" and "0o314" (octal), and "0x314" (hexadecimal). + + binary => sub { + #printf "# Value '%s' handled by the 'binary' sub.\n", $_[0]; + my $str = shift; + return $obj_class -> new($str) if $str =~ /^0[XxBb]/; + $obj_class -> from_oct($str); + }; +} + +sub inf () { $obj_class -> binf(); } +sub NaN () { $obj_class -> bnan(); } + +# This should depend on the current accuracy/precision. Fixme! +sub PI () { $obj_class -> new('3.141592653589793238462643383279502884197'); } +sub e () { $obj_class -> new('2.718281828459045235360287471352662497757'); } + +sub bpi ($) { + my $up = Math::BigFloat -> upgrade(); # get current upgrading, if any ... + Math::BigFloat -> upgrade(undef); # ... and disable + + my $x = Math::BigFloat -> bpi(@_); + + Math::BigFloat -> upgrade($up); # reset the upgrading + + return $x; +} + +sub bexp ($$) { + my $up = Math::BigFloat -> upgrade(); # get current upgrading, if any ... + Math::BigFloat -> upgrade(undef); # ... and disable + + my $x = Math::BigFloat -> new(shift); + $x -> bexp(@_); + + Math::BigFloat -> upgrade($up); # reset the upgrading + + return $x; +} + +1; + +__END__ + +=pod + +=head1 NAME + +bigfloat - transparent big floating point number support for Perl + +=head1 SYNOPSIS + + use bigfloat; + + $x = 2 + 4.5; # Math::BigFloat 6.5 + print 2 ** 512 * 0.1; # Math::BigFloat 134...09.6 + print inf + 42; # Math::BigFloat inf + print NaN * 7; # Math::BigFloat NaN + print hex("0x1234567890123490"); # Perl v5.10.0 or later + + { + no bigfloat; + print 2 ** 256; # a normal Perl scalar now + } + + # for older Perls, import into current package: + use bigfloat qw/hex oct/; + print hex("0x1234567890123490"); + print oct("01234567890123490"); + +=head1 DESCRIPTION + +All numeric literals in the given scope are converted to Math::BigFloat objects. + +All operators (including basic math operations) except the range operator C<..> +are overloaded. + +So, the following: + + use bigfloat; + $x = 1234; + +creates a Math::BigFloat and stores a reference to in $x. This happens +transparently and behind your back, so to speak. + +You can see this with the following: + + perl -Mbigfloat -le 'print ref(1234)' + +Since numbers are actually objects, you can call all the usual methods from +Math::BigFloat on them. This even works to some extent on expressions: + + perl -Mbigfloat -le '$x = 1234; print $x->bdec()' + perl -Mbigfloat -le 'print 1234->copy()->binc();' + perl -Mbigfloat -le 'print 1234->copy()->binc->badd(6);' + perl -Mbigfloat -le 'print +(1234)->copy()->binc()' + +(Note that print doesn't do what you expect if the expression starts with +'(' hence the C<+>) + +You can even chain the operations together as usual: + + perl -Mbigfloat -le 'print 1234->copy()->binc->badd(6);' + 1241 + +Please note the following does not work as expected (prints nothing), since +overloading of '..' is not yet possible in Perl (as of v5.8.0): + + perl -Mbigfloat -le 'for (1..2) { print ref($_); }' + +=head2 Options + +C<bigfloat> recognizes some options that can be passed while loading it via via +C<use>. The following options exist: + +=over 4 + +=item a or accuracy + +This sets the accuracy for all math operations. The argument must be greater +than or equal to zero. See Math::BigInt's bround() method for details. + + perl -Mbigfloat=a,50 -le 'print sqrt(20)' + +Note that setting precision and accuracy at the same time is not possible. + +=item p or precision + +This sets the precision for all math operations. The argument can be any +integer. Negative values mean a fixed number of digits after the dot, while a +positive value rounds to this digit left from the dot. 0 means round to integer. +See Math::BigInt's bfround() method for details. + + perl -Mbigfloat=p,-50 -le 'print sqrt(20)' + +Note that setting precision and accuracy at the same time is not possible. + +=item t or trace + +This enables a trace mode and is primarily for debugging. + +=item l, lib, try, or only + +Load a different math lib, see L<Math Library>. + + perl -Mbigfloat=l,GMP -e 'print 2 ** 512' + perl -Mbigfloat=lib,GMP -e 'print 2 ** 512' + perl -Mbigfloat=try,GMP -e 'print 2 ** 512' + perl -Mbigfloat=only,GMP -e 'print 2 ** 512' + +=item hex + +Override the built-in hex() method with a version that can handle big numbers. +This overrides it by exporting it to the current package. Under Perl v5.10.0 and +higher, this is not so necessary, as hex() is lexically overridden in the +current scope whenever the C<bigfloat> pragma is active. + +=item oct + +Override the built-in oct() method with a version that can handle big numbers. +This overrides it by exporting it to the current package. Under Perl v5.10.0 and +higher, this is not so necessary, as oct() is lexically overridden in the +current scope whenever the C<bigfloat> pragma is active. + +=item v or version + +this prints out the name and version of the modules and then exits. + + perl -Mbigfloat=v + +=back + +=head2 Math Library + +Math with the numbers is done (by default) by a backend library module called +Math::BigInt::Calc. The default is equivalent to saying: + + use bigfloat lib => 'Calc'; + +you can change this by using: + + use bigfloat lib => 'GMP'; + +The following would first try to find Math::BigInt::Foo, then Math::BigInt::Bar, +and if this also fails, revert to Math::BigInt::Calc: + + use bigfloat lib => 'Foo,Math::BigInt::Bar'; + +Using c<lib> warns if none of the specified libraries can be found and +L<Math::BigInt> fell back to one of the default libraries. To suppress this +warning, use c<try> instead: + + use bigfloat try => 'GMP'; + +If you want the code to die instead of falling back, use C<only> instead: + + use bigfloat only => 'GMP'; + +Please see respective module documentation for further details. + +=head2 Method calls + +Since all numbers are now objects, you can use all methods that are part of the +Math::BigFloat API. + +But a warning is in order. When using the following to make a copy of a number, +only a shallow copy will be made. + + $x = 9; $y = $x; + $x = $y = 7; + +Using the copy or the original with overloaded math is okay, e.g., the following +work: + + $x = 9; $y = $x; + print $x + 1, " ", $y,"\n"; # prints 10 9 + +but calling any method that modifies the number directly will result in B<both> +the original and the copy being destroyed: + + $x = 9; $y = $x; + print $x->badd(1), " ", $y,"\n"; # prints 10 10 + + $x = 9; $y = $x; + print $x->binc(1), " ", $y,"\n"; # prints 10 10 + + $x = 9; $y = $x; + print $x->bmul(2), " ", $y,"\n"; # prints 18 18 + +Using methods that do not modify, but test that the contents works: + + $x = 9; $y = $x; + $z = 9 if $x->is_zero(); # works fine + +See the documentation about the copy constructor and C<=> in overload, as well +as the documentation in Math::BigFloat for further details. + +=head2 Methods + +=over 4 + +=item inf() + +A shortcut to return Math::BigFloat->binf(). Useful because Perl does not always +handle bareword C<inf> properly. + +=item NaN() + +A shortcut to return Math::BigFloat->bnan(). Useful because Perl does not always +handle bareword C<NaN> properly. + +=item e + + # perl -Mbigfloat=e -wle 'print e' + +Returns Euler's number C<e>, aka exp(1) + +=item PI + + # perl -Mbigfloat=PI -wle 'print PI' + +Returns PI. + +=item bexp() + + bexp($power, $accuracy); + +Returns Euler's number C<e> raised to the appropriate power, to the wanted +accuracy. + +Example: + + # perl -Mbigfloat=bexp -wle 'print bexp(1,80)' + +=item bpi() + + bpi($accuracy); + +Returns PI to the wanted accuracy. + +Example: + + # perl -Mbigfloat=bpi -wle 'print bpi(80)' + +=item accuracy() + +Set or get the accuracy. + +=item precision() + +Set or get the precision. + +=item round_mode() + +Set or get the rounding mode. + +=item div_scale() + +Set or get the division scale. + +=item upgrade() + +Set or get the class that the downgrade class upgrades to, if any. Set the +upgrade class to C<undef> to disable upgrading. + +Upgrading is disabled by default. + +=item downgrade() + +Set or get the class that the upgrade class downgrades to, if any. Set the +downgrade class to C<undef> to disable upgrading. + +Downgrading is disabled by default. + +=item in_effect() + + use bigfloat; + + print "in effect\n" if bigfloat::in_effect; # true + { + no bigfloat; + print "in effect\n" if bigfloat::in_effect; # false + } + +Returns true or false if C<bigfloat> is in effect in the current scope. + +This method only works on Perl v5.9.4 or later. + +=back + +=head1 CAVEATS + +=over 4 + +=item Hexadecimal, octal, and binary floating point literals + +Perl (and this module) accepts hexadecimal, octal, and binary floating point +literals, but use them with care with Perl versions before v5.32.0, because some +versions of Perl silently give the wrong result. + +=item Operator vs literal overloading + +C<bigrat> works by overloading handling of integer and floating point literals, +converting them to L<Math::BigRat> objects. + +This means that arithmetic involving only string values or string literals are +performed using Perl's built-in operators. + +For example: + + use bigrat; + my $x = "900000000000000009"; + my $y = "900000000000000007"; + print $x - $y; + +outputs C<0> on default 32-bit builds, since C<bigfloat> never sees the string +literals. To ensure the expression is all treated as C<Math::BigFloat> objects, +use a literal number in the expression: + + print +(0+$x) - $y; + +=item Ranges + +Perl does not allow overloading of ranges, so you can neither safely use ranges +with C<bigfloat> endpoints, nor is the iterator variable a C<Math::BigFloat>. + + use 5.010; + for my $i (12..13) { + for my $j (20..21) { + say $i ** $j; # produces a floating-point number, + # not an object + } + } + +=item in_effect() + +This method only works on Perl v5.9.4 or later. + +=item hex()/oct() + +C<bigfloat> overrides these routines with versions that can also handle big +integer values. Under Perl prior to version v5.9.4, however, this will not +happen unless you specifically ask for it with the two import tags "hex" and +"oct" - and then it will be global and cannot be disabled inside a scope with +C<no bigfloat>: + + use bigfloat qw/hex oct/; + + print hex("0x1234567890123456"); + { + no bigfloat; + print hex("0x1234567890123456"); + } + +The second call to hex() will warn about a non-portable constant. + +Compare this to: + + use bigfloat; + + # will warn only under Perl older than v5.9.4 + print hex("0x1234567890123456"); + +=back + +=head1 EXAMPLES + +Some cool command line examples to impress the Python crowd ;) + + perl -Mbigfloat -le 'print sqrt(33)' + perl -Mbigfloat -le 'print 2**255' + perl -Mbigfloat -le 'print 4.5+2**255' + perl -Mbigfloat -le 'print 3/7 + 5/7 + 8/3' + perl -Mbigfloat -le 'print 123->is_odd()' + perl -Mbigfloat -le 'print log(2)' + perl -Mbigfloat -le 'print exp(1)' + perl -Mbigfloat -le 'print 2 ** 0.5' + perl -Mbigfloat=a,65 -le 'print 2 ** 0.2' + perl -Mbigfloat=l,GMP -le 'print 7 ** 7777' + +=head1 BUGS + +Please report any bugs or feature requests to +C<bug-bignum at rt.cpan.org>, or through the web interface at +L<https://rt.cpan.org/Ticket/Create.html?Queue=bignum> (requires login). +We will be notified, and then you'll automatically be notified of +progress on your bug as I make changes. + +=head1 SUPPORT + +You can find documentation for this module with the perldoc command. + + perldoc bigfloat + +You can also look for information at: + +=over 4 + +=item * GitHub + +L<https://github.com/pjacklam/p5-bignum> + +=item * RT: CPAN's request tracker + +L<https://rt.cpan.org/Dist/Display.html?Name=bignum> + +=item * MetaCPAN + +L<https://metacpan.org/release/bignum> + +=item * CPAN Testers Matrix + +L<http://matrix.cpantesters.org/?dist=bignum> + +=item * CPAN Ratings + +L<https://cpanratings.perl.org/dist/bignum> + +=back + +=head1 LICENSE + +This program is free software; you may redistribute it and/or modify it under +the same terms as Perl itself. + +=head1 SEE ALSO + +L<bigint> and L<bigrat>. + +L<Math::BigInt>, L<Math::BigFloat>, L<Math::BigRat> and L<Math::Big> as well as +L<Math::BigInt::FastCalc>, L<Math::BigInt::Pari> and L<Math::BigInt::GMP>. + +=head1 AUTHORS + +=over 4 + +=item * + +(C) by Tels L<http://bloodgate.com/> in early 2002 - 2007. + +=item * + +Maintained by Peter John Acklam E<lt>pjacklam@gmail.comE<gt>, 2014-. + +=back + +=cut diff --git a/cpan/bignum/lib/bigint.pm b/cpan/bignum/lib/bigint.pm index dee181adcf..bb68d5183a 100644 --- a/cpan/bignum/lib/bigint.pm +++ b/cpan/bignum/lib/bigint.pm @@ -5,7 +5,7 @@ use warnings; use Carp qw< carp croak >; -our $VERSION = '0.64'; +our $VERSION = '0.65'; use Exporter; our @ISA = qw( Exporter ); @@ -38,16 +38,6 @@ sub div_scale { $obj_class -> div_scale(@_); } -sub upgrade { - my $self = shift; - $obj_class -> upgrade(@_); -} - -sub downgrade { - my $self = shift; - $obj_class -> downgrade(@_); -} - sub in_effect { my $level = shift || 0; my $hinthash = (caller($level))[10]; @@ -107,9 +97,6 @@ sub _float_constant { my $expo = substr($nstr, $pos + 2); if ($expo_sgn eq '-') { - my $upgrade = $obj_class -> upgrade(); - return $upgrade -> new($nstr) if defined $upgrade; - if ($mant_len <= $expo) { return $obj_class -> bzero(); # underflow } else { @@ -248,19 +235,19 @@ my ($prev_oct, $prev_hex, $overridden); if (LEXICAL) { eval <<'.' } sub _hex(_) { my $hh = (caller 0)[10]; - return $$hh{bigint} ? bigint::_hex_core($_[0]) - : $$hh{bignum} ? bignum::_hex_core($_[0]) - : $$hh{bigrat} ? bigrat::_hex_core($_[0]) - : $prev_hex ? &$prev_hex($_[0]) + return $$hh{bigint} ? bigint::_hex_core($_[0]) + : $$hh{bigfloat} ? bigfloat::_hex_core($_[0]) + : $$hh{bigrat} ? bigrat::_hex_core($_[0]) + : $prev_hex ? &$prev_hex($_[0]) : CORE::hex($_[0]); } sub _oct(_) { my $hh = (caller 0)[10]; - return $$hh{bigint} ? bigint::_oct_core($_[0]) - : $$hh{bignum} ? bignum::_oct_core($_[0]) - : $$hh{bigrat} ? bigrat::_oct_core($_[0]) - : $prev_oct ? &$prev_oct($_[0]) + return $$hh{bigint} ? bigint::_oct_core($_[0]) + : $$hh{bigfloat} ? bigfloat::_oct_core($_[0]) + : $$hh{bigrat} ? bigrat::_oct_core($_[0]) + : $prev_oct ? &$prev_oct($_[0]) : CORE::oct($_[0]); } . @@ -283,9 +270,9 @@ sub unimport { sub import { my $class = shift; - $^H{bigint} = 1; # we are in effect - $^H{bignum} = undef; - $^H{bigrat} = undef; + $^H{bigint} = 1; # we are in effect + $^H{bigfloat} = undef; + $^H{bigrat} = undef; # for newer Perls always override hex() and oct() with a lexical version: if (LEXICAL) { @@ -299,20 +286,6 @@ sub import { while (@_) { my $param = shift; - # Upgrading. - - if ($param eq 'upgrade') { - push @import, 'upgrade', shift(); - next; - } - - # Downgrading. - - if ($param eq 'downgrade') { - push @import, 'downgrade', shift(); - next; - } - # Accuracy. if ($param =~ /^a(ccuracy)?$/) { @@ -730,14 +703,6 @@ Set or get the rounding mode. Set or get the division scale. -=item upgrade() - -Return the class that numbers are upgraded to, if any. - -=item downgrade() - -Return the class that numbers are downgraded to, if any. - =item in_effect() use bigint; @@ -832,7 +797,7 @@ Compare this to: =head1 EXAMPLES Some cool command line examples to impress the Python crowd ;) You might want -to compare them to the results under -Mbignum or -Mbigrat: +to compare them to the results under -Mbigfloat or -Mbigrat: perl -Mbigint -le 'print sqrt(33)' perl -Mbigint -le 'print 2*255' diff --git a/cpan/bignum/lib/bignum.pm b/cpan/bignum/lib/bignum.pm index 70d2d1e0c5..a0ef30bdbe 100644 --- a/cpan/bignum/lib/bignum.pm +++ b/cpan/bignum/lib/bignum.pm @@ -5,7 +5,7 @@ use warnings; use Carp qw< carp croak >; -our $VERSION = '0.64'; +our $VERSION = '0.65'; use Exporter; our @ISA = qw( Exporter ); @@ -14,38 +14,47 @@ our @EXPORT = qw( inf NaN ); use overload; -my $obj_class = "Math::BigFloat"; +# Defaults: When a constant is an integer, Inf or NaN, it is converted to an +# object of class $int_class. When a constant is a finite non-integer, it is +# converted to an object of class $float_class. + +my $int_class = 'Math::BigInt'; +my $float_class = 'Math::BigFloat'; ############################################################################## sub accuracy { - my $self = shift; - $obj_class -> accuracy(@_); + shift; + $int_class -> accuracy(@_); + $float_class -> accuracy(@_); } sub precision { - my $self = shift; - $obj_class -> precision(@_); + shift; + $int_class -> precision(@_); + $float_class -> precision(@_); } sub round_mode { - my $self = shift; - $obj_class -> round_mode(@_); + shift; + $int_class -> round_mode(@_); + $float_class -> round_mode(@_); } sub div_scale { - my $self = shift; - $obj_class -> div_scale(@_); + shift; + $int_class -> div_scale(@_); + $float_class -> div_scale(@_); } sub upgrade { - my $self = shift; - $obj_class -> upgrade(@_); + shift; + $int_class -> upgrade(@_); } sub downgrade { - my $self = shift; - $obj_class -> downgrade(@_); + shift; + $float_class -> downgrade(@_); } sub in_effect { @@ -95,14 +104,38 @@ sub _float_constant { $str =~ /^0[Bb]/ and $nstr = Math::BigInt -> bin_str_to_dec_flt_str($str)) { - return $obj_class -> new($nstr); + my $pos = index($nstr, 'e'); + my $expo_sgn = substr($nstr, $pos + 1, 1); + my $sign = substr($nstr, 0, 1); + my $mant = substr($nstr, 1, $pos - 1); + my $mant_len = CORE::length($mant); + my $expo = substr($nstr, $pos + 2); + + # The number is a non-integer if and only if the exponent is negative. + + if ($expo_sgn eq '-') { + return $float_class -> new($str); + + my $upgrade = $int_class -> upgrade(); + return $upgrade -> new($nstr) if defined $upgrade; + + if ($mant_len <= $expo) { + return $int_class -> bzero(); # underflow + } else { + $mant = substr $mant, 0, $mant_len - $expo; # truncate + return $int_class -> new($sign . $mant); + } + } else { + $mant .= "0" x $expo; # pad with zeros + return $int_class -> new($sign . $mant); + } } # If we get here, there is a bug in the code above this point. warn "Internal error: unable to handle literal constant '$str'.", " This is a bug, so please report this to the module author."; - return $obj_class -> bnan(); + return $int_class -> bnan(); } ############################################################################# @@ -123,9 +156,9 @@ sub _hex_core { my $chrs = $2; $chrs =~ tr/_//d; $chrs = '0' unless CORE::length $chrs; - $x = $obj_class -> from_hex($chrs); + $x = $int_class -> from_hex($chrs); } else { - $x = $obj_class -> bzero(); + $x = $int_class -> bzero(); } # Warn about trailing garbage. @@ -163,7 +196,7 @@ sub _oct_core { my $chrs = $2; $chrs =~ tr/_//d; $chrs = '0' unless CORE::length $chrs; - $x = $obj_class -> from_bin($chrs); + $x = $int_class -> from_bin($chrs); } # Warn about trailing garbage. @@ -184,7 +217,7 @@ sub _oct_core { my $chrs = $2; $chrs =~ tr/_//d; $chrs = '0' unless CORE::length $chrs; - $x = $obj_class -> from_oct($chrs); + $x = $int_class -> from_oct($chrs); } # Warn about trailing garbage. CORE::oct() only warns about 8 and 9, but it @@ -259,7 +292,7 @@ sub unimport { sub import { my $class = shift; - $^H{bignum} = 1; # we are in effect + $^H{bignum} = 1; # we are in effect $^H{bigint} = undef; $^H{bigrat} = undef; @@ -268,9 +301,11 @@ sub import { _override(); } - my @import = (); - my @a = (); # unrecognized arguments - my $ver; # version? + my @import = (); # common options + my @int_import = (upgrade => $float_class); # int class only options + my @flt_import = (downgrade => $int_class); # float class only options + my @a = (); # unrecognized arguments + my $ver; # display version info? while (@_) { my $param = shift; @@ -278,14 +313,18 @@ sub import { # Upgrading. if ($param eq 'upgrade') { - push @import, 'upgrade', shift(); + my $arg = shift; + $float_class = $arg if defined $arg; + push @int_import, 'upgrade', $arg; next; } # Downgrading. if ($param eq 'downgrade') { - push @import, 'downgrade', shift(); + my $arg = shift; + $int_class = $arg if defined $arg; + push @flt_import, 'downgrade', $arg; next; } @@ -323,13 +362,6 @@ sub import { next; } - if ($param =~ /^(t|trace)$/) { - $obj_class .= "::Trace"; - eval "require $obj_class"; - die $@ if $@; - next; - } - if ($param =~ /^(PI|e|bexp|bpi|hex|oct)\z/) { push @a, $param; next; @@ -338,15 +370,19 @@ sub import { croak("Unknown option '$param'"); } - eval "require $obj_class"; + eval "require $int_class"; + die $@ if $@; + $int_class -> import(@int_import, @import); + + eval "require $float_class"; die $@ if $@; - $obj_class -> import(@import); + $float_class -> import(@flt_import, @import); if ($ver) { printf "%-31s v%s\n", $class, $class -> VERSION(); printf " lib => %-23s v%s\n", - $obj_class -> config("lib"), $obj_class -> config("lib_version"); - printf "%-31s v%s\n", $obj_class, $obj_class -> VERSION(); + $int_class -> config("lib"), $int_class -> config("lib_version"); + printf "%-31s v%s\n", $int_class, $int_class -> VERSION(); exit; } @@ -361,7 +397,7 @@ sub import { integer => sub { #printf "Value '%s' handled by the 'integer' sub.\n", $_[0]; my $str = shift; - return $obj_class -> new($str); + return $int_class -> new($str); }, # This takes care of each number written with a decimal point and/or @@ -381,38 +417,31 @@ sub import { binary => sub { #printf "# Value '%s' handled by the 'binary' sub.\n", $_[0]; my $str = shift; - return $obj_class -> new($str) if $str =~ /^0[XxBb]/; - $obj_class -> from_oct($str); + return $int_class -> new($str) if $str =~ /^0[XxBb]/; + $int_class -> from_oct($str); }; } -sub inf () { $obj_class -> binf(); } -sub NaN () { $obj_class -> bnan(); } +sub inf () { $int_class -> binf(); } +sub NaN () { $int_class -> bnan(); } # This should depend on the current accuracy/precision. Fixme! -sub PI () { $obj_class -> new('3.141592653589793238462643383279502884197'); } -sub e () { $obj_class -> new('2.718281828459045235360287471352662497757'); } +sub PI () { $float_class -> new('3.141592653589793238462643383279502884197'); } +sub e () { $float_class -> new('2.718281828459045235360287471352662497757'); } sub bpi ($) { my $up = Math::BigFloat -> upgrade(); # get current upgrading, if any ... Math::BigFloat -> upgrade(undef); # ... and disable - my $x = Math::BigFloat -> bpi(@_); - Math::BigFloat -> upgrade($up); # reset the upgrading - return $x; } sub bexp ($$) { my $up = Math::BigFloat -> upgrade(); # get current upgrading, if any ... Math::BigFloat -> upgrade(undef); # ... and disable - - my $x = Math::BigFloat -> new(shift); - $x -> bexp(@_); - + my $x = Math::BigFloat -> new(shift) -> bexp(@_); Math::BigFloat -> upgrade($up); # reset the upgrading - return $x; } @@ -432,8 +461,9 @@ bignum - transparent big number support for Perl $x = 2 + 4.5; # Math::BigFloat 6.5 print 2 ** 512 * 0.1; # Math::BigFloat 134...09.6 - print inf + 42; # Math::BigFloat inf - print NaN * 7; # Math::BigFloat NaN + print 2 ** 512; # Math::BigInt 134...096 + print inf + 42; # Math::BigInt inf + print NaN * 7; # Math::BigInt NaN print hex("0x1234567890123490"); # Perl v5.10.0 or later { @@ -448,43 +478,118 @@ bignum - transparent big number support for Perl =head1 DESCRIPTION -All numeric literals in the given scope are converted to Math::BigFloat objects. +=head2 Literal numeric constants + +By default, every literal integer becomes a Math::BigInt object, and literal +non-integer becomes a Math::BigFloat object. Whether a numeric literal is +considered an integer or non-integers depends only on the value of the constant, +not on how it is represented. For instance, the constants 3.14e2 and 0x1.3ap8 +become Math::BigInt objects, because they both represent the integer value +decimal 314. + +The default C<use bignum;> is equivalent to + + use bignum downgrade => "Math::BigInt", upgrade => "Math::BigFloat"; + +The classes used for integers and non-integers can be set at compile time with +the C<downgrade> and C<upgrade> options, for example + + # use Math::BigInt for integers and Math::BigRat for non-integers + use bignum upgrade => "Math::BigRat"; -All operators (including basic math operations) except the range operator C<..> -are overloaded. +Note that disabling downgrading and upgrading does not affect how numeric +literals are converted to objects -So, the following: + # disable both downgrading and upgrading + use bignum downgrade => undef, upgrade => undef; + $x = 2.4; # becomes 2.4 as a Math::BigFloat + $y = 2; # becomes 2 as a Math::BigInt + +=head2 Upgrading and downgrading + +By default, when the result of a computation is an integer, an Inf, or a NaN, +the result is downgraded even when all the operands are instances of the upgrade +class. use bignum; - $x = 1234; + $x = 2.4; # becomes 2.4 as a Math::BigFloat + $y = 1.2; # becomes 1.2 as a Math::BigFloat + $z = $x / $y; # becomes 2 as a Math::BigInt due to downgrading + +Equivalently, by default, when the result of a computation is a finite +non-integer, the result is upgraded even when all the operands are instances of +the downgrade class. -creates a Math::BigFloat and stores a reference to in $x. This happens -transparently and behind your back, so to speak. + use bignum; + $x = 7; # becomes 7 as a Math::BigInt + $y = 2; # becomes 2 as a Math::BigInt + $z = $x / $y; # becomes 3.5 as a Math::BigFloat due to upgrading -You can see this with the following: +The classes used for downgrading and upgrading can be set at runtime with the +L</downgrade()> and L</upgrade()> methods, but see L</CAVEATS> below. - perl -Mbignum -le 'print ref(1234)' +The upgrade and downgrade classes don't have to be Math::BigInt and +Math::BigFloat. For example, to use Math::BigRat as the upgrade class, use -Since numbers are actually objects, you can call all the usual methods from -Math::BigFloat on them. This even works to some extent on expressions: + use bignum upgrade => "Math::BigRat"; + $x = 2; # becomes 2 as a Math::BigInt + $y = 3.6; # becomes 18/5 as a Math::BigRat - perl -Mbignum -le '$x = 1234; print $x->bdec()' - perl -Mbignum -le 'print 1234->copy()->binc();' - perl -Mbignum -le 'print 1234->copy()->binc->badd(6);' - perl -Mbignum -le 'print +(1234)->copy()->binc()' +The upgrade and downgrade classes can be modified at runtime -(Note that print doesn't do what you expect if the expression starts with -'(' hence the C<+>) + use bignum; + $x = 3; # becomes 3 as a Math::BigInt + $y = 2; # becomes 2 as a Math::BigInt + $z = $x / $y; # becomes 1.5 as a Math::BigFlaot + + bignum -> upgrade("Math::BigRat"); + $w = $x / $y; # becomes 3/2 as a Math::BigRat + +Disabling downgrading doesn't change the fact that literal constant integers are +converted to the downgrade class, it only prevents downgrading as a result of a +computation. E.g., + + use bignum downgrade => undef; + $x = 2; # becomes 2 as a Math::BigInt + $y = 2.4; # becomes 2.4 as a Math::BigFloat + $z = 1.2; # becomes 1.2 as a Math::BigFloat + $w = $x / $y; # becomes 2 as a Math::BigFloat due to no downgrading + +If you want all numeric literals, both integers and non-integers, to become +Math::BigFloat objects, use the L<bigfloat> pragma. + +Equivalently, disabling upgrading doesn't change the fact that literal constant +non-integers are converted to the upgrade class, it only prevents upgrading as a +result of a computation. E.g., -You can even chain the operations together as usual: + use bignum upgrade => undef; + $x = 2.5; # becomes 2.5 as a Math::BigFloat + $y = 7; # becomes 7 as a Math::BigInt + $z = 2; # becomes 2 as a Math::BigInt + $w = $x / $y; # becomes 3 as a Math::BigInt due to no upgrading - perl -Mbignum -le 'print 1234->copy()->binc->badd(6);' - 1241 +If you want all numeric literals, both integers and non-integers, to become +Math::BigInt objects, use the L<bigint> pragma. -Please note the following does not work as expected (prints nothing), since -overloading of '..' is not yet possible in Perl (as of v5.8.0): +You can even do - perl -Mbignum -le 'for (1..2) { print ref($_); }' + use bignum upgrade => "Math::BigRat", upgrade => undef; + +which converts all integer literals to Math::BigInt objects and all non-integer +literals to Math::BigRat objects. However, when the result of a computation +involving two Math::BigInt objects results in a non-integer (e.g., 7/2), the +result will be truncted to a Math::BigInt rather than being upgraded to a +Math::BigRat, since upgrading is disabled. + +=head2 Overloading + +Since all numeric literals become objects, you can call all the usual methods +from Math::BigInt and Math::BigFloat on them. This even works to some extent on +expressions: + + perl -Mbignum -le '$x = 1234; print $x->bdec()' + perl -Mbignum -le 'print 1234->copy()->binc();' + perl -Mbignum -le 'print 1234->copy()->binc()->badd(6);' =head2 Options @@ -513,10 +618,6 @@ See Math::BigInt's bfround() method for details. Note that setting precision and accuracy at the same time is not possible. -=item t or trace - -This enables a trace mode and is primarily for debugging. - =item l, lib, try, or only Load a different math lib, see L<Math Library>. @@ -565,8 +666,8 @@ and if this also fails, revert to Math::BigInt::Calc: use bignum lib => 'Foo,Math::BigInt::Bar'; Using c<lib> warns if none of the specified libraries can be found and -L<Math::BigInt> fell back to one of the default libraries. To suppress this -warning, use c<try> instead: +L<Math::BigInt> and L<Math::BigFloat> fell back to one of the default +libraries. To suppress this warning, use C<try> instead: use bignum try => 'GMP'; @@ -578,8 +679,8 @@ Please see respective module documentation for further details. =head2 Method calls -Since all numbers are now objects, you can use all methods that are part of the -Math::BigFloat API. +Since all numbers are now objects, you can use the methods that are part of the +Math::BigInt and Math::BigFloat API. But a warning is in order. When using the following to make a copy of a number, only a shallow copy will be made. @@ -619,25 +720,25 @@ as the documentation in Math::BigFloat for further details. =item inf() -A shortcut to return Math::BigFloat->binf(). Useful because Perl does not always +A shortcut to return C<inf> as an object. Useful because Perl does not always handle bareword C<inf> properly. =item NaN() -A shortcut to return Math::BigFloat->bnan(). Useful because Perl does not always +A shortcut to return C<NaN> as an object. Useful because Perl does not always handle bareword C<NaN> properly. =item e # perl -Mbignum=e -wle 'print e' -Returns Euler's number C<e>, aka exp(1) +Returns Euler's number C<e>, aka exp(1) (= 2.7182818284...). =item PI # perl -Mbignum=PI -wle 'print PI' -Returns PI. +Returns PI (= 3.1415926532..). =item bexp() @@ -678,11 +779,13 @@ Set or get the division scale. =item upgrade() -Return the class that numbers are upgraded to, if any. +Set or get the class that the downgrade class upgrades to, if any. Set the +upgrade class to C<undef> to disable upgrading. See C</CAVEATS> below. =item downgrade() -Return the class that numbers are downgraded to, if any. +Set or get the class that the upgrade class downgrades to, if any. Set the +downgrade class to C<undef> to disable upgrading. See L</CAVEATS> below. =item in_effect() @@ -704,6 +807,34 @@ This method only works on Perl v5.9.4 or later. =over 4 +=item The upgrade() and downgrade() methods + +Note that setting both the upgrade and downgrade classes at runtime with the +L</upgrade()> and L</downgrade()> methods, might not do what you expect: + + # Assuming that downgrading and upgrading hasn't been modified so far, so + # the downgrade and upgrade classes are Math::BigInt and Math::BigFloat, + # respectively, the following sets the upgrade class to Math::BigRat, i.e., + # makes Math::BigInt upgrade to Math::BigRat: + + bignum -> upgrade("Math::BigRat"); + + # The following sets the downgrade class to Math::BigInt::Lite, i.e., makes + # the new upgrade class Math::BigRat downgrade to Math::BigInt::Lite + + bignum -> downgrade("Math::BigInt::Lite"); + + # Note that at this point, it is still Math::BigInt, not Math::BigInt::Lite, + # that upgrades to Math::BigRat, so to get Math::BigInt::Lite to upgrade to + # Math::BigRat, we need to do the following (again): + + bignum -> upgrade("Math::BigRat"); + +A simpler way to do this at runtime is to use import(), + + bignum -> import(upgrade => "Math::BigRat", + downgrade => "Math::BigInt::Lite"); + =item Hexadecimal, octal, and binary floating point literals Perl (and this module) accepts hexadecimal, octal, and binary floating point diff --git a/cpan/bignum/lib/bigrat.pm b/cpan/bignum/lib/bigrat.pm index 115c8620d4..371138d2b0 100644 --- a/cpan/bignum/lib/bigrat.pm +++ b/cpan/bignum/lib/bigrat.pm @@ -5,7 +5,7 @@ use warnings; use Carp qw< carp croak >; -our $VERSION = '0.64'; +our $VERSION = '0.65'; use Exporter; our @ISA = qw( Exporter ); @@ -38,16 +38,6 @@ sub div_scale { $obj_class -> div_scale(@_); } -sub upgrade { - my $self = shift; - $obj_class -> upgrade(@_); -} - -sub downgrade { - my $self = shift; - $obj_class -> downgrade(@_); -} - sub in_effect { my $level = shift || 0; my $hinthash = (caller($level))[10]; @@ -224,19 +214,19 @@ my ($prev_oct, $prev_hex, $overridden); if (LEXICAL) { eval <<'.' } sub _hex(_) { my $hh = (caller 0)[10]; - return $$hh{bigrat} ? bigrat::_hex_core($_[0]) - : $$hh{bignum} ? bignum::_hex_core($_[0]) - : $$hh{bigint} ? bigint::_hex_core($_[0]) - : $prev_hex ? &$prev_hex($_[0]) + return $$hh{bigrat} ? bigrat::_hex_core($_[0]) + : $$hh{bigfloat} ? bigfloat::_hex_core($_[0]) + : $$hh{bigint} ? bigint::_hex_core($_[0]) + : $prev_hex ? &$prev_hex($_[0]) : CORE::hex($_[0]); } sub _oct(_) { my $hh = (caller 0)[10]; - return $$hh{bigrat} ? bigrat::_oct_core($_[0]) - : $$hh{bignum} ? bignum::_oct_core($_[0]) - : $$hh{bigint} ? bigint::_oct_core($_[0]) - : $prev_oct ? &$prev_oct($_[0]) + return $$hh{bigrat} ? bigrat::_oct_core($_[0]) + : $$hh{bigfloat} ? bigfloat::_oct_core($_[0]) + : $$hh{bigint} ? bigint::_oct_core($_[0]) + : $prev_oct ? &$prev_oct($_[0]) : CORE::oct($_[0]); } . @@ -259,9 +249,9 @@ sub unimport { sub import { my $class = shift; - $^H{bigrat} = 1; # we are in effect - $^H{bigint} = undef; - $^H{bignum} = undef; + $^H{bigrat} = 1; # we are in effect + $^H{bigint} = undef; + $^H{bigfloat} = undef; # for newer Perls always override hex() and oct() with a lexical version: if (LEXICAL) { @@ -275,20 +265,6 @@ sub import { while (@_) { my $param = shift; - # Upgrading. - - if ($param eq 'upgrade') { - push @import, 'upgrade', shift(); - next; - } - - # Downgrading. - - if ($param eq 'downgrade') { - push @import, 'downgrade', shift(); - next; - } - # Accuracy. if ($param =~ /^a(ccuracy)?$/) { @@ -396,23 +372,17 @@ sub e () { $obj_class -> new('2.718281828459045235360287471352662497757'); } sub bpi ($) { my $up = Math::BigFloat -> upgrade(); # get current upgrading, if any ... Math::BigFloat -> upgrade(undef); # ... and disable - my $x = Math::BigFloat -> bpi(@_); - Math::BigFloat -> upgrade($up); # reset the upgrading - return $obj_class -> new($x); } sub bexp ($$) { my $up = Math::BigFloat -> upgrade(); # get current upgrading, if any ... Math::BigFloat -> upgrade(undef); # ... and disable - my $x = Math::BigFloat -> new(shift); $x -> bexp(@_); - Math::BigFloat -> upgrade($up); # reset the upgrading - return $obj_class -> new($x); } @@ -676,14 +646,6 @@ Set or get the rounding mode. Set or get the division scale. -=item upgrade() - -Return the class that numbers are upgraded to, if any. - -=item downgrade() - -Return the class that numbers are downgraded to, if any. - =item in_effect() use bigrat; diff --git a/cpan/bignum/t/backend-gmp-bigfloat.t b/cpan/bignum/t/backend-gmp-bigfloat.t new file mode 100644 index 0000000000..df036a3b49 --- /dev/null +++ b/cpan/bignum/t/backend-gmp-bigfloat.t @@ -0,0 +1,21 @@ +# -*- mode: perl; -*- + +use strict; +use warnings; + +use Test::More; + +BEGIN { + eval { require Math::BigInt::GMP; }; + if ($@) { + plan skip_all => "Math::BigInt::GMP not installed"; + } else { + plan tests => "1"; + } +} + +use bigfloat only => "GMP"; + +my $x = 1; +is($x -> config("lib"), "Math::BigInt::GMP", + "backend is Math::BigInt::GMP"); diff --git a/cpan/bignum/t/backend-pari-bigfloat.t b/cpan/bignum/t/backend-pari-bigfloat.t new file mode 100644 index 0000000000..ac12890382 --- /dev/null +++ b/cpan/bignum/t/backend-pari-bigfloat.t @@ -0,0 +1,21 @@ +# -*- mode: perl; -*- + +use strict; +use warnings; + +use Test::More; + +BEGIN { + eval { require Math::BigInt::Pari; }; + if ($@) { + plan skip_all => "Math::BigInt::Pari not installed"; + } else { + plan tests => "1"; + } +} + +use bigfloat only => "Pari"; + +my $x = 1; +is($x -> config("lib"), "Math::BigInt::Pari", + "backend is Math::BigInt::Pari"); diff --git a/cpan/bignum/t/bigexp.t b/cpan/bignum/t/bigexp.t index 61c98465ea..9ab565a557 100644 --- a/cpan/bignum/t/bigexp.t +++ b/cpan/bignum/t/bigexp.t @@ -1,14 +1,14 @@ # -*- mode: perl; -*- ############################################################################### -# test for bug #18025: bignum/bigrat can lead to a number that is both 1 and 0 +# test for bug #18025: bigfloat/bigrat can lead to a number that is both 1 and 0 use strict; use warnings; use Test::More tests => 4; -use bignum; +use bigfloat; my $ln_ev = -7 / (10 ** 17); my $ev = exp($ln_ev); diff --git a/cpan/bignum/t/bigfloat.t b/cpan/bignum/t/bigfloat.t new file mode 100644 index 0000000000..e5b17e9b1d --- /dev/null +++ b/cpan/bignum/t/bigfloat.t @@ -0,0 +1,59 @@ +# -*- mode: perl; -*- + +############################################################################### + +use strict; +use warnings; + +use Test::More tests => 17; + +use bigfloat; + +############################################################################### +# general tests + +my $x = 5; +is(ref($x), 'Math::BigFloat', '$x = 5 makes $x a Math::BigFloat'); + +$x = 2 + 3.5; +is($x, 5.5, '2 + 3.5 = 5.5'); +is(ref($x), 'Math::BigFloat', '$x = 2 + 3.5 makes $x a Math::BigFloat'); + +$x = 2 ** 255; +is(ref($x), 'Math::BigFloat', '$x = 2 ** 255 makes $x a Math::BigFloat'); + +is(sqrt(12), '3.464101615137754587054892683011744733886', + 'sqrt(12)'); + +is(2/3, "0.6666666666666666666666666666666666666667", '2/3'); + +#is(2 ** 0.5, 'NaN'); # should be sqrt(2); + +is(12->bfac(), 479001600, '12->bfac() = 479001600'); + +# see if Math::BigFloat constant works + +# 0123456789 0123456789 <- default 40 +# 0123456789 0123456789 +is(1/3, '0.3333333333333333333333333333333333333333', '1/3'); + +############################################################################### +# accuracy and precision + +is(bigfloat->accuracy(), undef, 'get accuracy'); +bigfloat->accuracy(12); +is(bigfloat->accuracy(), 12, 'get accuracy again'); +bigfloat->accuracy(undef); +is(bigfloat->accuracy(), undef, 'get accuracy again'); + +is(bigfloat->precision(), undef, 'get precision'); +bigfloat->precision(12); +is(bigfloat->precision(), 12, 'get precision again'); +bigfloat->precision(undef); +is(bigfloat->precision(), undef, 'get precision again'); + +is(bigfloat->round_mode(), 'even', 'get round mode'); +bigfloat->round_mode('odd'); +is(bigfloat->round_mode(), 'odd', 'get round mode again'); +bigfloat->round_mode('even'); +is(bigfloat->round_mode(), 'even', 'get round mode again'); diff --git a/cpan/bignum/t/bigint.t b/cpan/bignum/t/bigint.t index de9526e07b..7447d8a415 100644 --- a/cpan/bignum/t/bigint.t +++ b/cpan/bignum/t/bigint.t @@ -5,7 +5,7 @@ use strict; use warnings; -use Test::More tests => 15; +use Test::More tests => 17; use bigint; @@ -15,8 +15,9 @@ use bigint; my $x = 5; is(ref($x), 'Math::BigInt', '$x = 5 makes $x a Math::BigInt'); -# todo: is(2 + 2.5, 4.5); # should still work -# todo: $x = 2 + 3.5; is(ref($x), 'Math::BigFloat'); +$x = 2 + 3.5; +is($x, 5.5, '2 + 3.5 = 5.5'); +is(ref($x), 'Math::BigInt', '$x = 2 + 3.5 makes $x a Math::BigInt'); $x = 2 ** 255; is(ref($x), 'Math::BigInt', '$x = 2 ** 255 makes $x a Math::BigInt'); diff --git a/cpan/bignum/t/bignum.t b/cpan/bignum/t/bignum.t index 22ebece6b1..fe2f2f4d22 100644 --- a/cpan/bignum/t/bignum.t +++ b/cpan/bignum/t/bignum.t @@ -5,41 +5,27 @@ use strict; use warnings; -use Test::More tests => 19; +use Test::More tests => 15; -use bignum qw/oct hex/; +use bignum; ############################################################################### # general tests my $x = 5; -is(ref($x), 'Math::BigFloat', '$x = 5 makes $x a Math::BigFloat'); # :constant +is(ref($x), 'Math::BigInt', '$x = 5 makes $x a Math::BigInt'); -is(2 + 2.5, 4.5, '2 + 2.5 = 4.5'); $x = 2 + 3.5; +is($x, 5.5, '2 + 3.5 = 5.5'); is(ref($x), 'Math::BigFloat', '$x = 2 + 3.5 makes $x a Math::BigFloat'); -is(2 * 2.1, 4.2, '2 * 2.1 = 4.2'); -$x = 2 + 2.1; -is(ref($x), 'Math::BigFloat', '$x = 2 + 2.1 makes $x a Math::BigFloat'); - $x = 2 ** 255; -is(ref($x), 'Math::BigFloat', '$x = 2 ** 255 makes $x a Math::BigFloat'); - -is(sqrt(12), '3.464101615137754587054892683011744733886', - 'sqrt(12)'); - -is(2/3, "0.6666666666666666666666666666666666666667", '2/3'); - -#is(2 ** 0.5, 'NaN'); # should be sqrt(2); - -is(12->bfac(), 479001600, '12->bfac() = 479001600'); +is(ref($x), 'Math::BigInt', '$x = 2 ** 255 makes $x a Math::BigInt'); -# see if Math::BigFloat constant works +is(9/4, 2.25, '9/4 = 2.25 as a Math::BigFloat'); -# 0123456789 0123456789 <- default 40 -# 0123456789 0123456789 -is(1/3, '0.3333333333333333333333333333333333333333', '1/3'); +is(4.5 + 4.5, 9, '4.5 + 4.5 = 9'); +#is(ref(4.5 + 4.5), 'Math::BigInt', '4.5 + 4.5 makes a Math::BigInt'); ############################################################################### # accuracy and precision diff --git a/cpan/bignum/t/bigrat.t b/cpan/bignum/t/bigrat.t index bbb3fb00e0..ffa769c392 100644 --- a/cpan/bignum/t/bigrat.t +++ b/cpan/bignum/t/bigrat.t @@ -5,7 +5,7 @@ use strict; use warnings; -use Test::More tests => 29;; +use Test::More tests => 27; use bigrat; @@ -15,14 +15,10 @@ use bigrat; my $x = 5; is(ref($x), 'Math::BigRat', '$x = 5 makes $x a Math::BigRat'); -is(2 + 2.5, 4.5); # should still work $x = 2 + 3.5; +is($x, 5.5, '2 + 3.5 = 5.5'); is(ref($x), 'Math::BigRat', '$x = 2 + 3.5 makes $x a Math::BigRat'); -is(2 * 2.1, 4.2, '2 * 2.1 = 4.2'); -$x = 2 + 2.1; -is(ref($x), 'Math::BigRat', '$x = 2 + 2.1 makes $x a Math::BigRat'); - $x = 2 ** 255; is(ref($x), 'Math::BigRat', '$x = 2 ** 255 makes $x a Math::BigRat'); diff --git a/cpan/bignum/t/const-bigfloat.t b/cpan/bignum/t/const-bigfloat.t new file mode 100644 index 0000000000..ab444d4334 --- /dev/null +++ b/cpan/bignum/t/const-bigfloat.t @@ -0,0 +1,337 @@ +# -*- mode: perl; -*- + +# Binary, octal, and hexadecimal floating point literals were introduced in +# v5.22.0. +# +# - It wasn't until v5.28.0 that binary, octal, and hexadecimal floating point +# literals were converted to the correct value on perls compiled with quadmath +# support. +# +# - It wasn't until v5.32.0 that binary and octal floating point literals worked +# correctly with constant overloading. Before v5.32.0, it seems like the +# second character is always silently converted to an "x", so, e.g., "0b1.1p8" +# is passed to the overload::constant subroutine as "0x1.1p8", and "01.1p+8" +# is passed as "0x.1p+8". +# +# - Octal floating point literals using the "0o" prefix were introduced in +# v5.34.0. + +# Note that all numeric literals that should not be overloaded must be quoted. + +use strict; +use warnings; + +use Test::More tests => "171"; + +use bigfloat; + +my $class = "Math::BigFloat"; +my $x; + +################################################################################ +# The following tests should be identical for Math::BigInt, Math::BigFloat and +# Math::BigRat. + +# These are handled by "binary". + +$x = 0xff; +is($x, "255", "hexadecimal integer literal 0xff"); +is(ref($x), "Math::BigFloat", + "value is a Math::BigInt or Math::BigInt::Lite"); + +SKIP: { + # Hexadecimal literals using the "0X" prefix require v5.14.0. + skip "perl v5.14.0 required for hexadecimal integer literals" + . " with '0X' prefix", "2" if $] < "5.014"; + + $x = eval "0XFF"; + is($x, "255", "hexadecimal integer literal 0XFF"); + is(ref($x), $class, "value is a $class"); +} + +$x = 0377; +is($x, "255", "octal integer literal 0377"); +is(ref($x), "Math::BigFloat", + "value is a Math::BigInt or Math::BigInt::Lite"); + +SKIP: { + # Octal literals using the "0o" prefix require v5.34.0. + skip "perl v5.34.0 required for octal floating point literals" + . " with '0o' prefix", "4" if $] < "5.034"; + + for my $str (qw/ 0o377 0O377 /) { + $x = eval $str; + is($x, "255", "octal integer literal $str"); + is(ref($x), "Math::BigFloat", + "value is a Math::BigInt or Math::BigInt::Lite"); + } +} + +$x = 0b11111111; +is($x, "255", "binary integer literal 0b11111111"); +is(ref($x), "Math::BigFloat", + "value is a Math::BigInt or Math::BigInt::Lite"); + +SKIP: { + # Binary literals using the "0B" prefix require v5.14.0. + skip "perl v5.14.0 required for binary integer literals" + . " with '0B' prefix", "2" if $] < "5.014"; + + $x = eval "0B11111111"; + is($x, "255", "binary integer literal 0B11111111"); + is(ref($x), $class, "value is a $class"); +} + +# These are handled by "float". + +$x = 999999999999999999999999999999999999999999999999999999999999999999999999; +is($x, + "999999999999999999999999999999999999999999999999999999999999999999999999", + "decimal integer literal " . ("9" x 72)); +is(ref($x), "Math::BigFloat", + "value is a Math::BigInt or Math::BigInt::Lite"); + +$x = 1e72 - 1; +is($x, + "999999999999999999999999999999999999999999999999999999999999999999999999", + "literal 1e72 - 1"); +is(ref($x), "Math::BigFloat", + "value is a Math::BigInt or Math::BigInt::Lite"); + +# These are handled by "float". + +SKIP: { + # Hexadecimal floating point literals require v5.28.0. + skip "perl v5.28.0 required for hexadecimal floating point literals", + "6" * "2" + "2" * "2" if $] < "5.028"; + + for my $str (qw/ 0x1.3ap+8 0X1.3AP+8 + 0x1.3ap8 0X1.3AP8 + 0x13a0p-4 0X13A0P-4 /) + { + $x = eval $str; + is($x, "314", "hexadecimal floating point literal $str"); + is(ref($x), "Math::BigFloat", + "value is a Math::BigInt or Math::BigInt::Lite"); + } + + for my $str (qw/ 0x0.0p+8 0X0.0P+8 /) + { + $x = eval $str; + is($x, "0", "hexadecimal floating point literal $str"); + is(ref($x), "Math::BigFloat", + "value is a Math::BigInt or Math::BigInt::Lite"); + } +} + +SKIP: { + # Octal floating point literals using the "0o" prefix require v5.34.0. + skip "perl v5.34.0 required for octal floating point literals" + . " with '0o' prefix", "6" * "2" + "6" * "2" if $] < "5.034"; + + for my $str (qw/ 0o1.164p+8 0O1.164P+8 + 0o1.164p8 0O1.164P8 + 0o11640p-4 0O11640P-4 /) + { + $x = eval $str; + is($x, "314", "octal floating point literal $str"); + is(ref($x), "Math::BigFloat", + "value is a Math::BigInt or Math::BigInt::Lite"); + } + + for my $str (qw/ 0o0.0p+8 0O0.0P+8 + 0o0.0p8 0O0.0P8 + 0o0.0p-8 0O0.0P-8 /) + { + $x = eval $str; + is($x, "0", "octal floating point literal $str"); + is(ref($x), "Math::BigFloat", + "value is a Math::BigInt or Math::BigInt::Lite"); + } +} + +SKIP: { + # Octal floating point literals using the "0" prefix require v5.32.0. + skip "perl v5.32.0 required for octal floating point literals", + "6" * "2" + "6" * "2" if $] < "5.032"; + + for my $str (qw/ 01.164p+8 01.164P+8 + 01.164p8 01.164P8 + 011640p-4 011640P-4 /) + { + $x = eval $str; + is($x, "314", "octal floating point literal $str"); + is(ref($x), "Math::BigFloat", + "value is a Math::BigInt or Math::BigInt::Lite"); + } + + for my $str (qw/ 00.0p+8 00.0P+8 + 00.0p8 00.0P8 + 00.0p-8 00.0P-8 /) + { + $x = eval $str; + is($x, "0", "octal floating point literal $str"); + is(ref($x), "Math::BigFloat", + "value is a Math::BigInt or Math::BigInt::Lite"); + } +} + +SKIP: { + # Binary floating point literals require v5.32.0. + skip "perl v5.32.0 required for binary floating point literals", + "6" * "2" + "6" * "2" if $] < "5.032"; + + for my $str (qw/ 0b1.0011101p+8 0B1.0011101P+8 + 0b1.0011101p8 0B1.0011101P8 + 0b10011101000p-2 0B10011101000P-2 /) + { + $x = eval $str; + is($x, "314", "binary floating point literal $str"); + is(ref($x), "Math::BigFloat", + "value is a Math::BigInt or Math::BigInt::Lite"); + } + + for my $str (qw/ 0b0p+8 0B0P+8 + 0b0p8 0B0P8 + 0b0p-8 0B0P-8 + /) + { + $x = eval $str; + is($x, "0", "binary floating point literal $str"); + is(ref($x), "Math::BigFloat", + "value is a Math::BigInt or Math::BigInt::Lite"); + } +} + +# These are handled by "integer". + +$x = 314; +is($x, "314", "integer literal 314"); +is(ref($x), "Math::BigFloat", + "value is a Math::BigInt or Math::BigInt::Lite"); + +$x = 0; +is($x, "0", "integer literal 0"); +is(ref($x), "Math::BigFloat", + "value is a Math::BigInt or Math::BigInt::Lite"); + +$x = 2 ** 255; +is($x, + "578960446186580977117854925043439539266" + . "34992332820282019728792003956564819968", + "2 ** 255"); +is(ref($x), "Math::BigFloat", + "value is a Math::BigInt or Math::BigInt::Lite"); + +# These are handled by "binary". + +{ + no warnings "portable"; # protect against "non-portable" warnings + + # hexadecimal constant + $x = 0x123456789012345678901234567890; + is($x, + "94522879687365475552814062743484560", + "hexadecimal constant 0x123456789012345678901234567890"); + is(ref($x), "Math::BigFloat", + "value is a Math::BigInt or Math::BigInt::Lite"); + + # octal constant + $x = 012345676543210123456765432101234567654321; + is($x, + "1736132869400711976876385488263403729", + "octal constant 012345676543210123456765432101234567654321"); + is(ref($x), "Math::BigFloat", + "value is a Math::BigInt or Math::BigInt::Lite"); + + # binary constant + $x = 0b01010100011001010110110001110011010010010110000101101101; + is($x, + "23755414508757357", + "binary constant 0b0101010001100101011011000111" + . "0011010010010110000101101101"); + is(ref($x), "Math::BigFloat", + "value is a Math::BigInt or Math::BigInt::Lite"); +} + +################################################################################ +# The following tests are unique to $class. + +# These are handled by "float". + +$x = 0.999999999999999999999999999999999999999999999999999999999999999999999999; +is($x, + "0.999999999999999999999999999999999999999999999999999999999999999999999999", + "decimal floating point literal 0." . ("9" x 72)); +is(ref($x), $class, "value is a $class"); + +$x = 1e72 - 0.1; +is($x, + "999999999999999999999999999999999999999999999999999999999999999999999999.9", + "literal 1e72 - 0.1"); +is(ref($x), $class, "value is a $class"); + +# These are handled by "float". + +SKIP: { + # Hexadecimal floating point literals require v5.28.0. + skip "perl v5.22.0 required for hexadecimal floating point literals", + "6" * "2" if $] < "5.028"; + + for my $str (qw/ 0x1.92p+1 0X1.92P+1 + 0x1.92p1 0X1.92P1 + 0x19.2p-3 0X19.2P-3 /) + { + $x = eval $str; + is($x, "3.140625", "hexadecimal floating point literal $str"); + is(ref($x), $class, "value is a $class"); + } +} + +SKIP: { + # Octal floating point literals using the "0o" prefix require v5.34.0. + skip "perl v5.34.0 required for octal floating point literals" + . " with '0o' prefix", "6" * "2" if $] < "5.034"; + + for my $str (qw/ 0o1.444p+1 0O1.444P+1 + 0o1.444p1 0O1.444P1 + 0o14.44p-2 0O14.44P-2 /) + { + $x = eval $str; + is($x, "3.140625", "octal floating point literal $str"); + is(ref($x), $class, "value is a $class"); + } +} + +SKIP: { + # Octal floating point literals using the "0" prefix require v5.32.0. + skip "perl v5.32.0 required for octal floating point literals", + "6" * "2" if $] < "5.032"; + + for my $str (qw/ 01.444p+1 01.444P+1 + 01.444p1 01.444P1 + 014.44p-2 014.44P-2 /) + { + $x = eval $str; + is($x, "3.140625", "octal floating point literal $str"); + is(ref($x), $class, "value is a $class"); + } +} + +SKIP: { + # Binary floating point literals require v5.32.0. + skip "perl v5.32.0 required for binary floating point literals", + "6" * "2" if $] < "5.032"; + + for my $str (qw/ 0b1.1001001p+1 0B1.1001001P+1 + 0b1.1001001p1 0B1.1001001P1 + 0b110.01001p-1 0B110.01001P-1 /) + { + $x = eval $str; + is($x, "3.140625", "binary floating point literal $str"); + is(ref($x), $class, "value is a $class"); + } +} + +is(1.0 / 3.0, "0.3333333333333333333333333333333333333333", + "1.0 / 3.0 = 0.3333333333333333333333333333333333333333"); diff --git a/cpan/bignum/t/const-bignum.t b/cpan/bignum/t/const-bignum.t index b9021d6032..304243cbfa 100644 --- a/cpan/bignum/t/const-bignum.t +++ b/cpan/bignum/t/const-bignum.t @@ -36,7 +36,7 @@ my $x; $x = 0xff; is($x, "255", "hexadecimal integer literal 0xff"); -is(ref($x), "Math::BigFloat", +like(ref($x), qr/^Math::BigInt(::Lite)?$/, "value is a Math::BigInt or Math::BigInt::Lite"); SKIP: { @@ -46,12 +46,13 @@ SKIP: { $x = eval "0XFF"; is($x, "255", "hexadecimal integer literal 0XFF"); - is(ref($x), $class, "value is a $class"); + like(ref($x), qr/^Math::BigInt(::Lite)?$/, + "value is a Math::BigInt or Math::BigInt::Lite"); } $x = 0377; is($x, "255", "octal integer literal 0377"); -is(ref($x), "Math::BigFloat", +like(ref($x), qr/^Math::BigInt(::Lite)?$/, "value is a Math::BigInt or Math::BigInt::Lite"); SKIP: { @@ -62,14 +63,14 @@ SKIP: { for my $str (qw/ 0o377 0O377 /) { $x = eval $str; is($x, "255", "octal integer literal $str"); - is(ref($x), "Math::BigFloat", - "value is a Math::BigInt or Math::BigInt::Lite"); + like(ref($x), qr/^Math::BigInt(::Lite)?$/, + "value is a Math::BigInt or Math::BigInt::Lite"); } } $x = 0b11111111; is($x, "255", "binary integer literal 0b11111111"); -is(ref($x), "Math::BigFloat", +like(ref($x), qr/^Math::BigInt(::Lite)?$/, "value is a Math::BigInt or Math::BigInt::Lite"); SKIP: { @@ -79,7 +80,8 @@ SKIP: { $x = eval "0B11111111"; is($x, "255", "binary integer literal 0B11111111"); - is(ref($x), $class, "value is a $class"); + like(ref($x), qr/^Math::BigInt(::Lite)?$/, + "value is a Math::BigInt or Math::BigInt::Lite"); } # These are handled by "float". @@ -88,14 +90,14 @@ $x = 999999999999999999999999999999999999999999999999999999999999999999999999; is($x, "999999999999999999999999999999999999999999999999999999999999999999999999", "decimal integer literal " . ("9" x 72)); -is(ref($x), "Math::BigFloat", +like(ref($x), qr/^Math::BigInt(::Lite)?$/, "value is a Math::BigInt or Math::BigInt::Lite"); $x = 1e72 - 1; is($x, "999999999999999999999999999999999999999999999999999999999999999999999999", "literal 1e72 - 1"); -is(ref($x), "Math::BigFloat", +like(ref($x), qr/^Math::BigInt(::Lite)?$/, "value is a Math::BigInt or Math::BigInt::Lite"); # These are handled by "float". @@ -111,7 +113,7 @@ SKIP: { { $x = eval $str; is($x, "314", "hexadecimal floating point literal $str"); - is(ref($x), "Math::BigFloat", + like(ref($x), qr/^Math::BigInt(::Lite)?$/, "value is a Math::BigInt or Math::BigInt::Lite"); } @@ -119,7 +121,7 @@ SKIP: { { $x = eval $str; is($x, "0", "hexadecimal floating point literal $str"); - is(ref($x), "Math::BigFloat", + like(ref($x), qr/^Math::BigInt(::Lite)?$/, "value is a Math::BigInt or Math::BigInt::Lite"); } } @@ -135,7 +137,7 @@ SKIP: { { $x = eval $str; is($x, "314", "octal floating point literal $str"); - is(ref($x), "Math::BigFloat", + like(ref($x), qr/^Math::BigInt(::Lite)?$/, "value is a Math::BigInt or Math::BigInt::Lite"); } @@ -145,7 +147,7 @@ SKIP: { { $x = eval $str; is($x, "0", "octal floating point literal $str"); - is(ref($x), "Math::BigFloat", + like(ref($x), qr/^Math::BigInt(::Lite)?$/, "value is a Math::BigInt or Math::BigInt::Lite"); } } @@ -161,7 +163,7 @@ SKIP: { { $x = eval $str; is($x, "314", "octal floating point literal $str"); - is(ref($x), "Math::BigFloat", + like(ref($x), qr/^Math::BigInt(::Lite)?$/, "value is a Math::BigInt or Math::BigInt::Lite"); } @@ -171,7 +173,7 @@ SKIP: { { $x = eval $str; is($x, "0", "octal floating point literal $str"); - is(ref($x), "Math::BigFloat", + like(ref($x), qr/^Math::BigInt(::Lite)?$/, "value is a Math::BigInt or Math::BigInt::Lite"); } } @@ -187,7 +189,7 @@ SKIP: { { $x = eval $str; is($x, "314", "binary floating point literal $str"); - is(ref($x), "Math::BigFloat", + like(ref($x), qr/^Math::BigInt(::Lite)?$/, "value is a Math::BigInt or Math::BigInt::Lite"); } @@ -198,7 +200,7 @@ SKIP: { { $x = eval $str; is($x, "0", "binary floating point literal $str"); - is(ref($x), "Math::BigFloat", + like(ref($x), qr/^Math::BigInt(::Lite)?$/, "value is a Math::BigInt or Math::BigInt::Lite"); } } @@ -207,12 +209,12 @@ SKIP: { $x = 314; is($x, "314", "integer literal 314"); -is(ref($x), "Math::BigFloat", +like(ref($x), qr/^Math::BigInt(::Lite)?$/, "value is a Math::BigInt or Math::BigInt::Lite"); $x = 0; is($x, "0", "integer literal 0"); -is(ref($x), "Math::BigFloat", +like(ref($x), qr/^Math::BigInt(::Lite)?$/, "value is a Math::BigInt or Math::BigInt::Lite"); $x = 2 ** 255; @@ -220,7 +222,7 @@ is($x, "578960446186580977117854925043439539266" . "34992332820282019728792003956564819968", "2 ** 255"); -is(ref($x), "Math::BigFloat", +like(ref($x), qr/^Math::BigInt(::Lite)?$/, "value is a Math::BigInt or Math::BigInt::Lite"); # These are handled by "binary". @@ -233,7 +235,7 @@ is(ref($x), "Math::BigFloat", is($x, "94522879687365475552814062743484560", "hexadecimal constant 0x123456789012345678901234567890"); - is(ref($x), "Math::BigFloat", + like(ref($x), qr/^Math::BigInt(::Lite)?$/, "value is a Math::BigInt or Math::BigInt::Lite"); # octal constant @@ -241,7 +243,7 @@ is(ref($x), "Math::BigFloat", is($x, "1736132869400711976876385488263403729", "octal constant 012345676543210123456765432101234567654321"); - is(ref($x), "Math::BigFloat", + like(ref($x), qr/^Math::BigInt(::Lite)?$/, "value is a Math::BigInt or Math::BigInt::Lite"); # binary constant @@ -250,7 +252,7 @@ is(ref($x), "Math::BigFloat", "23755414508757357", "binary constant 0b0101010001100101011011000111" . "0011010010010110000101101101"); - is(ref($x), "Math::BigFloat", + like(ref($x), qr/^Math::BigInt(::Lite)?$/, "value is a Math::BigInt or Math::BigInt::Lite"); } diff --git a/cpan/bignum/t/down-mbi-up-mbf.t b/cpan/bignum/t/down-mbi-up-mbf.t new file mode 100644 index 0000000000..d1ee1c52ea --- /dev/null +++ b/cpan/bignum/t/down-mbi-up-mbf.t @@ -0,0 +1,58 @@ +# -*- mode: perl; -*- + +use strict; +use warnings; + +use Test::More tests => 14; + +use bignum; + +is(bignum -> downgrade(), "Math::BigInt", + "bignum's downgrade class is Math::BigInt"); +is(bignum -> upgrade(), "Math::BigFloat", + "bignum's upgrade class is Math::BigFloat"); + +is(Math::BigFloat -> downgrade(), "Math::BigInt", + "Math::BigFloat's downgrade class is Math::BigInt"); +is(Math::BigInt -> upgrade(), "Math::BigFloat", + "Math::BigInt's upgrade class is Math::BigFloat"); + +my $i1 = 7; +my $i2 = 2; +my $f1 = 3.75; +my $f2 = 1.25; + +is(ref($i1), "Math::BigInt", "literal $i1 is a Math::BigInt"); +is(ref($f1), "Math::BigFloat", "literal $f1 is a Math::BigFloat"); + +# Verify that the result is upgraded to a Math::BigFloat. + +cmp_ok($i1/$i2, "==", "3.5", "$i1/$i2 is 3.5"); +is(ref($i1/$i2), "Math::BigFloat", "$i1/$i2 is 3.5 as a Math::BigFloat"); + +# Verify that the result is downgraded to a Math::BigInt. + +cmp_ok($f1/$f2, "==", "3", "$f1/$f2 is 3"); +is(ref($f1/$f2), "Math::BigInt", "$f1/$f2 is 3 as a Math::BigInt"); + +# Change the upgrade class during runtime. + +SKIP: { + eval "use Math::BigRat"; + skip "Math::BigRat not installed", 4 if $@; + + bignum -> upgrade("Math::BigRat"); + + my $r1 = 3.75; + my $r2 = 1.25; + + # Verify that the result is upgraded to a Math::BigRat. + + cmp_ok($i1/$i2, "==", "3.5", "$i1/$i2 is 3.5"); + is(ref($i1/$i2), "Math::BigRat", "$i1/$i2 is 3.5 as a Math::BigRat"); + + # Verify that the result is downgraded to a Math::BigInt. + + cmp_ok($r1/$r2, "==", "3", "($r1)/($r2) is 3"); + is(ref($r1/$r2), "Math::BigInt", "($r1)/($r2) is 3 as a Math::BigInt"); +}; diff --git a/cpan/bignum/t/down-mbi-up-mbr.t b/cpan/bignum/t/down-mbi-up-mbr.t new file mode 100644 index 0000000000..a4f4642e36 --- /dev/null +++ b/cpan/bignum/t/down-mbi-up-mbr.t @@ -0,0 +1,43 @@ +# -*- mode: perl; -*- + +use strict; +use warnings; + +use Test::More; + +BEGIN { + eval "use Math::BigRat"; + plan skip_all => 'Math::BigRat required for these tests' if $@; +} + +plan tests => 10; + +use bignum upgrade => "Math::BigRat"; + +is(bignum -> downgrade(), "Math::BigInt", + "bignum's upgrade class is Math::BigInt"); +is(bignum -> upgrade(), "Math::BigRat", + "bignum's downgrade class is Math::BigInt"); + +is(Math::BigInt -> upgrade(), "Math::BigRat", + "Math::BigInt's upgrade class is Math::BigRat"); +is(Math::BigRat -> downgrade(), "Math::BigInt", + "Math::BigRat's downgrade class is Math::BigInt"); + +my $i1 = 7; +my $i2 = 2; +my $r1 = 3.75; +my $r2 = 1.25; + +is(ref($i1), "Math::BigInt", "literal $i1 is a Math::BigInt"); +is(ref($r1), "Math::BigRat", "literal $r1 is a Math::BigRat"); + +# Verify that the result is upgraded to a Math::BigRat. + +cmp_ok($i1/$i2, "==", "3.5", "$i1/$i2 is 3.5"); +is(ref($i1/$i2), "Math::BigRat", "$i1/$i2 is 3.5 as a Math::BigRat"); + +# Verify that the result is downgraded to a Math::BigInt. + +cmp_ok($r1/$r2, "==", "3", "($r1)/($r2) is 3"); +is(ref($r1/$r2), "Math::BigInt", "($r1)/($r2) is 3 as a Math::BigInt"); diff --git a/cpan/bignum/t/down-mbi-up-undef.t b/cpan/bignum/t/down-mbi-up-undef.t new file mode 100644 index 0000000000..638ce95db8 --- /dev/null +++ b/cpan/bignum/t/down-mbi-up-undef.t @@ -0,0 +1,45 @@ +# -*- mode: perl; -*- + +use strict; +use warnings; + +use Test::More; + +BEGIN { + eval "use Math::BigRat"; + plan skip_all => 'Math::BigRat required for these tests' if $@; +} + +plan tests => 10; + +use bignum upgrade => undef; + +is(bignum -> downgrade(), "Math::BigInt", + "bignum's upgrade class is Math::BigInt"); +is(bignum -> upgrade(), undef, + "bignum's downgrade class is undefined"); + +is(Math::BigInt -> upgrade(), undef, + "Math::BigInt's upgrade class is undefined"); +is(Math::BigFloat -> downgrade(), "Math::BigInt", + "Math::BigFloat's downgrade class is Math::BigInt"); + +my $i1 = 7; +my $i2 = 2; +my $f1 = 3.75; +my $f2 = 1.25; + +is(ref($i1), "Math::BigInt", "literal $i1 is a Math::BigInt"); +is(ref($f1), "Math::BigFloat", "literal $f1 is a Math::BigFloat"); + +# Verify that the result is not upgraded to a Math::BigFloat. + +cmp_ok($i1/$i2, "==", "3", "$i1/$i2 is 3"); +is(ref($i1/$i2), "Math::BigInt", + "$i1/$i2 is 3 as a Math::BigInt due to no upgrading"); + +# Verify that the result is downgraded to a Math::BigInt. + +cmp_ok($f1/$f2, "==", "3", "$f1/$f2 is 3"); +is(ref($f1/$f2), "Math::BigInt", + "$f1/$f2 is 3 as a Math::BigInt due to downgrading"); diff --git a/cpan/bignum/t/down-undef-up-mbf.t b/cpan/bignum/t/down-undef-up-mbf.t new file mode 100644 index 0000000000..971fc7e5ec --- /dev/null +++ b/cpan/bignum/t/down-undef-up-mbf.t @@ -0,0 +1,38 @@ +# -*- mode: perl; -*- + +use strict; +use warnings; + +use Test::More tests => 10; + +use bignum downgrade => undef; + +is(bignum -> downgrade(), undef, + "bignum's downgrade class is undefined"); +is(bignum -> upgrade(), "Math::BigFloat", + "bignum's upgrade class is Math::BigFloat"); + +is(Math::BigFloat -> downgrade(), undef, + "Math::BigFloat's downgrade class is undefined"); +is(Math::BigInt -> upgrade(), "Math::BigFloat", + "Math::BigInt's upgrade class is Math::BigFloat"); + +my $i1 = 7; +my $i2 = 2; +my $f1 = 3.75; +my $f2 = 1.25; + +is(ref($i1), "Math::BigInt", "literal $i1 is a Math::BigInt"); +is(ref($f1), "Math::BigFloat", "literal $f1 is a Math::BigFloat"); + +# Verify that the result is upgraded to a Math::BigFloat. + +cmp_ok($i1/$i2, "==", "3.5", "$i1/$i2 is 3.5"); +is(ref($i1/$i2), "Math::BigFloat", + "$i1/$i2 is 3.5 as a Math::BigFloat due to upgrading"); + +# Verify that the result is not downgraded to a Math::BigInt. + +cmp_ok($f1/$f2, "==", "3", "$f1/$f2 is 3"); +is(ref($f1/$f2), "Math::BigFloat", + "$f1/$f2 is 3 as a Math::BigFloat due to no downgrading"); diff --git a/cpan/bignum/t/e_pi-bigfloat.t b/cpan/bignum/t/e_pi-bigfloat.t new file mode 100644 index 0000000000..c3eaf6ddb7 --- /dev/null +++ b/cpan/bignum/t/e_pi-bigfloat.t @@ -0,0 +1,17 @@ +# -*- mode: perl; -*- + +############################################################################### +# test for e() and PI() exports + +use strict; +use warnings; + +use Test::More tests => 4; + +use bigfloat qw/e PI bexp bpi/; + +is(e, "2.718281828459045235360287471352662497757", 'e'); +is(PI, "3.141592653589793238462643383279502884197", 'PI'); + +is(bexp(1, 10), "2.718281828", 'bexp(1, 10)'); +is(bpi(10), "3.141592654", 'bpi(10)'); diff --git a/cpan/bignum/t/import-bigfloat.t b/cpan/bignum/t/import-bigfloat.t new file mode 100644 index 0000000000..d2ff343cda --- /dev/null +++ b/cpan/bignum/t/import-bigfloat.t @@ -0,0 +1,63 @@ +# -*- mode: perl; -*- + +# test the "l", "lib", "try" and "only" options: + +use strict; +use warnings; + +use Test::More tests => 21; + +use bigfloat; + +# Catch warnings. + +my $WARNINGS; +local $SIG{__WARN__} = sub { + $WARNINGS = $_[0]; +}; + +my $rc; + +$WARNINGS = ""; +$rc = eval { bigfloat -> import("l" => "foo") }; +is($@, '', + qq|eval { bigfloat -> import("l" => "foo") }|); +is($WARNINGS, "", "no warnings"); + +$WARNINGS = ""; +$rc = eval { bigfloat -> import("lib" => "foo") }; +is($@, '', + qq|eval { bigfloat -> import("lib" => "foo") }|); +is($WARNINGS, "", "no warnings"); + +$WARNINGS = ""; +$rc = eval { bigfloat -> import("try" => "foo") }; +is($@, '', + qq|eval { bigfloat -> import("try" => "foo") }|); +is($WARNINGS, "", "no warnings"); + +$WARNINGS = ""; +$rc = eval { bigfloat -> import("try" => "foo") }; +is($@, '', + qq|eval { bigfloat -> import("try" => "foo") }|); +is($WARNINGS, "", "no warnings"); + +$WARNINGS = ""; +$rc = eval { bigfloat -> import("foo" => "bar") }; +like($@, qr/^Unknown option/, + qq|eval { bigfloat -> import("foo" => "bar") }|); +is($WARNINGS, "", "no warnings"); + +$WARNINGS = ""; +$rc = eval { bigfloat -> import("only" => "bar") }; +is($@, "", + qq|eval { bigfloat -> import("only" => "bar") }|); +is($WARNINGS, "", "no warnings"); + +# test that options are only lowercase (don't see a reason why allow UPPER) + +foreach (qw/L LIB Lib T Trace TRACE V Version VERSION/) { + $rc = eval { bigfloat -> import($_ => "bar") }; + like($@, qr/^Unknown option/i, # should die + qq|eval { bigfloat -> import($_ => "bar") }|); +} diff --git a/cpan/bignum/t/in_effect.t b/cpan/bignum/t/in_effect.t index 28cc7c9dad..1b32baf5e0 100644 --- a/cpan/bignum/t/in_effect.t +++ b/cpan/bignum/t/in_effect.t @@ -17,7 +17,7 @@ use Test::More tests => 21; skip('Need at least Perl v5.9.4', 3) if $] < "5.009005"; is(bigint::in_effect(), 1, 'bigint in effect'); - is(bignum::in_effect(), undef, 'bignum not in effect'); + is(bigfloat::in_effect(), undef, 'bigfloat not in effect'); is(bigrat::in_effect(), undef, 'bigint not in effect'); } @@ -25,29 +25,29 @@ use Test::More tests => 21; no bigint; is(bigint::in_effect(), undef, 'bigint not in effect'); - is(bignum::in_effect(), undef, 'bignum not in effect'); + is(bigfloat::in_effect(), undef, 'bigfloat not in effect'); is(bigrat::in_effect(), undef, 'bigrat not in effect'); } } { - use bignum; + use bigfloat; - can_ok('bignum', qw/in_effect/); + can_ok('bigfloat', qw/in_effect/); SKIP: { skip('Need at least Perl v5.9.4', 3) if $] < "5.009005"; is(bigint::in_effect(), undef, 'bigint not in effect'); - is(bignum::in_effect(), 1, 'bignum in effect'); + is(bigfloat::in_effect(), 1, 'bigfloat in effect'); is(bigrat::in_effect(), undef, 'bigint not in effect'); } { - no bignum; + no bigfloat; is(bigint::in_effect(), undef, 'bigint not in effect'); - is(bignum::in_effect(), undef, 'bignum not in effect'); + is(bigfloat::in_effect(), undef, 'bigfloat not in effect'); is(bigrat::in_effect(), undef, 'bigrat not in effect'); } } @@ -61,7 +61,7 @@ use Test::More tests => 21; skip('Need at least Perl v5.9.4', 3) if $] < "5.009005"; is(bigint::in_effect(), undef, 'bigint not in effect'); - is(bignum::in_effect(), undef, 'bignum not in effect'); + is(bigfloat::in_effect(), undef, 'bigfloat not in effect'); is(bigrat::in_effect(), 1, 'bigint in effect'); } @@ -69,7 +69,7 @@ use Test::More tests => 21; no bigrat; is(bigint::in_effect(), undef, 'bigint not in effect'); - is(bignum::in_effect(), undef, 'bignum not in effect'); + is(bigfloat::in_effect(), undef, 'bigfloat not in effect'); is(bigrat::in_effect(), undef, 'bigrat not in effect'); } } diff --git a/cpan/bignum/t/infnan-bigfloat.t b/cpan/bignum/t/infnan-bigfloat.t new file mode 100644 index 0000000000..f94adeaebf --- /dev/null +++ b/cpan/bignum/t/infnan-bigfloat.t @@ -0,0 +1,100 @@ +# -*- mode: perl; -*- + +use strict; +use warnings; + +use Test::More tests => 66; + +use bigfloat; + +my $class = "Math::BigFloat"; +my $x; + +############################################################################### + +note("inf tests"); + +$x = 1 + inf; +note("\n\n" . $x . "\n\n"); + +$x = 1 + inf; +is(ref($x), $class, "\$x = 1 + inf makes a $class"); +is($x->bstr(), "inf", '$x = 1 + inf; $x->bstr() = "inf"'); + +$x = 1 * inf; +is(ref($x), $class, "\$x = 1 * inf makes a $class"); +is($x->bstr(), "inf", '$x = 1 * inf; $x->bstr() = "inf"'); + +# these don't work without exporting inf() +$x = inf; +is(ref($x), $class, "\$x = inf makes a $class"); +is($x->bstr(), "inf", '$x = inf; $x->bstr() = "inf"'); + +$x = inf + inf; +is(ref($x), $class, "\$x = inf + inf makes a $class"); +is($x->bstr(), "inf", '$x = inf + inf; $x->bstr() = "inf"'); + +$x = inf * inf; +is(ref($x), $class, "\$x = inf * inf makes a $class"); +is($x->bstr(), "inf", '$x = inf * inf; $x->bstr() = "inf"'); + +############################################################################### + +note("NaN tests"); + +$x = 1 + NaN; +is(ref($x), $class, "\$x = 1 + NaN makes a $class"); +is($x->bstr(), "NaN", '$x = 1 + NaN; $x->bstr() = "NaN"'); + +$x = 1 * NaN; +is(ref($x), $class, "\$x = 1 * NaN makes a $class"); +is($x->bstr(), "NaN", '$x = 1 * NaN; $x->bstr() = "NaN"'); + +# these don't work without exporting NaN() +$x = NaN; +is(ref($x), $class, "\$x = NaN makes a $class"); +is($x->bstr(), "NaN", '$x = NaN; $x->bstr() = "NaN"'); + +$x = NaN + NaN; +is(ref($x), $class, "\$x = NaN + NaN makes a $class"); +is($x->bstr(), "NaN", '$x = NaN + NaN; $x->bstr() = "NaN"'); + +$x = NaN * NaN; +is(ref($x), $class, "\$x = NaN * NaN makes a $class"); +is($x->bstr(), "NaN", '$x = NaN * NaN; $x->bstr() = "NaN"'); + +############################################################################### + +note("mixed tests"); + +# these don't work without exporting NaN() or inf() + +$x = NaN + inf; +is(ref($x), $class, "\$x = NaN + inf makes a $class"); +is($x->bstr(), "NaN", '$x = NaN + inf; $x->bstr() = "NaN"'); + +$x = NaN * inf; +is(ref($x), $class, "\$x = NaN * inf makes a $class"); +is($x->bstr(), "NaN", '$x = NaN * inf; $x->bstr() = "NaN"'); + +$x = inf * NaN; +is(ref($x), $class, "\$x = inf * NaN makes a $class"); +is($x->bstr(), "NaN", '$x = inf * NaN; $x->bstr() = "NaN"'); + +############################################################################### +# inf and NaN as strings. + +for my $nan (qw/ nan naN nAn nAN Nan NaN NAn NAN /) { + my $x = 1 + $nan; + is($x->bstr(), "NaN", qq|\$x = 1 + "$nan"|); + is(ref($x), $class, "\$x is a $class"); +} + +for my $inf (qw/ inf inF iNf iNF Inf InF INf INF + infinity Infinity InFiNiTy iNfInItY + /) +{ + my $x = 1 + $inf; + is($x->bstr(), "inf", qq|\$x = 1 + "$inf"|); + is(ref($x), $class, "\$x is a $class"); +} diff --git a/cpan/bignum/t/infnan-bignum.t b/cpan/bignum/t/infnan-bignum.t index 3c4691051d..9224b823af 100644 --- a/cpan/bignum/t/infnan-bignum.t +++ b/cpan/bignum/t/infnan-bignum.t @@ -5,9 +5,9 @@ use warnings; use Test::More tests => 66; -use bignum; +use bignum downgrade => undef; -my $class = "Math::BigFloat"; +my $class = "Math::BigInt"; my $x; ############################################################################### diff --git a/cpan/bignum/t/option_a-bignum.t b/cpan/bignum/t/option_a-bignum.t new file mode 100644 index 0000000000..429bad3bba --- /dev/null +++ b/cpan/bignum/t/option_a-bignum.t @@ -0,0 +1,18 @@ +# -*- mode: perl; -*- + +use strict; +use warnings; + +use Test::More tests => 4; + +{ + use bignum a => "12"; + for my $class ("Math::BigInt", "Math::BigFloat") { + cmp_ok($class -> accuracy(), "==", 12, "$class accuracy = 12"); + } + + bignum -> import(accuracy => "23"); + for my $class ("Math::BigInt", "Math::BigFloat") { + cmp_ok($class -> accuracy(), "==", 23, "$class accuracy = 23"); + } +} diff --git a/cpan/bignum/t/option_a.t b/cpan/bignum/t/option_a.t index 6cd02268e1..7d4f05da78 100644 --- a/cpan/bignum/t/option_a.t +++ b/cpan/bignum/t/option_a.t @@ -18,19 +18,19 @@ use Test::More tests => 6; { my $class = "Math::BigFloat"; - use bignum a => "12"; - cmp_ok($class -> accuracy(), "==", 12, "$class accuracy = 12"); + use bigfloat a => "13"; + cmp_ok($class -> accuracy(), "==", 13, "$class accuracy = 12"); - bignum -> import(accuracy => "23"); - cmp_ok($class -> accuracy(), "==", 23, "$class accuracy = 23"); + bigfloat -> import(accuracy => "24"); + cmp_ok($class -> accuracy(), "==", 24, "$class accuracy = 23"); } { my $class = "Math::BigRat"; - use bigrat a => "12"; - cmp_ok($class -> accuracy(), "==", 12, "$class accuracy = 12"); + use bigrat a => "14"; + cmp_ok($class -> accuracy(), "==", 14, "$class accuracy = 12"); - bigrat -> import(accuracy => "23"); - cmp_ok($class -> accuracy(), "==", 23, "$class accuracy = 23"); + bigrat -> import(accuracy => "25"); + cmp_ok($class -> accuracy(), "==", 25, "$class accuracy = 23"); } diff --git a/cpan/bignum/t/option_l-bigfloat.t b/cpan/bignum/t/option_l-bigfloat.t new file mode 100644 index 0000000000..a8f8fd94ac --- /dev/null +++ b/cpan/bignum/t/option_l-bigfloat.t @@ -0,0 +1,72 @@ +# -*- mode: perl; -*- + +# test the "l", "lib", "try" and "only" options: + +use strict; +use warnings; + +use Test::More tests => 14; + +use bigfloat; + +# Catch warning. + +my $warning; +local $SIG{__WARN__} = sub { + $warning = $_[0]; +}; + +my $rc; + +$warning = ""; +$rc = eval { bigfloat->import("l" => "foo") }; +subtest qq|eval { bigfloat->import("l" => "foo") }| => sub { + plan tests => 2; + + is($@, '', "didn't die"); + is($warning, "", "didn't get a warning"); +}; + +$warning = ""; +$rc = eval { bigfloat->import("lib" => "foo") }; +subtest qq|eval { bigfloat->import("lib" => "foo") }| => sub { + plan tests => 2; + + is($@, '', "didn't die"); + is($warning, "", "didn't get a warning"); +}; + +$warning = ""; +$rc = eval { bigfloat->import("try" => "foo") }; +subtest qq|eval { bigfloat->import("try" => "foo") }| => sub { + plan tests => 2; + + is($@, '', "didn't die"); + is($warning, "", "didn't get a warning"); +}; + +$warning = ""; +$rc = eval { bigfloat->import("only" => "foo") }; +subtest qq|eval { bigfloat->import("only" => "foo") }| => sub { + plan tests => 2; + + is($@, '', "didn't die"); + is($warning, "", "didn't get a warning"); +}; + +$warning = ""; +$rc = eval { bigfloat->import("foo" => "bar") }; +subtest qq|eval { bigfloat->import("foo" => "bar") }| => sub { + plan tests => 2; + + is($@, '', "didn't die"); + is($warning, "", "didn't get a warning"); +}; + +# test that options are only lowercase (don't see a reason why allow UPPER) + +foreach (qw/L LIB Lib T Trace TRACE V Version VERSION/) { + $rc = eval { bigfloat->import($_ => "bar") }; + like($@, qr/^Unknown option /i, + qq|eval { bigfloat->import($_ => "bar") }|); +} diff --git a/cpan/bignum/t/option_l-bigint.t b/cpan/bignum/t/option_l-bigint.t new file mode 100644 index 0000000000..fb02c5f198 --- /dev/null +++ b/cpan/bignum/t/option_l-bigint.t @@ -0,0 +1,72 @@ +# -*- mode: perl; -*- + +# test the "l", "lib", "try" and "only" options: + +use strict; +use warnings; + +use Test::More tests => 14; + +use bigint; + +# Catch warning. + +my $warning; +local $SIG{__WARN__} = sub { + $warning = $_[0]; +}; + +my $rc; + +$warning = ""; +$rc = eval { bigint->import("l" => "foo") }; +subtest qq|eval { bigint->import("l" => "foo") }| => sub { + plan tests => 2; + + is($@, '', "didn't die"); + is($warning, "", "didn't get a warning"); +}; + +$warning = ""; +$rc = eval { bigint->import("lib" => "foo") }; +subtest qq|eval { bigint->import("lib" => "foo") }| => sub { + plan tests => 2; + + is($@, '', "didn't die"); + is($warning, "", "didn't get a warning"); +}; + +$warning = ""; +$rc = eval { bigint->import("try" => "foo") }; +subtest qq|eval { bigint->import("try" => "foo") }| => sub { + plan tests => 2; + + is($@, '', "didn't die"); + is($warning, "", "didn't get a warning"); +}; + +$warning = ""; +$rc = eval { bigint->import("only" => "foo") }; +subtest qq|eval { bigint->import("only" => "foo") }| => sub { + plan tests => 2; + + is($@, '', "didn't die"); + is($warning, "", "didn't get a warning"); +}; + +$warning = ""; +$rc = eval { bigint->import("foo" => "bar") }; +subtest qq|eval { bigint->import("foo" => "bar") }| => sub { + plan tests => 2; + + is($@, '', "didn't die"); + is($warning, "", "didn't get a warning"); +}; + +# test that options are only lowercase (don't see a reason why allow UPPER) + +foreach (qw/L LIB Lib T Trace TRACE V Version VERSION/) { + $rc = eval { bigint->import($_ => "bar") }; + like($@, qr/^Unknown option /i, + qq|eval { bigint->import($_ => "bar") }|); +} diff --git a/cpan/bignum/t/option_l.t b/cpan/bignum/t/option_l-bignum.t index 74a1ce7ece..74a1ce7ece 100644 --- a/cpan/bignum/t/option_l.t +++ b/cpan/bignum/t/option_l-bignum.t diff --git a/cpan/bignum/t/option_l-bigrat.t b/cpan/bignum/t/option_l-bigrat.t new file mode 100644 index 0000000000..46e55e2fea --- /dev/null +++ b/cpan/bignum/t/option_l-bigrat.t @@ -0,0 +1,72 @@ +# -*- mode: perl; -*- + +# test the "l", "lib", "try" and "only" options: + +use strict; +use warnings; + +use Test::More tests => 14; + +use bigrat; + +# Catch warning. + +my $warning; +local $SIG{__WARN__} = sub { + $warning = $_[0]; +}; + +my $rc; + +$warning = ""; +$rc = eval { bigrat->import("l" => "foo") }; +subtest qq|eval { bigrat->import("l" => "foo") }| => sub { + plan tests => 2; + + is($@, '', "didn't die"); + is($warning, "", "didn't get a warning"); +}; + +$warning = ""; +$rc = eval { bigrat->import("lib" => "foo") }; +subtest qq|eval { bigrat->import("lib" => "foo") }| => sub { + plan tests => 2; + + is($@, '', "didn't die"); + is($warning, "", "didn't get a warning"); +}; + +$warning = ""; +$rc = eval { bigrat->import("try" => "foo") }; +subtest qq|eval { bigrat->import("try" => "foo") }| => sub { + plan tests => 2; + + is($@, '', "didn't die"); + is($warning, "", "didn't get a warning"); +}; + +$warning = ""; +$rc = eval { bigrat->import("only" => "foo") }; +subtest qq|eval { bigrat->import("only" => "foo") }| => sub { + plan tests => 2; + + is($@, '', "didn't die"); + is($warning, "", "didn't get a warning"); +}; + +$warning = ""; +$rc = eval { bigrat->import("foo" => "bar") }; +subtest qq|eval { bigrat->import("foo" => "bar") }| => sub { + plan tests => 2; + + is($@, '', "didn't die"); + is($warning, "", "didn't get a warning"); +}; + +# test that options are only lowercase (don't see a reason why allow UPPER) + +foreach (qw/L LIB Lib T Trace TRACE V Version VERSION/) { + $rc = eval { bigrat->import($_ => "bar") }; + like($@, qr/^Unknown option /i, + qq|eval { bigrat->import($_ => "bar") }|); +} diff --git a/cpan/bignum/t/option_p-bignum.t b/cpan/bignum/t/option_p-bignum.t new file mode 100644 index 0000000000..99a42edd15 --- /dev/null +++ b/cpan/bignum/t/option_p-bignum.t @@ -0,0 +1,18 @@ +# -*- mode: perl; -*- + +use strict; +use warnings; + +use Test::More tests => 4; + +{ + use bignum p => "12"; + for my $class ("Math::BigInt", "Math::BigFloat") { + cmp_ok($class -> precision(), "==", 12, "$class precision = 12"); + } + + bignum -> import(precision => "23"); + for my $class ("Math::BigInt", "Math::BigFloat") { + cmp_ok($class -> precision(), "==", 23, "$class precision = 23"); + } +} diff --git a/cpan/bignum/t/option_p.t b/cpan/bignum/t/option_p.t index 672d73e199..c1c16db0a9 100644 --- a/cpan/bignum/t/option_p.t +++ b/cpan/bignum/t/option_p.t @@ -18,19 +18,19 @@ use Test::More tests => 6; { my $class = "Math::BigFloat"; - use bignum p => "12"; - cmp_ok($class -> precision(), "==", 12, "$class precision = 12"); + use bigfloat p => "13"; + cmp_ok($class -> precision(), "==", 13, "$class precision = 12"); - bignum -> import(precision => "23"); - cmp_ok($class -> precision(), "==", 23, "$class precision = 23"); + bigfloat -> import(precision => "24"); + cmp_ok($class -> precision(), "==", 24, "$class precision = 23"); } { my $class = "Math::BigRat"; - use bigrat p => "12"; - cmp_ok($class -> precision(), "==", 12, "$class precision = 12"); + use bigrat p => "14"; + cmp_ok($class -> precision(), "==", 14, "$class precision = 12"); - bigrat -> import(precision => "23"); - cmp_ok($class -> precision(), "==", 23, "$class precision = 23"); + bigrat -> import(precision => "25"); + cmp_ok($class -> precision(), "==", 25, "$class precision = 23"); } diff --git a/cpan/bignum/t/overrides.t b/cpan/bignum/t/overrides.t index c79563182b..deec75e680 100644 --- a/cpan/bignum/t/overrides.t +++ b/cpan/bignum/t/overrides.t @@ -35,27 +35,27 @@ BEGIN { { skip "no lexical hex/oct", 2 unless $] > "5.009004"; is ref hex(1), 'Math::BigInt', - 'bigint hex() works when bignum and bigrat are loaded'; + 'bigint hex() works when bigfloat and bigrat are loaded'; is ref oct(1), 'Math::BigInt', - 'bigint oct() works when bignum and bigrat are loaded'; + 'bigint oct() works when bigfloat and bigrat are loaded'; } } { - use bignum; + use bigfloat; $_ = "20"; - is hex, "32", 'bignum hex override without arguments infers $_'; - is oct, "16", 'bignum oct override without arguments infers $_'; + is hex, "32", 'bigfloat hex override without arguments infers $_'; + is oct, "16", 'bigfloat oct override without arguments infers $_'; @_ = 1..20; - is hex(@_), "32", 'bignum hex override provides scalar context'; - is oct(@_), "16", 'bignum oct override provides scalar context'; + is hex(@_), "32", 'bigfloat hex override provides scalar context'; + is oct(@_), "16", 'bigfloat oct override provides scalar context'; SKIP: { skip "no lexical hex/oct", 2 unless $] > "5.009004"; is ref hex(1), 'Math::BigFloat', - 'bignum hex() works when bigint and bigrat are loaded'; + 'bigfloat hex() works when bigint and bigrat are loaded'; is ref oct(1), 'Math::BigFloat', - 'bignum oct() works when bigint and bigrat are loaded'; + 'bigfloat oct() works when bigint and bigrat are loaded'; } } @@ -71,9 +71,9 @@ BEGIN { { skip "no lexical hex/oct", 2 unless $] > "5.009004"; is ref hex(1), 'Math::BigRat', - 'bigrat hex() works when bignum and bigint are loaded'; + 'bigrat hex() works when bigfloat and bigint are loaded'; is ref oct(1), 'Math::BigRat', - 'bigrat oct() works when bignum and bigint are loaded'; + 'bigrat oct() works when bigfloat and bigint are loaded'; } } @@ -99,11 +99,11 @@ is $oct_called, 1, 'existing oct overrides are called'; { package _importer2; - use bignum 'hex', 'oct'; - ::is \&hex, \&bignum::hex, 'bignum exports hex'; - ::is \&oct, \&bignum::oct, 'bignum exports oct'; -# ::is \&hex, \&bigint::hex, 'bignum exports same hex as bigint'; -# ::is \&oct, \&bigint::oct, 'bignum exports same oct as bigint'; + use bigfloat 'hex', 'oct'; + ::is \&hex, \&bigfloat::hex, 'bigfloat exports hex'; + ::is \&oct, \&bigfloat::oct, 'bigfloat exports oct'; +# ::is \&hex, \&bigint::hex, 'bigfloat exports same hex as bigint'; +# ::is \&oct, \&bigint::oct, 'bigfloat exports same oct as bigint'; } { diff --git a/cpan/bignum/t/scope-bigfloat.t b/cpan/bignum/t/scope-bigfloat.t new file mode 100644 index 0000000000..cada14605f --- /dev/null +++ b/cpan/bignum/t/scope-bigfloat.t @@ -0,0 +1,35 @@ +# -*- mode: perl; -*- + +############################################################################### +# Test "no bigfloat;" and overloading of hex()/oct() for newer Perls + +use strict; +use warnings; + +use Test::More tests => 10; + +# no :hex and :oct means these do not get overloaded for older Perls: +use bigfloat; + +isnt(ref(1), '', 'is in effect'); +isnt(ref(2.0), '', 'is in effect'); +isnt(ref(0x20), '', 'is in effect'); + +SKIP: { + # Quote numbers due to "use bigfloat;" + skip('Need at least Perl v5.9.4', "2") if $] < "5.009004"; + + is(ref(hex(9)), 'Math::BigFloat', 'hex is overloaded'); + is(ref(oct(07)), 'Math::BigFloat', 'oct is overloaded'); +} + +{ + no bigfloat; + + is(ref(1), '', 'is not in effect'); + is(ref(2.0), '', 'is not in effect'); + is(ref(0x20), '', 'is not in effect'); + + is(ref(hex(9)), '', 'hex is not overloaded'); + is(ref(oct(07)), '', 'oct is not overloaded'); +} diff --git a/cpan/bignum/t/scope-bignum.t b/cpan/bignum/t/scope-bignum.t index c10b24978c..555aed73e2 100644 --- a/cpan/bignum/t/scope-bignum.t +++ b/cpan/bignum/t/scope-bignum.t @@ -19,8 +19,8 @@ SKIP: { # Quote numbers due to "use bignum;" skip('Need at least Perl v5.9.4', "2") if $] < "5.009004"; - is(ref(hex(9)), 'Math::BigFloat', 'hex is overloaded'); - is(ref(oct(07)), 'Math::BigFloat', 'oct is overloaded'); + is(ref(hex(9)), 'Math::BigInt', 'hex is overloaded'); + is(ref(oct(07)), 'Math::BigInt', 'oct is overloaded'); } { diff --git a/cpan/bignum/t/scope-nested-const.t b/cpan/bignum/t/scope-nested-const.t index b2f2a4d039..3c0279292d 100644 --- a/cpan/bignum/t/scope-nested-const.t +++ b/cpan/bignum/t/scope-nested-const.t @@ -3,220 +3,272 @@ use strict; use warnings; -use Test::More tests => 48; +use Test::More; -note "\nbigint -> bignum -> bigrat\n\n"; +plan skip_all => 'Need at least Perl v5.10.1' if $] < "5.010001"; + +plan tests => 96; + +note "\nbigint -> bigfloat -> bigrat\n\n"; { note "use bigint;"; use bigint; - is(ref(1), "Math::BigInt"); + is(ref(hex("1")), "Math::BigInt", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigInt", 'ref(oct("1"))'); { - note "use bignum;"; - use bignum; - is(ref(1), "Math::BigFloat"); + note "use bigfloat;"; + use bigfloat; + is(ref(hex("1")), "Math::BigFloat", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigFloat", 'ref(oct("1"))'); { note "use bigrat;"; use bigrat; - is(ref(1), "Math::BigRat"); + is(ref(hex("1")), "Math::BigRat", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigRat", 'ref(oct("1"))'); note "no bigrat;"; no bigrat; - is(ref(1), ""); + is(ref(hex("1")), "", 'ref(hex("1"))'); + is(ref(oct("1")), "", 'ref(oct("1"))'); } - is(ref(1), "Math::BigFloat"); + is(ref(hex("1")), "Math::BigFloat", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigFloat", 'ref(oct("1"))'); - note "no bignum;"; - no bignum; - is(ref(1), ""); + note "no bigfloat;"; + no bigfloat; + is(ref(hex("1")), "", 'ref(hex("1"))'); + is(ref(oct("1")), "", 'ref(oct("1"))'); } - is(ref(1), "Math::BigInt"); + is(ref(hex("1")), "Math::BigInt", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigInt", 'ref(oct("1"))'); note "no bigint;"; no bigint; - is(ref(1), ""); + is(ref(hex("1")), "", 'ref(hex("1"))'); + is(ref(oct("1")), "", 'ref(oct("1"))'); } -note "\nbigint -> bigrat -> bignum\n\n"; +note "\nbigint -> bigrat -> bigfloat\n\n"; { note "use bigint;"; use bigint; - is(ref(1), "Math::BigInt"); + is(ref(hex("1")), "Math::BigInt", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigInt", 'ref(oct("1"))'); { note "use bigrat;"; use bigrat; - is(ref(1), "Math::BigRat"); + is(ref(hex("1")), "Math::BigRat", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigRat", 'ref(oct("1"))'); { - note "use bignum;"; - use bignum; - is(ref(1), "Math::BigFloat"); - - note "no bignum;"; - no bignum; - is(ref(1), ""); + note "use bigfloat;"; + use bigfloat; + is(ref(hex("1")), "Math::BigFloat", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigFloat", 'ref(oct("1"))'); + + note "no bigfloat;"; + no bigfloat; + is(ref(hex("1")), "", 'ref(hex("1"))'); + is(ref(oct("1")), "", 'ref(oct("1"))'); } - is(ref(1), "Math::BigRat"); + is(ref(hex("1")), "Math::BigRat", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigRat", 'ref(oct("1"))'); note "no bigrat;"; no bigrat; - is(ref(1), ""); + is(ref(hex("1")), "", 'ref(hex("1"))'); + is(ref(oct("1")), "", 'ref(oct("1"))'); } - is(ref(1), "Math::BigInt"); + is(ref(hex("1")), "Math::BigInt", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigInt", 'ref(oct("1"))'); note "no bigint;"; no bigint; - is(ref(1), ""); + is(ref(hex("1")), "", 'ref(hex("1"))'); + is(ref(oct("1")), "", 'ref(oct("1"))'); } -note "\nbignum -> bigint -> bigrat\n\n"; +note "\nbigfloat -> bigint -> bigrat\n\n"; { - note "use bignum;"; - use bignum; - is(ref(1), "Math::BigFloat"); + note "use bigfloat;"; + use bigfloat; + is(ref(hex("1")), "Math::BigFloat", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigFloat", 'ref(oct("1"))'); { note "use bigint;"; use bigint; - is(ref(1), "Math::BigInt"); + is(ref(hex("1")), "Math::BigInt", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigInt", 'ref(oct("1"))'); { note "use bigrat;"; use bigrat; - is(ref(1), "Math::BigRat"); + is(ref(hex("1")), "Math::BigRat", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigRat", 'ref(oct("1"))'); note "no bigrat;"; no bigrat; - is(ref(1), ""); + is(ref(hex("1")), "", 'ref(hex("1"))'); + is(ref(oct("1")), "", 'ref(oct("1"))'); } - is(ref(1), "Math::BigInt"); + is(ref(hex("1")), "Math::BigInt", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigInt", 'ref(oct("1"))'); note "no bigint;"; no bigint; - is(ref(1), ""); + is(ref(hex("1")), "", 'ref(hex("1"))'); + is(ref(oct("1")), "", 'ref(oct("1"))'); } - is(ref(1), "Math::BigFloat"); + is(ref(hex("1")), "Math::BigFloat", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigFloat", 'ref(oct("1"))'); - note "no bignum;"; - no bignum; - is(ref(1), ""); + note "no bigfloat;"; + no bigfloat; + is(ref(hex("1")), "", 'ref(hex("1"))'); + is(ref(oct("1")), "", 'ref(oct("1"))'); } -note "\nbignum -> bigrat -> bigint\n\n"; +note "\nbigfloat -> bigrat -> bigint\n\n"; { - note "use bignum;"; - use bignum; - is(ref(1), "Math::BigFloat"); + note "use bigfloat;"; + use bigfloat; + is(ref(hex("1")), "Math::BigFloat", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigFloat", 'ref(oct("1"))'); { note "use bigrat;"; use bigrat; - is(ref(1), "Math::BigRat"); + is(ref(hex("1")), "Math::BigRat", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigRat", 'ref(oct("1"))'); { note "use bigint;"; use bigint; - is(ref(1), "Math::BigInt"); + is(ref(hex("1")), "Math::BigInt", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigInt", 'ref(oct("1"))'); note "no bigint;"; no bigint; - is(ref(1), ""); + is(ref(hex("1")), "", 'ref(hex("1"))'); + is(ref(oct("1")), "", 'ref(oct("1"))'); } - is(ref(1), "Math::BigRat"); + is(ref(hex("1")), "Math::BigRat", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigRat", 'ref(oct("1"))'); note "no bigrat;"; no bigrat; - is(ref(1), ""); + is(ref(hex("1")), "", 'ref(hex("1"))'); + is(ref(oct("1")), "", 'ref(oct("1"))'); } - is(ref(1), "Math::BigFloat"); + is(ref(hex("1")), "Math::BigFloat", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigFloat", 'ref(oct("1"))'); - note "no bignum;"; - no bignum; - is(ref(1), ""); + note "no bigfloat;"; + no bigfloat; + is(ref(hex("1")), "", 'ref(hex("1"))'); + is(ref(oct("1")), "", 'ref(oct("1"))'); } -note "\nbigrat -> bigint -> bignum\n\n"; +note "\nbigrat -> bigint -> bigfloat\n\n"; { note "use bigrat;"; use bigrat; - is(ref(1), "Math::BigRat"); + is(ref(hex("1")), "Math::BigRat", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigRat", 'ref(oct("1"))'); { note "use bigint;"; use bigint; - is(ref(1), "Math::BigInt"); + is(ref(hex("1")), "Math::BigInt", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigInt", 'ref(oct("1"))'); { - note "use bignum;"; - use bignum; - is(ref(1), "Math::BigFloat"); - - note "no bignum;"; - no bignum; - is(ref(1), ""); + note "use bigfloat;"; + use bigfloat; + is(ref(hex("1")), "Math::BigFloat", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigFloat", 'ref(oct("1"))'); + + note "no bigfloat;"; + no bigfloat; + is(ref(hex("1")), "", 'ref(hex("1"))'); + is(ref(oct("1")), "", 'ref(oct("1"))'); } - is(ref(1), "Math::BigInt"); + is(ref(hex("1")), "Math::BigInt", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigInt", 'ref(oct("1"))'); note "no bigint;"; no bigint; - is(ref(1), ""); + is(ref(hex("1")), "", 'ref(hex("1"))'); + is(ref(oct("1")), "", 'ref(oct("1"))'); } - is(ref(1), "Math::BigRat"); + is(ref(hex("1")), "Math::BigRat", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigRat", 'ref(oct("1"))'); note "no bigrat;"; no bigrat; - is(ref(1), ""); + is(ref(hex("1")), "", 'ref(hex("1"))'); + is(ref(oct("1")), "", 'ref(oct("1"))'); } -note "\nbigrat -> bignum -> bigint\n\n"; +note "\nbigrat -> bigfloat -> bigint\n\n"; { note "use bigrat;"; use bigrat; - is(ref(1), "Math::BigRat"); + is(ref(hex("1")), "Math::BigRat", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigRat", 'ref(oct("1"))'); { - note "use bignum;"; - use bignum; - is(ref(1), "Math::BigFloat"); + note "use bigfloat;"; + use bigfloat; + is(ref(hex("1")), "Math::BigFloat", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigFloat", 'ref(oct("1"))'); { note "use bigint;"; use bigint; - is(ref(1), "Math::BigInt"); + is(ref(hex("1")), "Math::BigInt", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigInt", 'ref(oct("1"))'); note "no bigint;"; no bigint; - is(ref(1), ""); + is(ref(hex("1")), "", 'ref(hex("1"))'); + is(ref(oct("1")), "", 'ref(oct("1"))'); } - is(ref(1), "Math::BigFloat"); + is(ref(hex("1")), "Math::BigFloat", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigFloat", 'ref(oct("1"))'); - note "no bignum;"; - no bignum; - is(ref(1), ""); + note "no bigfloat;"; + no bigfloat; + is(ref(hex("1")), "", 'ref(hex("1"))'); + is(ref(oct("1")), "", 'ref(oct("1"))'); } - is(ref(1), "Math::BigRat"); + is(ref(hex("1")), "Math::BigRat", 'ref(hex("1"))'); + is(ref(oct("1")), "Math::BigRat", 'ref(oct("1"))'); note "no bigrat;"; no bigrat; - is(ref(1), ""); + is(ref(hex("1")), "", 'ref(hex("1"))'); + is(ref(oct("1")), "", 'ref(oct("1"))'); } diff --git a/cpan/bignum/t/scope-nested-hex-oct.t b/cpan/bignum/t/scope-nested-hex-oct.t index df26efa7f4..3c0279292d 100644 --- a/cpan/bignum/t/scope-nested-hex-oct.t +++ b/cpan/bignum/t/scope-nested-hex-oct.t @@ -9,7 +9,7 @@ plan skip_all => 'Need at least Perl v5.10.1' if $] < "5.010001"; plan tests => 96; -note "\nbigint -> bignum -> bigrat\n\n"; +note "\nbigint -> bigfloat -> bigrat\n\n"; { note "use bigint;"; @@ -18,8 +18,8 @@ note "\nbigint -> bignum -> bigrat\n\n"; is(ref(oct("1")), "Math::BigInt", 'ref(oct("1"))'); { - note "use bignum;"; - use bignum; + note "use bigfloat;"; + use bigfloat; is(ref(hex("1")), "Math::BigFloat", 'ref(hex("1"))'); is(ref(oct("1")), "Math::BigFloat", 'ref(oct("1"))'); @@ -38,8 +38,8 @@ note "\nbigint -> bignum -> bigrat\n\n"; is(ref(hex("1")), "Math::BigFloat", 'ref(hex("1"))'); is(ref(oct("1")), "Math::BigFloat", 'ref(oct("1"))'); - note "no bignum;"; - no bignum; + note "no bigfloat;"; + no bigfloat; is(ref(hex("1")), "", 'ref(hex("1"))'); is(ref(oct("1")), "", 'ref(oct("1"))'); } @@ -53,7 +53,7 @@ note "\nbigint -> bignum -> bigrat\n\n"; is(ref(oct("1")), "", 'ref(oct("1"))'); } -note "\nbigint -> bigrat -> bignum\n\n"; +note "\nbigint -> bigrat -> bigfloat\n\n"; { note "use bigint;"; @@ -68,13 +68,13 @@ note "\nbigint -> bigrat -> bignum\n\n"; is(ref(oct("1")), "Math::BigRat", 'ref(oct("1"))'); { - note "use bignum;"; - use bignum; + note "use bigfloat;"; + use bigfloat; is(ref(hex("1")), "Math::BigFloat", 'ref(hex("1"))'); is(ref(oct("1")), "Math::BigFloat", 'ref(oct("1"))'); - note "no bignum;"; - no bignum; + note "no bigfloat;"; + no bigfloat; is(ref(hex("1")), "", 'ref(hex("1"))'); is(ref(oct("1")), "", 'ref(oct("1"))'); } @@ -97,11 +97,11 @@ note "\nbigint -> bigrat -> bignum\n\n"; is(ref(oct("1")), "", 'ref(oct("1"))'); } -note "\nbignum -> bigint -> bigrat\n\n"; +note "\nbigfloat -> bigint -> bigrat\n\n"; { - note "use bignum;"; - use bignum; + note "use bigfloat;"; + use bigfloat; is(ref(hex("1")), "Math::BigFloat", 'ref(hex("1"))'); is(ref(oct("1")), "Math::BigFloat", 'ref(oct("1"))'); @@ -135,17 +135,17 @@ note "\nbignum -> bigint -> bigrat\n\n"; is(ref(hex("1")), "Math::BigFloat", 'ref(hex("1"))'); is(ref(oct("1")), "Math::BigFloat", 'ref(oct("1"))'); - note "no bignum;"; - no bignum; + note "no bigfloat;"; + no bigfloat; is(ref(hex("1")), "", 'ref(hex("1"))'); is(ref(oct("1")), "", 'ref(oct("1"))'); } -note "\nbignum -> bigrat -> bigint\n\n"; +note "\nbigfloat -> bigrat -> bigint\n\n"; { - note "use bignum;"; - use bignum; + note "use bigfloat;"; + use bigfloat; is(ref(hex("1")), "Math::BigFloat", 'ref(hex("1"))'); is(ref(oct("1")), "Math::BigFloat", 'ref(oct("1"))'); @@ -179,13 +179,13 @@ note "\nbignum -> bigrat -> bigint\n\n"; is(ref(hex("1")), "Math::BigFloat", 'ref(hex("1"))'); is(ref(oct("1")), "Math::BigFloat", 'ref(oct("1"))'); - note "no bignum;"; - no bignum; + note "no bigfloat;"; + no bigfloat; is(ref(hex("1")), "", 'ref(hex("1"))'); is(ref(oct("1")), "", 'ref(oct("1"))'); } -note "\nbigrat -> bigint -> bignum\n\n"; +note "\nbigrat -> bigint -> bigfloat\n\n"; { note "use bigrat;"; @@ -200,13 +200,13 @@ note "\nbigrat -> bigint -> bignum\n\n"; is(ref(oct("1")), "Math::BigInt", 'ref(oct("1"))'); { - note "use bignum;"; - use bignum; + note "use bigfloat;"; + use bigfloat; is(ref(hex("1")), "Math::BigFloat", 'ref(hex("1"))'); is(ref(oct("1")), "Math::BigFloat", 'ref(oct("1"))'); - note "no bignum;"; - no bignum; + note "no bigfloat;"; + no bigfloat; is(ref(hex("1")), "", 'ref(hex("1"))'); is(ref(oct("1")), "", 'ref(oct("1"))'); } @@ -229,7 +229,7 @@ note "\nbigrat -> bigint -> bignum\n\n"; is(ref(oct("1")), "", 'ref(oct("1"))'); } -note "\nbigrat -> bignum -> bigint\n\n"; +note "\nbigrat -> bigfloat -> bigint\n\n"; { note "use bigrat;"; @@ -238,8 +238,8 @@ note "\nbigrat -> bignum -> bigint\n\n"; is(ref(oct("1")), "Math::BigRat", 'ref(oct("1"))'); { - note "use bignum;"; - use bignum; + note "use bigfloat;"; + use bigfloat; is(ref(hex("1")), "Math::BigFloat", 'ref(hex("1"))'); is(ref(oct("1")), "Math::BigFloat", 'ref(oct("1"))'); @@ -258,8 +258,8 @@ note "\nbigrat -> bignum -> bigint\n\n"; is(ref(hex("1")), "Math::BigFloat", 'ref(hex("1"))'); is(ref(oct("1")), "Math::BigFloat", 'ref(oct("1"))'); - note "no bignum;"; - no bignum; + note "no bigfloat;"; + no bigfloat; is(ref(hex("1")), "", 'ref(hex("1"))'); is(ref(oct("1")), "", 'ref(oct("1"))'); } |