Reference · Math

math.acos

signature
math.acos(num) -> float

What it does

The arc cosine: the angle in radians, between 0 and pi, whose cosine is the number, as Python's math.acos. The number must be between -1 and 1. The angle in degrees comes from math.degrees.

Examples

print(math.acos(1), math.acos(0), math.acos(-1))print(math.acos(0.5), math.degrees(math.acos(0.5)))
output
0.0 1.5707963267948966 3.1415926535897931.0471975511965979 60.00000000000001

Edge cases

print(math.degrees(math.acos(0.5)), round(math.degrees(math.acos(0.5)), 10))let c = 1.0000000000000002print(math.acos(min([1, max([-1, c])])))print(math.acos(math.cos(1)), math.acos(math.cos(-1)))print(math.acos(math.nan))
output
60.00000000000001 60.00.00.9999999999999999 0.9999999999999999NaN

Errors

A number outside -1..1, infinity included, is a runtime error (a domain error), not an error value: it stops the request, and ?? does not catch it. A value that is not a number is a runtime error too.

this one fails
print(math.acos(2))
output
line 1: `math.acos`: math domain error (2)
this one fails
print(math.acos(math.inf))
output
line 1: `math.acos`: math domain error (inf)

Chaining

The angle between two vectors, from their dot product:

let a = [1, 0]let b = [1, 1]print(vec.dot(a, b) / (vec.norm(a) * vec.norm(b)) | math.acos | math.degrees | round(6))print([1, 0, -1] | map(math.acos))
output
45.0[0.0, 1.5707963267948966, 3.141592653589793]

See also

math.cos, math.asin, math.atan2, math.degrees, vec.dot

Thread
6Useful? Like it, or add to its thread below.

Thread 0 posts

On math.acos(): questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.

    Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo