Haskell (**)
(), ( ) . , , C pow
:
printf("%f\n", pow(-1.0, 1.0/3.0)); // prints "-nan", for me
Python **
:
print((-1.0)**(1.0/3.0))
. " " . . , SO.
, , , , @Istvan signum
sign
, :
cbrt x = signum x * abs x ** (1/3)
, , n
n- , , , :
-- | Calculate nth root of b
root :: (Integral n, RealFloat b) => n -> b -> b
root n b | odd n && b < 0 = - abs b ** overn
| otherwise = b ** overn
where overn = 1 / fromIntegral n
:
> root 3 (-8)
-2.0
> root 4 (-8)
NaN -- correct, as no real root exists
>