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

Function interval

src/compute-engine/numerics/interval.ts:38–95  ·  view source on GitHub ↗
(expr: Expression)

Source from the content-addressed store, hash-verified

36}
37
38export function interval(expr: Expression): Interval | undefined {
39 if (isFunction(expr, 'Interval')) {
40 let op1: Expression = expr.op1;
41 let op2: Expression = expr.op2;
42 let openStart = false;
43 let openEnd = false;
44 if (isFunction(op1, 'Open')) {
45 openStart = true;
46 op1 = op1.op1;
47 } else if (isFunction(op1, 'Closed')) {
48 op1 = op1.op1;
49 }
50
51 if (isFunction(op2, 'Open')) {
52 openEnd = true;
53 op2 = op2.op1;
54 } else if (isFunction(op2, 'Closed')) {
55 op2 = op2.op1;
56 }
57
58 const start = op1.N();
59 const end = op2.N();
60
61 if (!isNumber(start) || !isNumber(end)) return undefined;
62
63 return { start: start.re, openStart, end: end.re, openEnd };
64 }
65
66 //
67 // Known sets which are also intervals...
68 //
69 if (isSymbol(expr)) {
70 if (expr.symbol === 'EmptySet')
71 return { start: 0, openStart: true, end: 0, openEnd: true };
72
73 if (expr.symbol === 'RealNumbers')
74 return {
75 start: -Infinity,
76 openStart: false,
77 end: Infinity,
78 openEnd: false,
79 };
80
81 if (expr.symbol === 'NegativeNumbers')
82 return { start: -Infinity, openStart: false, end: 0, openEnd: true };
83
84 if (expr.symbol === 'NonPositiveNumbers')
85 return { start: -Infinity, openStart: false, end: 0, openEnd: false };
86
87 if (expr.symbol === 'PositiveNumbers')
88 return { start: 0, openStart: true, end: Infinity, openEnd: false };
89
90 if (expr.symbol === 'NonNegativeNumbers')
91 return { start: 0, openStart: false, end: Infinity, openEnd: false };
92 }
93
94 return undefined;
95}

Callers 2

collections.tsFile · 0.90
domainBoundingRangeFunction · 0.90

Calls 4

isFunctionFunction · 0.70
isNumberFunction · 0.70
isSymbolFunction · 0.70
NMethod · 0.65

Tested by

no test coverage detected