my $class = "Math::BigInt";
require 5.005;
-$VERSION = '1.40';
+$VERSION = '1.41';
use Exporter;
@ISA = qw( Exporter );
@EXPORT_OK = qw( bneg babs bcmp badd bmul bdiv bmod bnorm bsub
length as_number
objectify _swap
);
-
#@EXPORT = qw( );
use vars qw/$rnd_mode $accuracy $precision $div_scale/;
use strict;
my $x = shift;
die ("precision() needs reference to object as first parameter.")
- unless ref $x;
+ if !ref $x;
if (@_ > 0)
{
my $c = ref($args[0]); # find out class of argument
unshift @args,$self; # add 'first' argument
+ # leave bigfloat parts alone
+ return $self if exists $self->{_f} && $self->{_f} & MB_NEVER_ROUND != 0;
+
no strict 'refs';
my $z = "$c\::accuracy"; my $aa = $$z; my $ap = undef;
if (!defined $aa)
$z = "$c\::precision"; $ap = $$z;
}
- # leave bigfloat parts alone
- return $self if exists $self->{_f} && $self->{_f} & MB_NEVER_ROUND != 0;
-
# now pick $a or $p, but only if we have got "arguments"
if ((!defined $a) && (!defined $p) && (@args > 0))
{
return $self->bnorm();
}
-sub bnorm
+sub bnorm
{
# (num_str or BINT) return BINT
# Normalize number -- no-op here
my $x = shift; $x = $class->new($x) unless ref $x;
return 0 if $x->{sign} !~ /^\+$/; # -, NaN & +-inf aren't
- return $CALC->_is_zero($x->{value});
+ $CALC->_is_zero($x->{value});
+ #return $CALC->_is_zero($x->{value});
}
sub is_nan
my $c = ref ($_[0]) || $class; # fallback $class should not happen
return ( $c->new($_[1]), $_[0] );
}
- else
- {
- return ( $_[0]->copy(), $_[1] );
- }
+ return ( $_[0]->copy(), $_[1] );
}
sub objectify
# it or override with their own integer conversion routine
my $self = shift;
- return $self->copy();
+ $self->copy();
}
##############################################################################
if ($sx eq '+')
{
return 1 if $sy eq '-'; # 0 check handled above
- #return acmp($cx,$cy);
return $CALC->_acmp($cx,$cy);
}
else
{
# $sx eq '-'
return -1 if $sy eq '+';
- #return acmp($cy,$cx);
return $CALC->_acmp($cy,$cx);
}
- return 0; # equal
+ 0; # equal
}
sub _lcm
It will not do what you think, e.g. making a copy of $x. Instead it just makes
a second reference to the B<same> object and stores it in $y. Thus anything
-that modifies $x will modify $y, and vice versa.
+that modifies $x (except overloaded operators) will modify $y, and vice versa.
+Or in other words, C<=> is only safe if you modify your BigInts only via
+overloaded math. As soon as you use a method call it breaks:
$x->bmul(2);
print "$x, $y\n"; # prints '10, 10'
$y = $x->copy();
+You can also chain the calls like this, this will make first a copy and then
+multiply it by 2:
+
+ $y = $x->copy()->bmul(2);
+
See also the documentation for overload.pm regarding C<=>.
=item bpow
ok (ref($x),'Math::Foo');
###############################################################################
-# test whether +inf eq inf
-
-$y = 1e1000000; # create inf, since bareword inf does not work
-$x = Math::BigInt->new('+inf'); ok_inf ($x,$y);
+# Test whether +inf eq inf
+# This tried to test whether BigInt inf equals Perl inf. Unfortunately, Perl
+# hasn't (before 5.7.3 at least) a consistent way to say inf, and some things
+# like 1e100000 crash on some platforms. So simple test for 'inf'
+$x = Math::BigInt->new('+inf'); ok ($x,'inf');
###############################################################################
# all tests done
###############################################################################
-
-# libc are confused what to call Infinity
-
-sub fix_inf {
- $_[0] =~ s/^(inf(?:inity)?|\+\+)$/Inf/i; # HP-UX calls it "++"
-}
-
-sub ok_inf {
- my ($x, $y) = @_;
-
- fix_inf($x);
- fix_inf($y);
-
- ok($x, $y);
-}
-
# Perl 5.005 does not like ok ($x,undef)
sub ok_undef