Menu

MySQL SIN() Function: Sine of an Angle in Radians

Updated on

MySQL SIN(X) returns the sine of X, where X is an angle in radians. If your input is in degrees, convert it with RADIANS() first. SIN(NULL) returns NULL.

SIN() Syntax

SIN(X)

X is the angle, measured in radians. MySQL reports NULL for a NULL argument; mathematical functions also return NULL when an error occurs.

Use an angle in degrees

SIN() does not take degrees directly. Convert degrees to radians with RADIANS():

SELECT SIN(RADIANS(30)) AS sine_of_30_degrees,
       SIN(RADIANS(90)) AS sine_of_90_degrees;

Use DEGREES() for the reverse conversion. For related trigonometric functions, see COS() and TAN().

Floating-point results

Trigonometric results use approximate floating-point arithmetic. For example, SIN(PI()) is very close to zero, but MySQL returns a small nonzero value. This is expected; do not rely on an exact = 0 comparison for such results. Round for display when appropriate, or choose a tolerance suited to the calculation:

SELECT SIN(PI()) AS sine_of_pi,
       ROUND(SIN(PI())) AS rounded_for_display;
sine_of_pi             rounded_for_display
---------------------  -------------------
1.2246063538224e-16    0

The rounded value is suitable for display, but do not use rounding as a substitute for choosing a meaningful tolerance in numeric comparisons.

Further reading