MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / sin

Function sin

src/compute-engine/interval/trigonometric.ts:25–50  ·  view source on GitHub ↗
(x: Interval | IntervalResult)

Source from the content-addressed store, hash-verified

23const THREE_HALF_PI = (3 * Math.PI) / 2;
24
25/**
26 * Sine of an interval.
27 *
28 * Sin is bounded [-1, 1] and periodic with extrema at pi/2 + n*pi.
29 */
30export function sin(x: Interval | IntervalResult): IntervalResult {
31 const unwrapped = unwrapOrPropagate(x);
32 if (!Array.isArray(unwrapped)) return unwrapped;
33 const [xVal] = unwrapped;
34 // Wide interval spans full range
35 if (xVal.hi - xVal.lo >= TWO_PI) {
36 return ok({ lo: -1, hi: 1 });
37 }
38
39 // Endpoint values
40 const sinLo = Math.sin(xVal.lo);
41 const sinHi = Math.sin(xVal.hi);
42 let lo = Math.min(sinLo, sinHi);
43 let hi = Math.max(sinLo, sinHi);
44
45 // Check for maximum at pi/2 + 2n*pi
46 if (containsExtremum(xVal, HALF_PI, TWO_PI)) {
47 hi = 1;
48 }
49 // Check for minimum at 3*pi/2 + 2n*pi
50 if (containsExtremum(xVal, THREE_HALF_PI, TWO_PI)) {
51 lo = -1;
52 }
53

Callers 3

gen_cases.pyFile · 0.85
gen_solve.pyFile · 0.85

Calls 4

unwrapOrPropagateFunction · 0.90
okFunction · 0.90
containsExtremumFunction · 0.90
sinMethod · 0.80

Tested by

no test coverage detected