in reply to Constructing complex numbers using recursion

This is quite straightforward trigonometry; there is absolutely no reason (except a homework assignment -- it isn't that, is it?) to use recursion. If you're trying to do this in an effort to do OO programming, it would make more sense (as someone mentioned before) to use Math::Trig or use Math::Complex or completely horrify the Perlmonks and use Fortran Smalltalk.

The conversion formulae should be in any math book (I used Protter, MH and Morrey, CB College Calculus with Analytical Geometry, 2/ed, Addison Wesley Publishing, Co, Reading, Massachusetts: 1970, pp405-413).

The Perl below will compile and give answers (they may even be the right answers) but I will not guarantee efficiency, elegance, or attractiveness.

sub p2r { (my $r, my $theta) = @_; return ($r * cos($theta), $r * sin($theta)); # (x,y) } sub r2p { (my $x, my $y) = @_; my $theta = atan2($y, $x); my $r = ($x **2 + $y **2) ** (0.5); return ($r, $theta); }

Of course, $theta is in radians.

emc