package bigrat;
-use 5.006002;
+use 5.006;
-$VERSION = '0.22';
+$VERSION = '0.23';
require Exporter;
@ISA = qw( bigint );
-@EXPORT_OK = qw( PI e );
-@EXPORT = qw( inf NaN );
+@EXPORT_OK = qw( PI e bpi bexp );
+@EXPORT = qw( inf NaN );
use strict;
use overload;
splice @a, $j, 1; $j --;
$oct = \&bigint::_oct_global;
}
- elsif ($_[$i] !~ /^(PI|e)\z/)
+ elsif ($_[$i] !~ /^(PI|e|bpi|bexp)\z/)
{
die ("unknown option $_[$i]");
}
}
}
-sub PI { local $Math::BigFloat::upgrade = undef; Math::BigFloat::bpi(@_); }
-sub e { local $Math::BigFloat::upgrade = undef; Math::BigFloat->bone()->bexp(@_); }
+sub PI () { Math::BigFloat->new('3.141592653589793238462643383279502884197'); }
+sub e () { Math::BigFloat->new('2.718281828459045235360287471352662497757'); }
+
+sub bpi ($) { local $Math::BigFloat::upgrade; Math::BigFloat::bpi(@_); }
+
+sub bexp ($$)
+ {
+ local $Math::BigFloat::upgrade;
+ my $x = Math::BigFloat->new($_[0]); $x->bexp($_[1]);
+ }
1;
A shortcut to return Math::BigInt->bnan(). Useful because Perl does not always
handle bareword C<NaN> properly.
-=item e()
+=item e
+
+ # perl -Mbigrat=e -wle 'print e'
+
+Returns Euler's number C<e>, aka exp(1).
+
+=item PI
+
+ # perl -Mbigrat=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 -Mbigrat=bexp -wle 'print bexp(1,80)'
+
+=item bpi()
+
+ bpi($accuracy);
-Returns Euler's number C<e>, aka exp(1), to the given number of digits.
+Returns PI to the wanted accuracy.
-=item PI()
+Example:
-Returns PI to the given number of digits.
+ # perl -Mbigrat=bpi -wle 'print bpi(80)'
=item upgrade()
=item hex
-Override the build-in hex() method with a version that can handle big
+Override the built-in hex() method with a version that can handle big
integers. Note that under Perl v5.9.4 or ealier, this will be global
and cannot be disabled with "no bigint;".
=item oct
-Override the build-in oct() method with a version that can handle big
+Override the built-in oct() method with a version that can handle big
integers. Note that under Perl v5.9.4 or ealier, this will be global
and cannot be disabled with "no bigint;".