in reply to Constructing complex numbers using recursion

It would be a lot better for all concerned if you could post a version of the code that actually compiles and runs (even if it runs in an endless loop). The code you posted has no usable sample data, plus a syntax error in the "PolarToRect" sub (you're missing a period between " _ " and $angle) -- and maybe it wouldn't be to awful to actually include the full code for that sub.

Based on what you've shown, it looks like the value being passed to the "recursed" constructComplex (i.e. the return value from PolarToRect) might be incorrect in some way -- but there's really no way to be sure, because the OP has left out some important parts.

(Like: when "$magnitude = blah", does this mean that it gets the part of a string that precedes " _ "? and similarly for "$angle = blah"?)

update: for that matter, I'm having trouble understanding why "constructComplex" is calling itself at all here... if the coordinates are "inPolarForm", why do you need to convert to rectangular and then back to polar?

  • Comment on Re: Constructing complex numbers using recursion

Replies are listed 'Best First'.
Re^2: Constructing complex numbers using recursion
by moltar512 (Sexton) on Nov 08, 2005 at 04:51 UTC
    the purpose of constructComplex ultimately is to take the strings that i give it (either in "3 _ 4" form or "3 + 4i" form) and pick out the numbers from the rest of the string.


    what i'm trying to do is if constructComplex detects that value1 is of type polar (if i get this fix i'd like to expand this to all other cases), i want it to get the rectangular form from PolarToRect and then use constructComplex (the recursion) to pick out the real/complex numbers and package all of that nicely in the @construct that constructComplex returns at the end