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'; }