You can do ugly things to B even from within A
Yes - and my overloading of the arithmetic operations are done in XSubs - which leads to a fair bit of code clutter, but is procedurally clean and simple (IMO, at least).
I actually don't fully understand the code you've provided, but I'll certainly try to remedy that when I get the chance. (I'm not really a proper perl programmer.)
Having decided that Math::MPC's basic arithmetic operators should be capable of handling Math::MPFR objects (since the MPC library already provides functions that perform such arithmetic), it's a fairly simple exercise to insert the few required lines of code into the relevant Math::MPC XSubs.
If not for this "conundrum", that would be the end of the exercise.
Math::MPFR, which has no business to engage in arithmetic with Math::MPC objects, could be left as is - with no need to even mention this new capability in the Math::MPFR docs.
The solution I use is simple enough, but it involves making changes to the Math::MPFR overloading XSubs.
It's only a matter of inserting one line of code into a new
if(condition){} block in each of those XSubs. And it just does a callback to (eg)
Math::MPC::overload_minus(mpc_object, mpfr_object, &PL_sv_yes) with the assistance of a 20-line macro.
I'm happy enough with that, and I've used that technique without issue in a number of cross-class overloading situations - though I have no idea how expensive that solution is.
There's even no need to check whether Math::MPC has been loaded. If a Math::MPC object has been passed to a Math::MPFR function then we know that perl has loaded Math::MPC.
It's just a bit annoying that I have to go that extra step.
It would be much better if I could simply tell perl's overloading process "hey, in this case, use the overloading subroutine of the
second object". But ... I can't do that :-((
Cheers,
Rob
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.