Reference · Math
math.sin
signature
math.sin(num) -> floatWhat it does
The sine of an angle in radians, as a float, as Python's math.sin. An angle in
degrees is converted first with math.radians.
Examples
print(math.sin(0), math.sin(math.pi / 2), math.sin(1))print(math.sin(math.radians(90)), math.sin(math.radians(30)))output
0.0 1.0 0.84147098480789651.0 0.49999999999999994Edge cases
- Floating point:
math.sin(math.pi)is about1.2e-16, not0, and the sine of 30 degrees is0.49999999999999994. Round when a clean figure is wanted. - A huge angle is still reduced exactly, as Python does:
math.sin(1e22)is-0.8522008497671888. NaNgivesNaN; an infinite angle is a domain error.
print(math.sin(math.pi), round(math.sin(math.pi), 12))print(math.sin(math.radians(30)), round(math.sin(math.radians(30)), 10))print(math.sin(1e22), math.sin(math.nan))output
0.00000000000000012246467991473532 0.00.49999999999999994 0.5-0.8522008497671888 NaNErrors
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.sin(math.inf))output
line 1: `math.sin`: math domain error (inf)this one fails
print(math.sin("0"))output
line 1: `math.sin` expects a number as argument 1, got strChaining
print(90 | math.radians | math.sin)print([0, 30, 90] | map(math.radians) | map(math.sin) | map((x) => round(x, 10)))output
1.0[0.0, 0.5, 1.0]See also
math.cos, math.tan, math.asin, math.radians, math.sinh
Thread
Thread 0 posts
On math.sin(): 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