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

Function cos

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

Source from the content-addressed store, hash-verified

55}
56
57/**
58 * Cosine of an interval.
59 *
60 * Cos is bounded [-1, 1] and periodic with extrema at n*pi.
61 */
62export function cos(x: Interval | IntervalResult): IntervalResult {
63 const unwrapped = unwrapOrPropagate(x);
64 if (!Array.isArray(unwrapped)) return unwrapped;
65 const [xVal] = unwrapped;
66 // Wide interval spans full range
67 if (xVal.hi - xVal.lo >= TWO_PI) {
68 return ok({ lo: -1, hi: 1 });
69 }
70
71 // Endpoint values
72 const cosLo = Math.cos(xVal.lo);
73 const cosHi = Math.cos(xVal.hi);
74 let lo = Math.min(cosLo, cosHi);
75 let hi = Math.max(cosLo, cosHi);
76
77 // Check for maximum at 2n*pi (including 0)
78 if (containsExtremum(xVal, 0, TWO_PI)) {
79 hi = 1;
80 }
81 // Check for minimum at pi + 2n*pi
82 if (containsExtremum(xVal, PI, TWO_PI)) {
83 lo = -1;
84 }
85

Callers 4

gen_kernel_refs.pyFile · 0.85
gen_cases.pyFile · 0.85
gen_solve.pyFile · 0.85

Calls 4

unwrapOrPropagateFunction · 0.90
okFunction · 0.90
containsExtremumFunction · 0.90
cosMethod · 0.80

Tested by

no test coverage detected