Do you know where your variables are? | |
PerlMonks |
Re^6: How does Math::GMP overload the assignment operator ? (more guessing)by syphilis (Archbishop) |
on Nov 10, 2020 at 11:52 UTC ( [id://11123556]=note: print w/replies, xml ) | Need Help?? |
I expect (but am not certain) that the '0+' overload is also invoked if an XSUB attempts to convert an object to an IV or UV No, I'm quite certain that doesn't happen. (And if I'm wrong about that, then I'm also now quite certain that I'll be told about it ;-) It's just that the '0+' overloading calls an XSUB that converts the value in the object to a signed/unsigned long and returns that signed/unsigned long as an IV/UV. Of course, you can always call intify or uintify (though the Math::GMP docs recommend avoiding the latter) without invoking any overloading. Still not sure if calling int($obj) is the only way to activate the overload '0+' sub, but it's the only way that I could find. There's probably good lessons to be learned from working through this, but I think I'll give it a miss for now, mainly because I don't see much value in what this Math::GMP overloading of '0+' provides. Interesting stuff, but. UPDATE: I took a look at Math::BigInt, and found that the '0+' overloading allows stuff like: Can do the same with Math::GMPz ... not exactly sure how it works there (as there's no explicit '0+' overloading) : UPDATE 2: This capability of '0+' overloading definitely provides a useful feature. And then Haarg has also pointed out that it contributes to sprintf() and pack() functionality - which adds to its usefulness. Cheers, Rob
In Section
Seekers of Perl Wisdom
|
|