$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;
splice @a, $j, 1; $j --;
$oct = \&_oct_global;
}
- elsif ($_[$i] !~ /^(PI|e)\z/)
+ elsif ($_[$i] !~ /^(PI|e|bpi|bexp)\z/)
{
die ("unknown option $_[$i]");
}
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;
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()
$VERSION = '0.22';
use Exporter;
@ISA = qw( bigint );
-@EXPORT_OK = qw( PI e );
+@EXPORT_OK = qw( PI e bexp bpi );
@EXPORT = qw( inf NaN );
use strict;
splice @a, $j, 1; $j --;
$oct = \&bigint::_oct_global;
}
- elsif ($_[$i] !~ /^(PI|e)\z/)
+ elsif ($_[$i] !~ /^(PI|e|bexp|bpi)\z/)
{
die ("unknown option $_[$i]");
}
}
}
-sub PI { Math::BigFloat::bpi(@_); }
-sub e { Math::BigFloat->bone->bexp(@_); }
+sub PI () { Math::BigFloat->new('3.141592653589793238462643383279502884197'); }
+sub e () { Math::BigFloat->new('2.718281828459045235360287471352662497757'); }
+sub bpi ($) { Math::BigFloat::bpi(@_); }
+sub bexp ($$) { my $x = Math::BigFloat->new($_[0]); $x->bexp($_[1]); }
1;
A shortcut to return Math::BigInt->bnan(). Useful because Perl does not always
handle bareword C<NaN> properly.
-=item e()
+=item e
-Returns Euler's number C<e>, aka exp(1), to the given number of digits.
+ # perl -Mbignum=e -wle 'print e'
+
+Returns Euler's number C<e>, aka exp(1).
=item PI()
-Returns PI to the given number of digits.
+ # perl -Mbignum=PI -wle 'print PI'
+
+Returns PI.
+
+=item bexp()
+
+ bexp($power,$accuracy);
+
+Returns Euler's number C<e> raised to the appropriate power, to
+the wanted accuracy.
+
+Example:
+
+ # perl -Mbignum=bexp -wle 'print bexp(1,80)'
+
+=item bpi()
+
+ bpi($accuracy);
+
+Returns PI to the wanted accuracy.
+
+Example:
+
+ # perl -Mbignum=bpi -wle 'print bpi(80)'
=item upgrade()
plan tests => 4;
}
-use bignum qw/e PI/;
+use bignum qw/e PI bexp bpi/;
is (e, "2.718281828459045235360287471352662497757", 'e');
is (PI, "3.141592653589793238462643383279502884197", 'PI');
-is (e(10), "2.718281828", 'e');
-is (PI(10), "3.141592654", 'PI');
+is (bexp(1,10), "2.718281828", 'e');
+is (bpi(10), "3.141592654", 'PI');
$| = 1;
chdir 't' if -d 't';
unshift @INC, '../lib';
- plan tests => 4;
+ plan tests => 5;
}
-use bigint qw/e PI/;
+use bigint qw/e PI bpi bexp/;
is (e, "2", 'e');
is (PI, "3", 'PI');
-is (e(10), "2", 'e');
-is (PI(10), "3", 'PI');
+is (bexp(1,10), "2", 'e');
+is (bexp(3,10), "20", 'e');
+is (bpi(10), "3", 'PI');
plan tests => 4;
}
-use bigrat qw/e PI/;
+use bigrat qw/e PI bexp bpi/;
is (e, "2.718281828459045235360287471352662497757", 'e');
is (PI, "3.141592653589793238462643383279502884197", 'PI');
-is (e(10), "2.718281828", 'e');
-is (PI(10), "3.141592654", 'PI');
+# these tests should actually produce big rationals, but this is not yet
+# implemented:
+is (bexp(1,10), "2.718281828", 'e');
+is (bpi(10), "3.141592654", 'PI');
$VERSION = '0.22';
require Exporter;
@ISA = qw( bigint );
-@EXPORT_OK = qw( PI e );
-@EXPORT = qw( inf NaN );
+@EXPORT_OK = qw( PI e bpi bexp );
+@EXPORT = qw( inf NaN );
use strict;
use overload;
splice @a, $j, 1; $j --;
$oct = \&bigint::_oct_global;
}
- elsif ($_[$i] !~ /^(PI|e)\z/)
+ elsif ($_[$i] !~ /^(PI|e|bpi|bexp)\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(@_); }
+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;
A shortcut to return Math::BigInt->bnan(). Useful because Perl does not always
handle bareword C<NaN> properly.
-=item e()
+=item e
+
+ # perl -Mbigrat=e -wle 'print e'
+
+Returns Euler's number C<e>, aka exp(1).
+
+=item PI
+
+ # perl -Mbigrat=PI -wle 'print PI'
+
+Returns PI.
+
+=item bexp()
+
+ bexp($power,$accuracy);
+
+
+Returns Euler's number C<e> raised to the appropriate power, to
+the wanted accuracy.
+
+Example:
+
+ # perl -Mbigrat=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.
-=item PI()
+Example:
-Returns PI to the given number of digits.
+ # perl -Mbigrat=bpi -wle 'print bpi(80)'
=item upgrade()