Skip to content

Commit

Permalink
cpan/Math-BigInt - Update to version 2.001001
Browse files Browse the repository at this point in the history
2.001001 2023-11-21

 * Fix CPAN RT #150469
  • Loading branch information
Peter John Acklam authored and jkeenan committed Nov 25, 2023
1 parent 67fb941 commit 6da59fe
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 47 deletions.
3 changes: 2 additions & 1 deletion Porting/Maintainers.pl
Expand Up @@ -757,7 +757,8 @@ package Maintainers;
},

'Math::BigInt' => {
'DISTRIBUTION' => 'PJACKLAM/Math-BigInt-2.001000.tar.gz',
'DISTRIBUTION' => 'PJACKLAM/Math-BigInt-2.001001.tar.gz',
'SYNCINFO' => 'jkeenan on Fri Nov 24 20:23:52 2023',
'SYNCINFO' => 'jkeenan on Tue Nov 14 17:22:07 2023',
'FILES' => q[cpan/Math-BigInt],
'EXCLUDED' => [
Expand Down
35 changes: 26 additions & 9 deletions cpan/Math-BigInt/lib/Math/BigFloat.pm
Expand Up @@ -20,7 +20,7 @@ use Carp qw< carp croak >;
use Scalar::Util qw< blessed >;
use Math::BigInt qw< >;

our $VERSION = '2.001000';
our $VERSION = '2.001001';
$VERSION =~ tr/_//d;

require Exporter;
Expand Down Expand Up @@ -1332,14 +1332,16 @@ sub as_int {

return $x -> copy() if $x -> isa("Math::BigInt");

# disable upgrading and downgrading
# Disable upgrading and downgrading.

require Math::BigInt;
my $upg = Math::BigInt -> upgrade();
my $dng = Math::BigInt -> downgrade();
Math::BigInt -> upgrade(undef);
Math::BigInt -> downgrade(undef);

# Copy the value.

my $y;
if ($x -> is_inf()) {
$y = Math::BigInt -> binf($x->sign());
Expand All @@ -1355,7 +1357,11 @@ sub as_int {
$y = Math::BigInt->new($x->{sign} . $LIB->_str($y));
}

# restore upgrading and downgrading
# Copy the remaining instance variables.

($y->{_a}, $y->{_p}) = ($x->{_a}, $x->{_p});

# Restore upgrading and downgrading.

Math::BigInt -> upgrade($upg);
Math::BigInt -> downgrade($dng);
Expand All @@ -1369,17 +1375,22 @@ sub as_float {

return $x -> copy() if $x -> isa("Math::BigFloat");

# disable upgrading and downgrading
# Disable upgrading and downgrading.

require Math::BigFloat;
my $upg = Math::BigFloat -> upgrade();
my $dng = Math::BigFloat -> downgrade();
Math::BigFloat -> upgrade(undef);
Math::BigFloat -> downgrade(undef);

my $y = Math::BigFloat -> copy($x);
# Copy the value.

my $y = Math::BigFloat -> new($x);

# Copy the remaining instance variables.

# restore upgrading and downgrading
($y->{_a}, $y->{_p}) = ($x->{_a}, $x->{_p});

# Restore upgrading and downgrading.

Math::BigFloat -> upgrade($upg);
Math::BigFloat -> downgrade($dng);
Expand All @@ -1394,14 +1405,16 @@ sub as_rat {

return $x -> copy() if $x -> isa("Math::BigRat");

# disable upgrading and downgrading
# Disable upgrading and downgrading.

require Math::BigRat;
my $upg = Math::BigRat -> upgrade();
my $dng = Math::BigRat -> downgrade();
Math::BigRat -> upgrade(undef);
Math::BigRat -> downgrade(undef);

# Copy the value.

my $y;
if ($x -> is_inf()) {
$y = Math::BigRat -> binf($x -> sign());
Expand All @@ -1414,7 +1427,11 @@ sub as_rat {
. '/' . $LIB -> _str($rat_parts[2]));
}

# restore upgrading and downgrading
# Copy the remaining instance variables.

($y->{_a}, $y->{_p}) = ($x->{_a}, $x->{_p});

# Restore upgrading and downgrading.

Math::BigRat -> upgrade($upg);
Math::BigRat -> downgrade($dng);
Expand Down
73 changes: 43 additions & 30 deletions cpan/Math-BigInt/lib/Math/BigInt.pm
Expand Up @@ -23,7 +23,7 @@ use warnings;
use Carp qw< carp croak >;
use Scalar::Util qw< blessed refaddr >;

our $VERSION = '2.001000';
our $VERSION = '2.001001';
$VERSION =~ tr/_//d;

require Exporter;
Expand Down Expand Up @@ -1333,21 +1333,24 @@ sub as_int {
my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_);
carp "Rounding is not supported for ", (caller(0))[3], "()" if @r;

# If called as an instance method, and the instance class is something we
# upgrade to, $x might not be a Math::BigInt, so don't just call copy().

return $x -> copy() if $x -> isa("Math::BigInt");

# disable upgrading and downgrading
# Disable upgrading and downgrading.

my $upg = Math::BigInt -> upgrade();
my $dng = Math::BigInt -> downgrade();
Math::BigInt -> upgrade(undef);
Math::BigInt -> downgrade(undef);

# Copy the value.

my $y = Math::BigInt -> new($x);

# reset upgrading and downgrading
# Copy the remaining instance variables.

($y->{_a}, $y->{_p}) = ($x->{_a}, $x->{_p});

# Restore upgrading and downgrading

Math::BigInt -> upgrade($upg);
Math::BigInt -> downgrade($dng);
Expand All @@ -1359,17 +1362,23 @@ sub as_float {
my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_);
carp "Rounding is not supported for ", (caller(0))[3], "()" if @r;

# disable upgrading and downgrading
# Disable upgrading and downgrading.

require Math::BigFloat;
my $upg = Math::BigFloat -> upgrade();
my $dng = Math::BigFloat -> downgrade();
Math::BigFloat -> upgrade(undef);
Math::BigFloat -> downgrade(undef);

# Copy the value.

my $y = Math::BigFloat -> new($x);

# reset upgrading and downgrading
# Copy the remaining instance variables.

($y->{_a}, $y->{_p}) = ($x->{_a}, $x->{_p});

# Restore upgrading and downgrading..

Math::BigFloat -> upgrade($upg);
Math::BigFloat -> downgrade($dng);
Expand All @@ -1381,7 +1390,7 @@ sub as_rat {
my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_);
carp "Rounding is not supported for ", (caller(0))[3], "()" if @r;

# disable upgrading and downgrading
# Disable upgrading and downgrading.

require Math::BigRat;
my $upg = Math::BigRat -> upgrade();
Expand All @@ -1391,7 +1400,11 @@ sub as_rat {

my $y = Math::BigRat -> new($x);

# reset upgrading and downgrading
# Copy the remaining instance variables.

($y->{_a}, $y->{_p}) = ($x->{_a}, $x->{_p});

# Restore upgrading and downgrading.

Math::BigRat -> upgrade($upg);
Math::BigRat -> downgrade($dng);
Expand Down Expand Up @@ -3244,9 +3257,7 @@ sub bsqrt {

return $x -> bnan(@r) if $x -> is_neg();

require Math::BigFloat;
my $tmp = Math::BigFloat -> bsqrt($x, @r) -> as_int();
$x->{value} = $tmp->{value};
$x->{value} = $LIB -> _sqrt($x->{value});
return $x -> round(@r);
}

Expand Down Expand Up @@ -5145,8 +5156,6 @@ sub objectify {
$count ||= @a;
unshift @a, $class;

no strict 'refs';

# What we upgrade to, if anything. Note that we need the whole upgrade
# chain, since there might be multiple levels of upgrading. E.g., class A
# upgrades to class B, which upgrades to class C. Delay getting the chain
Expand All @@ -5158,11 +5167,8 @@ sub objectify {
# Disable downgrading, because Math::BigFloat -> foo('1.0', '2.0') needs
# floats.

my $down;
if (defined ${"$a[0]::downgrade"}) {
$down = ${"$a[0]::downgrade"};
${"$a[0]::downgrade"} = undef;
}
my $dng = $class -> downgrade();
$class -> downgrade(undef);

ARG: for my $i (1 .. $count) {

Expand All @@ -5171,13 +5177,13 @@ sub objectify {
# Perl scalars are fed to the appropriate constructor.

unless ($ref) {
$a[$i] = $a[0] -> new($a[$i]);
$a[$i] = $class -> new($a[$i]);
next;
}

# If it is an object of the right class, all is fine.

next if $ref -> isa($a[0]);
next if $ref -> isa($class);

# Upgrading is OK, so skip further tests if the argument is upgraded,
# but first get the whole upgrade chain if we haven't got it yet.
Expand All @@ -5204,7 +5210,7 @@ sub objectify {

my $recheck = 0;

if ($a[0] -> isa('Math::BigInt')) {
if ($class -> isa('Math::BigInt')) {
if ($a[$i] -> can('as_int')) {
$a[$i] = $a[$i] -> as_int();
$recheck = 1;
Expand All @@ -5214,10 +5220,17 @@ sub objectify {
}
}

elsif ($a[0] -> isa('Math::BigFloat')) {
elsif ($class -> isa('Math::BigRat')) {
if ($a[$i] -> can('as_rat')) {
$a[$i] = $a[$i] -> as_rat();
$recheck = 1;
}
}

elsif ($class -> isa('Math::BigFloat')) {
if ($a[$i] -> can('as_float')) {
$a[$i] = $a[$i] -> as_float();
$recheck = $1;
$recheck = 1;
}
}

Expand All @@ -5229,23 +5242,23 @@ sub objectify {
# Perl scalars are fed to the appropriate constructor.

unless ($ref) {
$a[$i] = $a[0] -> new($a[$i]);
$a[$i] = $class -> new($a[$i]);
next;
}

# If it is an object of the right class, all is fine.

next if $ref -> isa($a[0]);
next if $ref -> isa($class);
}

# Last resort.

$a[$i] = $a[0] -> new($a[$i]);
$a[$i] = $class -> new($a[$i]);
}

# Reset the downgrading.
# Restore the downgrading.

${"$a[0]::downgrade"} = $down;
$class -> downgrade($dng);

return @a;
}
Expand Down
2 changes: 1 addition & 1 deletion cpan/Math-BigInt/lib/Math/BigInt/Calc.pm
Expand Up @@ -7,7 +7,7 @@ use warnings;
use Carp qw< carp croak >;
use Math::BigInt::Lib;

our $VERSION = '2.001000';
our $VERSION = '2.001001';
$VERSION =~ tr/_//d;

our @ISA = ('Math::BigInt::Lib');
Expand Down
2 changes: 1 addition & 1 deletion cpan/Math-BigInt/lib/Math/BigInt/Lib.pm
Expand Up @@ -4,7 +4,7 @@ use 5.006001;
use strict;
use warnings;

our $VERSION = '2.001000';
our $VERSION = '2.001001';
$VERSION =~ tr/_//d;

use Carp;
Expand Down

0 comments on commit 6da59fe

Please sign in to comment.