1N/A############################################################################## 1N/A# These are all alike, and thus faked by AUTOLOAD 1N/A *{
"bigrat::$name"} =
sub 1N/A # delayed load of Carp and avoid recursion 1N/A Carp::
croak (
"Can't call bigrat\-\>$name, not a valid method");
1N/A# $Math::BigInt::upgrade = $_[0]; 1N/A# $Math::BigFloat::upgrade = $_[0]; 1N/A # see also bignum->import() for additional comments 1N/A my @
import = (
':constant' );
# drive it w/ constant 1N/A my @a = @_;
my $l =
scalar @_;
my $j =
0;
1N/A for (
my $i =
0; $i < $l ; $i++,$j++ )
1N/A if ($_[$i]
eq 'upgrade')
1N/A # this causes upgrading 1N/A my $s =
2; $s =
1 if @a-$j <
2;
# avoid "can not modify non-existant..." 1N/A splice @a, $j, $s; $j -= $s;
1N/A elsif ($_[$i] =~ /^(l|
lib)$/)
1N/A # this causes a different low lib to take care... 1N/A my $s =
2; $s =
1 if @a-$j <
2;
# avoid "can not modify non-existant..." 1N/A splice @a, $j, $s; $j -= $s;
1N/A splice @a, $j,
1; $j --;
1N/A splice @a, $j,
1; $j --;
1N/A die (
"unknown option $_[$i]");
1N/A # see if we can find Math::BigInt::Lite 1N/A if (!
defined $a && !
defined $p)
# rounding won't work to well 1N/A eval 'require Math::BigInt::Lite;';
1N/A $
class =
'Math::BigInt';
# regardless of MBIL or not 1N/A # Math::BigInt::Trace or plain Math::BigInt 1N/A print "bigrat\t\t\t v$VERSION\n";
1N/A print "Math::BigInt::Lite\t v$Math::BigInt::Lite::VERSION\n" if $
_lite;
1N/A print "Math::BigInt\t\t v$Math::BigInt::VERSION";
1N/A print " lib => $config->{lib} v$config->{lib_version}\n";
1N/A print "Math::BigFloat\t\t v$Math::BigFloat::VERSION\n";
1N/A print "Math::BigRat\t\t v$Math::BigRat::VERSION\n";
1N/A $x = 2 + 4.5,"\n"; # BigFloat 6.5 1N/A print 1/3 + 1/4,"\n"; # produces 7/12 1N/AAll operators (inlcuding basic math operations) are overloaded. Integer and 1N/Afloating-point constants are created as proper BigInts or BigFloats, 1N/AOther than L<bignum>, this module upgrades to Math::BigRat, meaning that 1N/Ainstead of 2.5 you will get 2+1/2 as output. 1N/AC<bigrat> is just a thin wrapper around various modules of the Math::BigInt 1N/Afamily. Think of it as the head of the family, who runs the shop, and orders 1N/Athe others to do the work. 1N/AThe following modules are currently used by bignum: 1N/A Math::BigInt::Lite (for speed, and only if it is loadable) 1N/AMath with the numbers is done (by default) by a module called 1N/AMath::BigInt::Calc. This is equivalent to saying: 1N/A use bigrat lib => 'Calc'; 1N/AYou can change this by using: 1N/A use bigrat lib => 'BitVect'; 1N/AThe following would first try to find Math::BigInt::Foo, then 1N/AMath::BigInt::Bar, and when this also fails, revert to Math::BigInt::Calc: 1N/A use bigrat lib => 'Foo,Math::BigInt::Bar'; 1N/APlease see respective module documentation for further details. 1N/AThe sign is either '+', '-', 'NaN', '+inf' or '-inf' and stored seperately. 1N/AA sign of 'NaN' is used to represent the result when input arguments are not 1N/Anumbers or as a result of 0/0. '+inf' and '-inf' represent plus respectively 1N/Aminus infinity. You will get '+inf' when dividing a positive number by 0, and 1N/A'-inf' when dividing any negative number by 0. 1N/ASince all numbers are not objects, you can use all functions that are part of 1N/Athe BigInt or BigFloat API. It is wise to use only the bxxx() notation, and not 1N/Athe fxxx() notation, though. This makes you independed on the fact that the 1N/Aunderlying object might morph into a different class than BigFloat. 1N/ABut a warning is in order. When using the following to make a copy of a number, 1N/Aonly a shallow copy will be made. 1N/AUsing the copy or the original with overloaded math is okay, e.g. the 1N/A print $x + 1, " ", $y,"\n"; # prints 10 9 1N/Abut calling any method that modifies the number directly will result in 1N/AB<both> the original and the copy beeing destroyed: 1N/A print $x->badd(1), " ", $y,"\n"; # prints 10 10 1N/A print $x->binc(1), " ", $y,"\n"; # prints 10 10 1N/A print $x->bmul(2), " ", $y,"\n"; # prints 18 18 1N/AUsing methods that do not modify, but testthe contents works: 1N/A $z = 9 if $x->is_zero(); # works fine 1N/ASee the documentation about the copy constructor and C<=> in overload, as 1N/Awell as the documentation in BigInt for further details. 1N/A perl -Mbigrat -le 'print sqrt(33)' 1N/A perl -Mbigrat -le 'print 2*255' 1N/A perl -Mbigrat -le 'print 4.5+2*255' 1N/A perl -Mbigrat -le 'print 3/7 + 5/7 + 8/3' 1N/A perl -Mbigrat -le 'print 12->is_odd()'; 1N/AThis program is free software; you may redistribute it and/or modify it under 1N/Athe same terms as Perl itself. 1N/AEspecially L<bignum>. 1N/AL<Math::BigFloat>, L<Math::BigInt>, L<Math::BigRat> and L<Math::Big> as well 1N/Aas L<Math::BigInt::BitVect>, L<Math::BigInt::Pari> and L<Math::BigInt::GMP>.