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

Function serializeNumber

src/math-json/serialize-sympy.ts:15–43  ·  view source on GitHub ↗
(expr: Expression)

Source from the content-addressed store, hash-verified

13}
14
15function serializeNumber(expr: Expression): string | null {
16 if (operator(expr) === 'Complex') {
17 const op1 = operand(expr, 1);
18 const op2 = operand(expr, 2);
19 if (op1 === null || op2 === null) return null;
20 if (machineValue(op1) === 0) {
21 return serializeNumber(op2) + 'j';
22 }
23 if (machineValue(op2) === 0) return serializeNumber(op1);
24 return '(' + serializeNumber(op1) + ' + ' + serializeNumber(op2) + 'j)';
25 }
26
27 if (operator(expr) === 'Rational') {
28 const op1 = operand(expr, 1);
29 const op2 = operand(expr, 2);
30 if (op1 === null || op2 === null) return null;
31 return `Rational(${serializeNumber(op1)},${serializeNumber(op2)})`;
32 }
33
34 if (operator(expr) === 'Number') {
35 const op1 = machineValue(operand(expr, 1));
36 if (op1 === null) return null;
37 return op1.toString();
38 }
39
40 const op1 = machineValue(expr);
41 if (op1 === null) return null;
42 return op1.toString();
43}
44
45function serializeSymbol(expr: Expression): string | null {
46 const sym = symbol(expr);

Callers 1

serializeExpressionFunction · 0.70

Calls 4

operatorFunction · 0.90
operandFunction · 0.90
machineValueFunction · 0.90
toStringMethod · 0.65

Tested by

no test coverage detected