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
$VERSION = '0.22';
use Exporter;
@ISA = qw( Exporter );
-@EXPORT_OK = qw( );
+@EXPORT_OK = qw( PI e );
@EXPORT = qw( inf NaN );
use strict;
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 ?
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';
}
}
-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;
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
$VERSION = '0.22';
use Exporter;
@ISA = qw( bigint );
-@EXPORT_OK = qw( );
+@EXPORT_OK = qw( PI e );
@EXPORT = qw( inf NaN );
use strict;
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 ?
}
}
+sub PI { Math::BigFloat::bpi(@_); }
+sub e { Math::BigFloat->bone->bexp(@_); }
+
1;
__END__
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
--- /dev/null
+#!/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');
--- /dev/null
+#!/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');
--- /dev/null
+#!/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');
$VERSION = '0.22';
require Exporter;
@ISA = qw( bigint );
-@EXPORT_OK = qw( );
+@EXPORT_OK = qw( PI e );
@EXPORT = qw( inf NaN );
use strict;
splice @a, $j, 1; $j --;
$oct = \&bigint::_oct_global;
}
- else
+ elsif ($_[$i] !~ /^(PI|e)\z/)
{
die ("unknown option $_[$i]");
}
}
}
+sub PI { local $Math::BigFloat::upgrade = undef; Math::BigFloat::bpi(@_); }
+sub e { local $Math::BigFloat::upgrade = undef; Math::BigFloat->bone()->bexp(@_); }
+
1;
__END__
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