Skip to content

Instantly share code, notes, and snippets.

@grondilu
Created September 5, 2022 09:55
Show Gist options
  • Save grondilu/72daaea1a235a138597e745d29ce6fee to your computer and use it in GitHub Desktop.
Save grondilu/72daaea1a235a138597e745d29ce6fee to your computer and use it in GitHub Desktop.
hex root decimals in raku
sub integer_root ( Int $p where * >= 2, Int $n --> Int ) {
my Int $d = $p - 1;
my $guess = 10**($n.chars div $p);
my $iterator = { ( $d * $^x + $n div ($^x ** $d) ) div $p };
my $endpoint = { $^x ** $p <= $n
and ($^x + 1) ** $p > $n };
min (+$guess, $iterator ... $endpoint)[*-1, *-2];
}
say (($_ - .Int)*2**64).fmt("%0x") given integer_root( 2, 2 * 2**128 ).FatRat / 2**64;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment