Quirrel4.41.0

math.pow

Defined in module "math"
from "math" import pow
pure fastcall pow(x: number, y: number): float

Returns x raised to the power y

Parameters

xnumberthe base
ynumberthe exponent

Return value

x raised to the power y, as a float.

Notes

The result is always a float, even when both x and y are integers: type(pow(2, 3)) is "float".

Out-of-domain input does not throw. A negative x with a fractional y gives NaN; x equal to 0 with a negative y gives infinity. Both print differently between compilers and platforms, so do not print them from portable code.

Example

examples/math/pow.nut
from "math" import pow

println("pow(2, 10) =", pow(2, 10))
println("pow(2.0, 0.5) =", pow(2.0, 0.5))

// integer arguments still give a float result
println("type(pow(2, 3)) =", type(pow(2, 3)))
Output:
pow(2, 10) = 1024
pow(2.0, 0.5) = 1.41421
type(pow(2, 3)) = float

See also

sqrtReturns the square root of x
expReturns e raised to the power of x
logReturns the natural logarithm of x
mathmodule index