in reply to Calculating Nth root using perl.
Other than the snarky RTFM (Perl has an intrinsic exponentiation operator)
$x = $y ** (1/4) if $y > 0;
if($y >= 0){ $x = $y ** (1/4); }else{ undef($x); die "Even roots of negative numbers require complex arithmetic\n"; }
While the 4th root of a negative number exists, I'm presuming you don't need to do complex arithmetic. If you do, you man want to check out Math::Complex, although it appears to be developmental.
emc
"Being forced to write comments actually improves code, because it is easier to fix a crock than to explain it. "
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Calculating Nth root using perl.
by salva (Canon) on May 09, 2006 at 18:31 UTC | |
by ikegami (Patriarch) on May 09, 2006 at 18:34 UTC |