summaryrefslogtreecommitdiff
path: root/lib/Math/BigInt.pm
diff options
context:
space:
mode:
authorTels <nospam-abuse@bloodgate.com>2007-06-08 21:29:41 +0200
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2007-06-11 15:18:27 +0000
commitfdb4b05f1f9ef1d9dc6361348b4be14d11ea44f4 (patch)
treedb0880b2e28b848bf2d35c1c8526575edacb8bea /lib/Math/BigInt.pm
parent2095dafae09cfface71d4202b3188926ea0ccc1c (diff)
downloadperl-fdb4b05f1f9ef1d9dc6361348b4be14d11ea44f4.tar.gz
pidigits benchmark and bpi() method in Math::BigFloat/Math::BigInt, take 7 [PATCH]
Message-Id: <200706081929.44888@bloodgate.com> p4raw-id: //depot/perl@31364
Diffstat (limited to 'lib/Math/BigInt.pm')
-rw-r--r--lib/Math/BigInt.pm64
1 files changed, 56 insertions, 8 deletions
diff --git a/lib/Math/BigInt.pm b/lib/Math/BigInt.pm
index f99eea617e..10aeb1b025 100644
--- a/lib/Math/BigInt.pm
+++ b/lib/Math/BigInt.pm
@@ -2831,6 +2831,27 @@ sub __lcm
}
###############################################################################
+# trigonometric functions
+
+sub bpi
+ {
+ # Calculate PI to N digits. Unless upgrading is in effect, returns the
+ # result truncated to an integer, that is, always returns '3'.
+ my ($self,$n) = @_;
+ if (@_ == 1)
+ {
+ # called like Math::BigInt::bpi(10);
+ $n = $self; $self = $class;
+ }
+ $self = ref($self) if ref($self);
+
+ return $upgrade->new($n) if defined $upgrade;
+
+ # hard-wired to "3"
+ $self->new(3);
+ }
+
+###############################################################################
# this method returns 0 if the object can be modified, or 1 if not.
# We use a fast constant sub() here, to avoid costly calls. Subclasses
# may override it with special code (f.i. Math::BigInt::Constant does so)
@@ -2865,14 +2886,17 @@ Math::BigInt - Arbitrary size integer/float math package
my $n = 1; my $sign = '-';
# Number creation
- $x = Math::BigInt->new($str); # defaults to 0
- $y = $x->copy(); # make a true copy
- $nan = Math::BigInt->bnan(); # create a NotANumber
- $zero = Math::BigInt->bzero(); # create a +0
- $inf = Math::BigInt->binf(); # create a +inf
- $inf = Math::BigInt->binf('-'); # create a -inf
- $one = Math::BigInt->bone(); # create a +1
- $one = Math::BigInt->bone('-'); # create a -1
+ my $x = Math::BigInt->new($str); # defaults to 0
+ my $y = $x->copy(); # make a true copy
+ my $nan = Math::BigInt->bnan(); # create a NotANumber
+ my $zero = Math::BigInt->bzero(); # create a +0
+ my $inf = Math::BigInt->binf(); # create a +inf
+ my $inf = Math::BigInt->binf('-'); # create a -inf
+ my $one = Math::BigInt->bone(); # create a +1
+ my $mone = Math::BigInt->bone('-'); # create a -1
+
+ my $pi = Math::BigInt->bpi(); # returns '3'
+ # see Math::BigFloat::bpi()
$h = Math::BigInt->new('0x123'); # from hexadecimal
$b = Math::BigInt->new('0b101'); # from binary
@@ -3497,6 +3521,23 @@ function. The result is equivalent to:
This method was added in v1.84 of Math::BigInt (April 2007).
+=head2 bpi()
+
+ print Math::BigInt->bpi(100), "\n"; # 3
+
+Returns PI truncated to an integer, with the argument being ignored. that
+is it always returns C<3>.
+
+If upgrading is in effect, returns PI to N digits (including the "3"
+before the dot):
+
+ use Math::BigFloat;
+ use Math::BigInt upgrade => Math::BigFloat;
+ print Math::BigInt->bpi(3), "\n"; # 3.14
+ print Math::BigInt->bpi(100), "\n"; # 3.1415....
+
+This method was added in v1.87 of Math::BigInt (June 2007).
+
=head2 blsft()
$x->blsft($y); # left shift in base 2
@@ -4385,6 +4426,13 @@ All other methods upgrade themselves only when one (or all) of their
arguments are of the class mentioned in $upgrade (This might change in later
versions to a more sophisticated scheme):
+=head1 EXPORTS
+
+C<Math::BigInt> exports nothing by default, but can export the following methods:
+
+ bgcd
+ blcm
+
=head1 BUGS
=over 2