Skip to content

Instantly share code, notes, and snippets.

@zoffixznet

zoffixznet/p6.p6 Secret

Last active September 4, 2017 14:34
Show Gist options
  • Save zoffixznet/ba9a8730d4c1a1119b49d3765f249fae to your computer and use it in GitHub Desktop.
Save zoffixznet/ba9a8730d4c1a1119b49d3765f249fae to your computer and use it in GitHub Desktop.
# use Benchy;
use nqp;
multi huge_log_10 (Int $n) {
nqp::if(
nqp::islt_I($n, 10**300),
nqp::div_n(nqp::log_n(nqp::tonum_I(nqp::decont($n))), nqp::log_n(10e0)),
nqp::stmts(
(my num $ans = 0e0),
(my $leftovers := nqp::decont($n)),
nqp::while(
nqp::isgt_I($leftovers, 10**300),
($ans = nqp::add_n($ans,
nqp::div_n(nqp::log_n(1e300), nqp::log_n(10e0)))),
$leftovers := nqp::div_I($leftovers, 10**300, Int)),
nqp::add_n($ans,
nqp::div_n(nqp::log_n(nqp::tonum_I($leftovers)), nqp::log_n(10e0)) )))
}
# my $v = 10**200;
# b 1000_000,
# { log10 $v },
# { huge_log_10 $v };
say huge_log_10 $_ for 10, 10**100, 10**99, 10**1000, 10**10000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment