Math-BigInt
view release on metacpan or search on metacpan
lib/Math/BigFloat.pm view on Meta::CPAN
$pi = bless {
sign => '+',
_m => $LIB -> _new($digits),
_es => CORE::length($digits) > 1 ? '-' : '+',
_e => $LIB -> _new($n - 1),
}, $class;
} else {
# For large accuracy, the arctan formulas become very inefficient with
# Math::BigFloat, so use Brent-Salamin (aka AGM or Gauss-Legendre).
# Use a few more digits in the intermediate computations.
$n += 8;
$HALF = $class -> new($HALF) unless ref($HALF);
my ($an, $bn, $tn, $pn)
= ($class -> bone, $HALF -> copy() -> bsqrt($n),
$HALF -> copy() -> bmul($HALF), $class -> bone);
while ($pn < $n) {
lib/Math/BigFloat.pm view on Meta::CPAN
# We set Y here to multiples of 10 so that $x becomes below 1 - the smaller
# $x is the faster it gets. Since 2*$x takes about 10 times as long, we
# make it faster by about a factor of 100 by dividing $x by 10.
# The same observation is valid for numbers smaller than 0.1, e.g.
# computing log(1) is fastest, and the further away we get from 1, the
# longer it takes. So we also 'break' this down by multiplying $x with 10
# and subtract the log(10) afterwards to get the correct result.
# To get $x even closer to 1, we also divide by 2 and then use log(2) to
# correct for this. For instance if $x is 2.4, we use the formula:
# blog(2.4 * 2) == blog(1.2) + blog(2)
# and thus calculate only blog(1.2) and blog(2), which is faster in total
# than calculating blog(2.4).
# In addition, the values for blog(2) and blog(10) are cached.
# Calculate the number of digits before the dot, i.e., 1 + floor(log10(x)):
# x = 123 => dbd = 3
# x = 1.23 => dbd = 1
# x = 0.0123 => dbd = -1
( run in 1.742 second using v1.01-cache-2.11-cpan-26ccb49234f )