develooper Front page | perl.perl6.users | Postings from June 2022

Re: BigRoot precision question

Thread Previous
From:
Bruce Gray
Date:
June 11, 2022 12:59
Subject:
Re: BigRoot precision question
Message ID:
302E5A2D-7269-464D-9111-CBAADC24C671@acm.org


> On Jun 11, 2022, at 4:41 AM, ToddAndMargo via perl6-users <perl6-users@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]


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About