This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to Locale::Maketext 1.12
[perl5.git] / lib / bigint.pm
index 6eaa77e..1766e39 100644 (file)
@@ -4,8 +4,8 @@ use 5.006002;
 $VERSION = '0.22';
 use Exporter;
 @ISA           = qw( Exporter );
-@EXPORT_OK     = qw( PI e ); 
-@EXPORT                = qw( inf NaN ); 
+@EXPORT_OK     = qw( PI e bpi bexp );
+@EXPORT                = qw( inf NaN );
 
 use strict;
 use overload;
@@ -215,7 +215,7 @@ sub import
       splice @a, $j, 1; $j --;
       $oct = \&_oct_global;
       }
-    elsif ($_[$i] !~ /^(PI|e)\z/)
+    elsif ($_[$i] !~ /^(PI|e|bpi|bexp)\z/)
       {
       die ("unknown option $_[$i]");
       }
@@ -280,8 +280,11 @@ sub import
 
 sub inf () { Math::BigInt::binf(); }
 sub NaN () { Math::BigInt::bnan(); }
-sub PI { Math::BigInt->new(3); }
-sub e  { Math::BigInt->new(2); }
+
+sub PI () { Math::BigInt->new(3); }
+sub e () { Math::BigInt->new(2); }
+sub bpi ($) { Math::BigInt->new(3); }
+sub bexp ($$) { my $x = Math::BigInt->new($_[0]); $x->bexp($_[1]); }
 
 1;
 
@@ -393,13 +396,13 @@ Math::BigInt.
 
 =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;".
 
@@ -494,13 +497,43 @@ handle bareword C<inf> properly.
 A shortcut to return Math::BigInt->bnan(). Useful because Perl does not always
 handle bareword C<NaN> properly.
 
-=item e()
+=item e
+
+       # perl -Mbigint=e -wle 'print e'
+
+Returns Euler's number C<e>, aka exp(1). Note that under bigint, this is
+truncated to an integer, and hence simple '2'.
+
+=item PI
+
+       # perl -Mbigint=PI -wle 'print PI'
+
+Returns PI. Note that under bigint, this is truncated to an integer, and hence
+simple '3'.
+
+=item bexp()
+
+       bexp($power,$accuracy);
+
+Returns Euler's number C<e> raised to the appropriate power, to
+the wanted accuracy.
+
+Note that under bigint, the result is truncated to an integer.
+
+Example:
+
+       # perl -Mbigint=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. Note that under bigint, this is truncated
+to an integer, and hence simple '3'.
 
-=item PI()
+Example:
 
-Returns PI to the given number of digits.
+       # perl -Mbigint=bpi -wle 'print bpi(80)'
 
 =item upgrade()