-
-
Save zoffixznet/2539e8bebe9c5e19ab38ca43e173fe8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# use Benchy; | |
use nqp; | |
use MONKEY-TYPING; | |
augment class Int { | |
method log10_new { | |
nqp::if( | |
nqp::islt_I(self, 10**300), | |
nqp::div_n(nqp::log_n( | |
nqp::tonum_I(nqp::decont(self))), nqp::log_n(10e0)), | |
nqp::stmts( | |
(my num $ans = 0e0), | |
(my $leftovers := self), | |
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, | |
# { $v.log10 }, | |
# { $v.log10_new }; | |
say .log10_new 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