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

Function bigintValue

src/compute-engine/numerics/expression.ts:6–31  ·  view source on GitHub ↗
(
  expr: MathJsonExpression | null | undefined
)

Source from the content-addressed store, hash-verified

4import { numberToString } from './strings.js';
5
6export function bigintValue(
7 expr: MathJsonExpression | null | undefined
8): bigint | null {
9 if (typeof expr === 'number')
10 return Number.isInteger(expr) ? BigInt(expr) : null;
11
12 if (expr === null || expr === undefined) return null;
13
14 if (!isNumberExpression(expr)) return null;
15
16 const num = isNumberObject(expr) ? expr.num : expr;
17
18 if (typeof num === 'number')
19 return Number.isInteger(num) ? BigInt(num) : null;
20 if (typeof num !== 'string') return null;
21
22 const s = num
23 .toLowerCase()
24 .replace(/[nd]$/, '')
25 .replace(/[\u0009-\u000d\u0020\u00a0]/g, '');
26
27 if (s === 'nan') return null;
28 if (/^(infinity|\+infinity|oo|\+oo|-infinity|-oo)$/.test(s)) return null;
29
30 return bigint(s);
31}
32
33/** Output a shorthand if possible */
34export function numberToExpression(

Callers 1

asBigintFunction · 0.90

Calls 5

isNumberExpressionFunction · 0.90
isNumberObjectFunction · 0.90
bigintFunction · 0.90
replaceMethod · 0.65
isIntegerMethod · 0.45

Tested by

no test coverage detected