X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Fbignum.pm;h=2e075c8b5a72741a5eb7deb1e2ed8c6d73f4a813;hb=55ec0dff636c2a8ee5225314d7d46f928ab7f6da;hp=e9ab3bcce9483c3df0cba930e5f864d2b3b37cc9;hpb=c8ab6ea16e62f8a4c2caf5d6b6f57d1f5fb3b685;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/bignum.pm b/lib/bignum.pm index e9ab3bc..2e075c8 100644 --- a/lib/bignum.pm +++ b/lib/bignum.pm @@ -1,10 +1,10 @@ package bignum; -use 5.006002; +use 5.006; -$VERSION = '0.22'; +$VERSION = '0.23'; use Exporter; @ISA = qw( bigint ); -@EXPORT_OK = qw( PI e ); +@EXPORT_OK = qw( PI e bexp bpi ); @EXPORT = qw( inf NaN ); use strict; @@ -166,7 +166,7 @@ sub import splice @a, $j, 1; $j --; $oct = \&bigint::_oct_global; } - elsif ($_[$i] !~ /^(PI|e)\z/) + elsif ($_[$i] !~ /^(PI|e|bexp|bpi)\z/) { die ("unknown option $_[$i]"); } @@ -240,8 +240,10 @@ sub import } } -sub PI () { Math::BigFloat::bpi(@_); } -sub e () { Math::BigFloat->bone->bexp(@_); } +sub PI () { Math::BigFloat->new('3.141592653589793238462643383279502884197'); } +sub e () { Math::BigFloat->new('2.718281828459045235360287471352662497757'); } +sub bpi ($) { Math::BigFloat::bpi(@_); } +sub bexp ($$) { my $x = Math::BigFloat->new($_[0]); $x->bexp($_[1]); } 1; @@ -417,13 +419,13 @@ This will be hopefully fixed soon ;) =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 older than v5.9.4, 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 older than v5.9.4, this will be global and cannot be disabled with "no bigint;". @@ -494,13 +496,38 @@ handle bareword C properly. A shortcut to return Math::BigInt->bnan(). Useful because Perl does not always handle bareword C properly. -=item e() +=item e -Returns Euler's number C, aka exp(1), to the given number of digits. + # perl -Mbignum=e -wle 'print e' + +Returns Euler's number C, aka exp(1). =item PI() -Returns PI to the given number of digits. + # perl -Mbignum=PI -wle 'print PI' + +Returns PI. + +=item bexp() + + bexp($power,$accuracy); + +Returns Euler's number C raised to the appropriate power, to +the wanted accuracy. + +Example: + + # perl -Mbignum=bexp -wle 'print bexp(1,80)' + +=item bpi() + + bpi($accuracy); + +Returns PI to the wanted accuracy. + +Example: + + # perl -Mbignum=bpi -wle 'print bpi(80)' =item upgrade()