X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Fbigrat.pm;h=30acd275607ba930f17d5d0ab0caa2f259f09d7b;hb=2da7a6b5eab232c468b68576568f84877f032fd6;hp=a4de1d68f5f1575c97a812ebddbfd5ca26360dcf;hpb=075d4edd61a9648945541c8a76d8c03d4588400b;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/bigrat.pm b/lib/bigrat.pm index a4de1d6..30acd27 100644 --- a/lib/bigrat.pm +++ b/lib/bigrat.pm @@ -4,8 +4,8 @@ use 5.006002; $VERSION = '0.22'; require Exporter; @ISA = qw( bigint ); -@EXPORT_OK = qw( ); -@EXPORT = qw( inf NaN ); +@EXPORT_OK = qw( PI e bpi bexp ); +@EXPORT = qw( inf NaN ); use strict; use overload; @@ -158,7 +158,7 @@ sub import splice @a, $j, 1; $j --; $oct = \&bigint::_oct_global; } - else + elsif ($_[$i] !~ /^(PI|e|bpi|bexp)\z/) { die ("unknown option $_[$i]"); } @@ -226,6 +226,17 @@ sub import } } +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; __END__ @@ -329,6 +340,40 @@ handle bareword C properly. A shortcut to return Math::BigInt->bnan(). Useful because Perl does not always handle bareword C properly. +=item e + + # perl -Mbigrat=e -wle 'print e' + +Returns Euler's number C, aka exp(1). + +=item PI + + # perl -Mbigrat=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 -Mbigrat=bexp -wle 'print bexp(1,80)' + +=item bpi() + + bpi($accuracy); + +Returns PI to the wanted accuracy. + +Example: + + # perl -Mbigrat=bpi -wle 'print bpi(80)' + =item upgrade() Return the class that numbers are upgraded to, is in fact returning @@ -440,13 +485,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 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;".