Change 31479 by [EMAIL PROTECTED] on 2007/06/27 12:57:52
Subject: Re: RFC: bigint et. al exporting PI method? [PATCH]
From: Tels <[EMAIL PROTECTED]>
Date: Tue, 26 Jun 2007 20:56:45 +0200
Message-Id: <[EMAIL PROTECTED]>
Affected files ...
... //depot/perl/MANIFEST#1596 edit
... //depot/perl/lib/bigint.pm#18 edit
... //depot/perl/lib/bignum.pm#19 edit
... //depot/perl/lib/bignum/t/big_e_pi.t#1 add
... //depot/perl/lib/bignum/t/bii_e_pi.t#1 add
... //depot/perl/lib/bignum/t/bir_e_pi.t#1 add
... //depot/perl/lib/bigrat.pm#16 edit
Differences ...
==== //depot/perl/MANIFEST#1596 (text) ====
Index: perl/MANIFEST
--- perl/MANIFEST#1595~31470~ 2007-06-26 02:10:24.000000000 -0700
+++ perl/MANIFEST 2007-06-27 05:57:52.000000000 -0700
@@ -1467,6 +1467,9 @@
lib/bignum/t/bigint.t See if bigint works
lib/bignum/t/bignum.t See if bignum works
lib/bignum/t/bigrat.t See if bigrat works
+lib/bignum/t/bii_e_pi.t See if bigint exports e() and PI()
+lib/bignum/t/bir_e_pi.t See if bigrat exports e() and PI()
+lib/bignum/t/big_e_pi.t See if bignum exports e() and PI()
lib/bignum/t/biinfnan.t See if bignum works
lib/bignum/t/bninfnan.t See if bignum works
lib/bignum/t/bn_lite.t See if bignum with Math::BigInt::Lite works
==== //depot/perl/lib/bigint.pm#18 (text) ====
Index: perl/lib/bigint.pm
--- perl/lib/bigint.pm#17~31450~ 2007-06-23 03:14:43.000000000 -0700
+++ perl/lib/bigint.pm 2007-06-27 05:57:52.000000000 -0700
@@ -4,7 +4,7 @@
$VERSION = '0.22';
use Exporter;
@ISA = qw( Exporter );
[EMAIL PROTECTED] = qw( );
[EMAIL PROTECTED] = qw( PI e );
@EXPORT = qw( inf NaN );
use strict;
@@ -215,7 +215,10 @@
splice @a, $j, 1; $j --;
$oct = \&_oct_global;
}
- else { die "unknown option $_[$i]"; }
+ elsif ($_[$i] !~ /^(PI|e)\z/)
+ {
+ die ("unknown option $_[$i]");
+ }
}
my $class;
$_lite = 0; # using M::BI::L ?
@@ -266,7 +269,7 @@
no strict 'refs';
if (!defined *{"${package}::inf"})
{
- $self->export_to_level(1,$self,@a); # export inf and NaN
+ $self->export_to_level(1,$self,@a); # export inf and NaN, e and
PI
}
{
no warnings 'redefine';
@@ -275,8 +278,10 @@
}
}
-sub inf () { Math::BigInt->binf(); }
-sub NaN () { Math::BigInt->bnan(); }
+sub inf () { Math::BigInt::binf(); }
+sub NaN () { Math::BigInt::bnan(); }
+sub PI { Math::BigInt->new(3); }
+sub e { Math::BigInt->new(2); }
1;
@@ -489,6 +494,14 @@
A shortcut to return Math::BigInt->bnan(). Useful because Perl does not always
handle bareword C<NaN> properly.
+=item e()
+
+Returns Euler's number C<e>, aka exp(1), to the given number of digits.
+
+=item PI()
+
+Returns PI to the given number of digits.
+
=item upgrade()
Return the class that numbers are upgraded to, is in fact returning
==== //depot/perl/lib/bignum.pm#19 (text) ====
Index: perl/lib/bignum.pm
--- perl/lib/bignum.pm#18~31450~ 2007-06-23 03:14:43.000000000 -0700
+++ perl/lib/bignum.pm 2007-06-27 05:57:52.000000000 -0700
@@ -4,7 +4,7 @@
$VERSION = '0.22';
use Exporter;
@ISA = qw( bigint );
[EMAIL PROTECTED] = qw( );
[EMAIL PROTECTED] = qw( PI e );
@EXPORT = qw( inf NaN );
use strict;
@@ -166,7 +166,10 @@
splice @a, $j, 1; $j --;
$oct = \&bigint::_oct_global;
}
- else { die "unknown option $_[$i]"; }
+ elsif ($_[$i] !~ /^(PI|e)\z/)
+ {
+ die ("unknown option $_[$i]");
+ }
}
my $class;
$_lite = 0; # using M::BI::L ?
@@ -237,6 +240,9 @@
}
}
+sub PI { Math::BigFloat::bpi(@_); }
+sub e { Math::BigFloat->bone->bexp(@_); }
+
1;
__END__
@@ -488,6 +494,14 @@
A shortcut to return Math::BigInt->bnan(). Useful because Perl does not always
handle bareword C<NaN> properly.
+=item e()
+
+Returns Euler's number C<e>, aka exp(1), to the given number of digits.
+
+=item PI()
+
+Returns PI to the given number of digits.
+
=item upgrade()
Return the class that numbers are upgraded to, is in fact returning
==== //depot/perl/lib/bignum/t/big_e_pi.t#1 (text) ====
Index: perl/lib/bignum/t/big_e_pi.t
--- /dev/null 2007-03-19 09:41:43.516454971 -0700
+++ perl/lib/bignum/t/big_e_pi.t 2007-06-27 05:57:52.000000000 -0700
@@ -0,0 +1,23 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+# test for e() and PI() exports
+
+use Test::More;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 4;
+ }
+
+use bignum qw/e PI/;
+
+is (e, "2.718281828459045235360287471352662497757", 'e');
+is (PI, "3.141592653589793238462643383279502884197", 'PI');
+
+is (e(10), "2.718281828", 'e');
+is (PI(10), "3.141592654", 'PI');
==== //depot/perl/lib/bignum/t/bii_e_pi.t#1 (text) ====
Index: perl/lib/bignum/t/bii_e_pi.t
--- /dev/null 2007-03-19 09:41:43.516454971 -0700
+++ perl/lib/bignum/t/bii_e_pi.t 2007-06-27 05:57:52.000000000 -0700
@@ -0,0 +1,23 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+# test for e() and PI() exports
+
+use Test::More;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 4;
+ }
+
+use bigint qw/e PI/;
+
+is (e, "2", 'e');
+is (PI, "3", 'PI');
+
+is (e(10), "2", 'e');
+is (PI(10), "3", 'PI');
==== //depot/perl/lib/bignum/t/bir_e_pi.t#1 (text) ====
Index: perl/lib/bignum/t/bir_e_pi.t
--- /dev/null 2007-03-19 09:41:43.516454971 -0700
+++ perl/lib/bignum/t/bir_e_pi.t 2007-06-27 05:57:52.000000000 -0700
@@ -0,0 +1,23 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+# test for e() and PI() exports
+
+use Test::More;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 4;
+ }
+
+use bigrat qw/e PI/;
+
+is (e, "2.718281828459045235360287471352662497757", 'e');
+is (PI, "3.141592653589793238462643383279502884197", 'PI');
+
+is (e(10), "2.718281828", 'e');
+is (PI(10), "3.141592654", 'PI');
==== //depot/perl/lib/bigrat.pm#16 (text) ====
Index: perl/lib/bigrat.pm
--- perl/lib/bigrat.pm#15~31450~ 2007-06-23 03:14:43.000000000 -0700
+++ perl/lib/bigrat.pm 2007-06-27 05:57:52.000000000 -0700
@@ -4,7 +4,7 @@
$VERSION = '0.22';
require Exporter;
@ISA = qw( bigint );
[EMAIL PROTECTED] = qw( );
[EMAIL PROTECTED] = qw( PI e );
@EXPORT = qw( inf NaN );
use strict;
@@ -158,7 +158,7 @@
splice @a, $j, 1; $j --;
$oct = \&bigint::_oct_global;
}
- else
+ elsif ($_[$i] !~ /^(PI|e)\z/)
{
die ("unknown option $_[$i]");
}
@@ -226,6 +226,9 @@
}
}
+sub PI { local $Math::BigFloat::upgrade = undef; Math::BigFloat::bpi(@_); }
+sub e { local $Math::BigFloat::upgrade = undef;
Math::BigFloat->bone()->bexp(@_); }
+
1;
__END__
@@ -329,6 +332,14 @@
A shortcut to return Math::BigInt->bnan(). Useful because Perl does not always
handle bareword C<NaN> properly.
+=item e()
+
+Returns Euler's number C<e>, aka exp(1), to the given number of digits.
+
+=item PI()
+
+Returns PI to the given number of digits.
+
=item upgrade()
Return the class that numbers are upgraded to, is in fact returning
End of Patch.