Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Overloading multiplication involving BigInt

by pileofrogs (Priest)
on Jan 13, 2012 at 21:43 UTC ( [id://947837]=note: print w/replies, xml ) Need Help??


in reply to Overloading multiplication involving BigInt

No one else is commenting, so I'll take a wild stab.

Why not add more elsif branches to your sub? You say you're worried about bmul behaving badly if it's handed something other than a BigInt, so why not just check for it?

You could also run some tests or read the source to find out what bmul really does if the 2nd operand isn't a BigInt.

Why would you have to explicitly bless your integers if you made a subclass of Math::BigInt?

And to step back a little: are you sure you want to do overloading? Will future users (or yourself) be flummoxed that $a*$b isn't doing what they expect? Is typing '$obj->mult($other_thing)' really that bad? At least that way you know exactly what you just did.

Okay, that's about all I can think of. I hope I was helpful.

--Pileofrogs

  • Comment on Re: Overloading multiplication involving BigInt

Replies are listed 'Best First'.
Re^2: Overloading multiplication involving BigInt
by grondilu (Friar) on Jan 14, 2012 at 15:17 UTC

    Well, I had a look at Math::BigInt source code and it seemed to me that the '*' overloading had already a lot of elsif branches. I just don't want to reinvent the wheel and redo what has already been done. Basically I whish I could just say "if the second operand is a My::Custom::Object then do this, otherwise just do whatever '*' does in the Math::BigInt class".

    About explicit blessing, I just don't see how I could do it otherwise, unless I use a constructor anyway. But now that you make me think of it , I wonder if the magic of bigint wouldn't be inherited. I have to check this out, indeed.

    You are right about using overloading not being necessary. But it would definitely be cool.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found