You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/math/base/special/sin/docs/types/index.d.ts
+109-7Lines changed: 109 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -21,28 +21,130 @@
21
21
/**
22
22
* Computes the sine of a number.
23
23
*
24
+
* ## Notes
25
+
* - The input value `x` must be in radians. To convert degrees to radians, multiply by `π/180` (e.g., `sin(45 * Math.PI / 180)`).
26
+
* - The input `x` should be a finite number for meaningful results. Non-finite inputs like `Infinity`, `-Infinity`, or `NaN` return `NaN`.
27
+
* - For very large finite inputs (e.g., `|x| > 1e308`), the result may lose precision due to the periodic nature of sine and floating-point limitations.
28
+
* - The function returns a value between -1 and 1.
29
+
* - The sine function is periodic with a period of 2π (approximately 6.28 radians), so `sin(x) = sin(x % (2 * Math.PI))`.
30
+
* - The function satisfies the symmetry property `sin(-x) = -sin(x)`.
31
+
* - For very small inputs (`|x| < 1e-308`), `sin(x) ≈ x` due to the small-angle approximation.
32
+
* - The function preserves the sign of zero: `sin(-0.0)` returns `-0.0`.
33
+
*
24
34
* @param x - input value (in radians)
25
35
* @returns sine
26
36
*
27
37
* @example
38
+
* // Basic example: sine of 0 radians (0 degrees)
28
39
* var v = sin( 0.0 );
29
-
* // returns ~0.0
40
+
* // returns 0.0
41
+
*
42
+
* @example
43
+
* // Sine of π/2 radians (90 degrees), where sine reaches its maximum
44
+
* var v = sin( 3.141592653589793 / 2.0 );
45
+
* // returns 1.0
46
+
*
47
+
* @example
48
+
* // Sine of -π/6 radians (-30 degrees), a negative angle
49
+
* var v = sin( -3.141592653589793 / 6.0 );
50
+
* // returns -0.5
51
+
*
52
+
* @example
53
+
* // Sine of π radians (180 degrees), a full half-circle
54
+
* var v = sin( 3.141592653589793 );
55
+
* // returns 0.0
56
+
*
57
+
* @example
58
+
* // Sine of π/4 radians (45 degrees), a common angle where sin(π/4) = √2/2
59
+
* var v = sin( 3.141592653589793 / 4.0 );
60
+
* // returns ~0.7071 (approximately √2/2)
61
+
*
62
+
* @example
63
+
* // Sine of π/3 radians (60 degrees), another common angle where sin(π/3) = √3/2
64
+
* var v = sin( 3.141592653589793 / 3.0 );
65
+
* // returns ~0.8660 (approximately √3/2)
66
+
*
67
+
* @example
68
+
* // Sine of 3π/2 radians (270 degrees), where sine reaches its minimum
69
+
* var v = sin( 3 * 3.141592653589793 / 2.0 );
70
+
* // returns -1.0
30
71
*
31
72
* @example
32
-
* var v = sin( 3.141592653589793/2.0 );
33
-
* // returns ~1.0
73
+
* // Edge case: sine of negative zero, should preserve the sign
74
+
* var v = sin( -0.0 );
75
+
* // returns -0.0
34
76
*
35
77
* @example
36
-
* var v = sin( -3.141592653589793/6.0 );
37
-
* // returns ~-0.5
78
+
* // Edge case: sine of a very small number, where sin(x) ≈ x
79
+
* var v = sin( 1e-308 );
80
+
* // returns ~1e-308
38
81
*
39
82
* @example
83
+
* // Edge case: sine of a very large number, exceeds safe computation range
84
+
* var v = sin( 1e308 );
85
+
* // returns NaN
86
+
*
87
+
* @example
88
+
* // Edge case: sine of negative infinity, non-finite input
89
+
* var v = sin( -Infinity );
90
+
* // returns NaN
91
+
*
92
+
* @example
93
+
* // Edge case: sine of NaN, invalid input
40
94
* var v = sin( NaN );
41
95
* // returns NaN
96
+
*
97
+
* @example
98
+
* // Practical use: animate a pulsating effect (e.g., for a UI element)
99
+
* function pulsate(time: number): number {
100
+
* return 0.5 + 0.5 * sin(time); // Oscillates between 0 and 1
0 commit comments