Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

math.trig

sine, cosine and friends; angles as units

Example results generated on 2026-10-08. Ones using now, today or randomness will differ when you run them: press Run on any example to run it in your browser, after editing it if you like.

Functions

functiondescription
sin(x: num|quantity)sine of radians or an angle unit
cos(x: num|quantity)cosine of radians or an angle unit
tan(x: num|quantity)tangent of radians or an angle unit
asin(x: num)arcsine, as an angle
acos(x: num)arccosine, as an angle
atan(x: num)arctangent, as an angle
atan2(y: num|quantity, x: num|quantity)angle of the point (x, y), as an angle
sinh(x: num)hyperbolic sine
cosh(x: num)hyperbolic cosine
tanh(x: num)hyperbolic tangent

sin

sin(x: num|quantity): sine of radians or an angle unit

sin(30 deg)
# → 0.5
sin(pi / 2)
# → 1

See also: cos, tan, asin

cos

cos(x: num|quantity): cosine of radians or an angle unit

cos(60 deg)
# → 0.5

See also: sin, tan, acos

tan

tan(x: num|quantity): tangent of radians or an angle unit

tan(45 deg)
# → 1

See also: sin, cos, atan

asin

asin(x: num): arcsine, as an angle

asin(1) to deg
# → 90 deg

See also: sin

acos

acos(x: num): arccosine, as an angle

acos(0) to deg
# → 90 deg

See also: cos

atan

atan(x: num): arctangent, as an angle

atan(1) to deg
# → 45 deg

See also: tan, atan2

atan2

atan2(y: num|quantity, x: num|quantity): angle of the point (x, y), as an angle

atan2(1, -1) to deg
# → 135 deg

See also: atan, hypot

sinh

sinh(x: num): hyperbolic sine

sinh(1)
# → 1.1752

See also: cosh, tanh

cosh

cosh(x: num): hyperbolic cosine

cosh(1)
# → 1.54308

See also: sinh, tanh

tanh

tanh(x: num): hyperbolic tangent

tanh(1)
# → 0.761594

See also: sinh, cosh

More examples

trig

# trig takes angle units
sin(30 deg)
# → 0.5
# radians back to degrees
atan2(1, 1) to deg
# → 45 deg