Pow v0.1.0

Source
Raises a base to an exponent.

Package: Math

Signature

func Pow(x: float64, y: float64) -> float64;
func Pow(x: float32, y: float32) -> float32;

Parameters

NameTypeDescription
xfloat64 / float32The base.
yfloat64 / float32The 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) is 1.0 for every x, a NaN included.
  • Pow(1.0, y) is 1.0 for every y, a NaN included.
  • Pow(x, y) is a NaN when x is negative and y is not an integer — there is no real result.
  • When x is negative and y is an odd integer, the result is negative; when y is an even integer, it is positive.
  • Pow(x, 2.0) and Pow(x, 0.5) (for non-negative x) are recognized and computed directly, as x * x and Sqrt(x).

Example

import Math::Pow;

func Main() -> int {
    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
    return 0;
}

See also

  • Math — the package overview
  • Sqrt — the common square-root case
  • Cbrt — real cube roots, including negative arguments