Pow
Raises a base to an exponent.
Module: Math
Signature
rux
func Pow(x: float64, y: float64) -> float64;
func Pow(x: float32, y: float32) -> float32;Parameters
| Name | Type | Description |
|---|---|---|
x | float64 / float32 | The base. |
y | float64 / float32 | The exponent. |
Returns
x raised to y, in the same precision as the arguments. Pow follows IEEE-754's special cases, of which the ones most likely to be surprising are:
Pow(x, 0.0)is1.0for everyx, a NaN included.Pow(1.0, y)is1.0for everyy, a NaN included.Pow(x, y)is a NaN whenxis negative andyis not an integer — there is no real result.- When
xis negative andyis an odd integer, the result is negative; whenyis an even integer, it is positive. Pow(x, 2.0)andPow(x, 0.5)(for non-negativex) are recognized and computed directly, asx * xandSqrt(x).
Example
rux
import Math::Pow;
let a = Pow(2.0, 10.0); // 1024.0
let b = Pow(9.0, 0.5); // 3.0
let c = Pow(-8.0, 1.0 / 3.0); // NaN -- exponent is not an integer