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.
In reply to Re^2: root function
by psini
in thread root function
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |