in reply to Re: root function
in thread root function
Yes it does. (-3)**(1/3) results in nan; But so does the log approach, too.
The odd roots of negative numbers must be treated separately as they are limit cases.
I'd try something like:
if ($base>0) { return $base**(1/$root); } elsif ($base==0) { return 0; ## or do manage the special case 0**0; } elsif ($root)==int($root) && $root%2==1) { return -((-$base)**($root)); } else { return 'nan'; }
Not tested, so probably broken :)
Careful with that hash Eugene.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: root function
by swampyankee (Parson) on Jun 21, 2008 at 21:40 UTC | |
by psini (Deacon) on Jun 21, 2008 at 21:47 UTC | |
by swampyankee (Parson) on Jun 21, 2008 at 23:39 UTC | |
by ysth (Canon) on Jun 22, 2008 at 06:53 UTC | |
by psini (Deacon) on Jun 22, 2008 at 07:14 UTC |