Quirrel4.41.0

math.acos

Defined in module "math"
from "math" import acos
pure fastcall acos(x: number): float

Returns the arccosine of x

Parameters

xnumbervalue whose arccosine is wanted

Return value

The arccosine of x, in the range [0, PI], always as a float.

Notes

The mathematical arccosine is only defined for x in [-1, 1]; C's acos answers a domain error with nan outside it. Quirrel avoids that: x is clamped to [-1, 1] before the call, so acos(2) quietly returns the same value as acos(1) instead of nan.

Example

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

println("acos(1) =", acos(1))
println("acos(0.5) =", acos(0.5))
println("acos(-1) =", acos(-1))

// out of [-1, 1], the argument is clamped instead of returning nan
println("acos(2) == acos(1) =", acos(2) == acos(1))
println("acos(-2) == acos(-1) =", acos(-2) == acos(-1))
Output:
acos(1) = 0
acos(0.5) = 1.0472
acos(-1) = 3.14159
acos(2) == acos(1) = true
acos(-2) == acos(-1) = true

See also

asinReturns the arcsine of x
atanReturns the arctangent of x
cosReturns the cosine of x (in radians)
PIThe ratio of a circle's circumference to its diameter, for converting between radians and degrees and for angle math in general.
mathmodule index