Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: bignum usage?

by Anonymous Monk
on Nov 24, 2023 at 09:22 UTC ( [id://11155786]=note: print w/replies, xml ) Need Help??


in reply to Re^2: bignum usage?
in thread bignum usage?

Thanks, looks like it's fallback (so called "div_scale", defaults to 40) value that was applied (and now I have a deja-vu to have already investigated this a few years back). Either of

use bignum p => 0; bignum-> precision( 0 ); bignum-> div_scale( 999 );

(or method calls on an instance) will help. That still doesn't feel right:

use strict; use warnings; use feature 'say'; use Data::Dump; use bignum; #use bigint; say my $x = 999999999921778071482940061661655974875633165533182; dd $x; dd $x-> precision; dd $x-> accuracy; dd $x-> div_scale; dd (Math::BigInt-> precision); dd (Math::BigInt-> accuracy); say my $y = $x / 1; __END__ 999999999921778071482940061661655974875633165533182 bless({ sign => "+", value => bless([165533182, 974875633, 61661655, 71482940, 999921778, + 999999], "Math::BigInt::Calc"), }, "Math::BigInt") undef undef 40 undef undef 999999999921778071482940061661655974875600000000000

But with bigint instead:

999999999921778071482940061661655974875633165533182 bless({ sign => "+", value => bless([165533182, 974875633, 61661655, 71482940, 999921778, + 999999], "Math::BigInt::Calc"), }, "Math::BigInt") undef undef 40 undef undef 999999999921778071482940061661655974875633165533182

i.e. object of the same class, with the same properties, same global parameters, but result is different. Same (per deja-vu) conclusion: avoid using bignum.

Replies are listed 'Best First'.
Re^4: bignum usage?
by syphilis (Archbishop) on Nov 24, 2023 at 10:29 UTC
    ... avoid using bignum.

    That's the rule that I live by.

    To be fair, however, bignum is quite possibly easier to use than I think.
    One just has to be aware of all the caveats ;-)

    UPDATE:
    i.e. object of the same class, with the same properties, same global parameters, but result is different.

    I think the difference occurs because the "bignum" division is done by Math::BigFloat::bdiv, whereas the "bigint" division is done by Math::BigInt::bdiv.

    Cheers,
    Rob

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11155786]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-06-23 10:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.