Reference · Math

math.tan

signature
math.tan(num) -> float

What it does

The tangent of an angle in radians, as a float, as Python's math.tan. An angle in degrees is converted first with math.radians.

Examples

print(math.tan(0), math.tan(math.pi / 4), math.tan(1))print(math.tan(math.radians(45)), math.tan(-math.pi / 4))
output
0.0 0.9999999999999999 1.55740772465490230.9999999999999999 -0.9999999999999999

Edge cases

print(math.tan(math.radians(45)), round(math.tan(math.radians(45)), 10))print(math.tan(math.pi / 2) > 1e16, math.isfinite(math.tan(math.pi / 2)))print(math.tan(math.nan))print(math.isclose(math.tan(1), math.sin(1) / math.cos(1)))
output
0.9999999999999999 1.0true trueNaNtrue

Errors

inf or -inf is a runtime error (a domain error), not an error value: it stops the request. A value that is not a number is a runtime error too; a decimal is converted first with float.

this one fails
print(math.tan(math.inf))
output
line 1: `math.tan`: math domain error (inf)
this one fails
print(math.tan(dec("1")))
output
line 1: `math.tan` expects a number as argument 1, got dec (this works on floats: convert a dec with float(x))

Chaining

A slope from an angle, and the angle back with math.atan:

print(30 | math.radians | math.tan)print(30 | math.radians | math.tan | math.atan | math.degrees)
output
0.577350269189625729.999999999999996

See also

math.sin, math.cos, math.atan, math.atan2, math.radians, math.tanh

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

Thread 0 posts

On math.tan(): 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