Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How does Math::GMP overload the assignment operator ? (more guessing)

by LanX (Saint)
on Nov 07, 2020 at 09:44 UTC ( [id://11123469]=note: print w/replies, xml ) Need Help??


in reply to How does Math::GMP overload the assignment operator ?

Just a guess: did you check fallback ?

See overload#Copy-Constructor

UPDATE

Another guess: I look into the sources (Perl side only) and saw that Math::GMP overloads numification where Math::GMPz doesn't.

"0+"  =>   sub { $_[0] >= 0 ? uintify($_[0]) : intify($_[0]) },

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: How does Math::GMP overload the assignment operator ? (more guessing)
by syphilis (Archbishop) on Nov 08, 2020 at 08:48 UTC
    "0+" => sub { $_[0] >= 0 ? uintify($_[0]) : intify($_[0]) },

    I don't think it's related to my particular problem, but it's an interesting case.
    Which operator is being overloaded here ? Is it overloading 'int' ?
    I actually wonder if that's a useful feature, but I won't rush to an assessment on that until I've found out a bit more about it.

    Cheers,
    Rob

      That is overloading numeric conversion.

      That sub will be called whenever an object is used in a context that expects a number.

        That sub will be called whenever an object is used in a context that expects a number.

        The only way I can find of having that sub called is by doing int($obj).
        Do you have an example of another way ?

        On Windows (where sizeof(long) is 4):
        C:\>perl -MMath::GMP -le "print int(Math::GMP->new(311) ** 100);" 385227681
        Math::GMPz achieves the same result with:
        C:\>perl -MMath::GMPz=":mpz" -le "print Rmpz_get_ui(Math::GMPz->new(31 +1) ** 100);" 385227681 alternatively: C:\>perl -MMath::GMPz -le "$x = (Math::GMPz->new(311) ** 100) & 429496 +7295; print $x;" 385227681
        though, in this very last example, $x is a Math::GMPz object, not an IV.

        Cheers,
        Rob

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-04-25 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found