> On Jun 11, 2022, at 4:41 AM, ToddAndMargo via perl6-users 
> <perl6-us...@perl.org> wrote:
> 
> Hi All,
> 
> In the following paper on Big Root:
> 
> https://newbedev.com/how-can-i-set-the-level-of-precision-for-raku-s-sqrt
> 
> 
> > use BigRoot;
> > BigRoot.precision = 7;
> > say (BigRoot.newton's-sqrt: 2;).base(10)
> 1.4142136
> > say (BigRoot.newton's-sqrt: 2;).base(16)
> 1.6A09E7
> 
> That is a base(10) precision.  In base(16) (Hex)
> that is only 3 digits past the decimal.
>    0x6A-0x09-0xE7
> 
> Is there a way to tell BigRoot I want a certain
> amount of Hex digits I want after the decimal?

No, https://github.com/juliodcs/BigRoot/blob/master/lib/BigRoot.rakumod shows 
that BigRoot only allows setting precision as decimal.

> Or just ask for double I want and prune afterwards?

Doubling your desired precision is overkill; you only need a 21% increase. 
Since:
    decimal_precision =~= ( hexadecimal_precision_wanted * log(16) / log(10) );
, this should work:
    BigRoot.precision = ( $hexadecimal_precision_wanted * log10(16) ).ceiling;

As evidence:
    my $hexadecimal_precision_wanted = 2 ** 13;
    my $decimal_precision_via_log    = ( $hexadecimal_precision_wanted * 
log10(16) ).ceiling;
    my $largest_hex_number_that_size = 'F' x $hexadecimal_precision_wanted;
    my $decimal_precision_via_chars  = 
$largest_hex_number_that_size.parse-base(16).chars;
    .say for ( :$hexadecimal_precision_wanted, :$decimal_precision_via_log, 
:$decimal_precision_via_chars );
Output:
    hexadecimal_precision_wanted => 8192
    decimal_precision_via_log => 9865
    decimal_precision_via_chars => 9865

-- 
Hope this helps,
Bruce Gray (Util of PerlMonks) [who just learned of the BigRoot module]

Reply via email to