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

Function serializeBaseForm

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

Source from the content-addressed store, hash-verified

2import { operand, machineValue, symbol, operator, operands } from './utils.js';
3
4function serializeBaseForm(expr: Expression): string | null {
5 if (operator(expr) !== 'BaseForm') return null;
6 const op1 = machineValue(operand(expr, 1));
7 if (op1 === null || !Number.isInteger(op1) || op1 < 0) return null;
8 const base = machineValue(operand(expr, 2)) ?? 10;
9 if (base === 2) return `0b${op1.toString(2)}`;
10 if (base === 8) return `0o${op1.toString(8)}`;
11 if (base === 16) return `0x${op1.toString(16)}`;
12 return op1.toString();
13}
14
15function serializeNumber(expr: Expression): string | null {
16 if (operator(expr) === 'Complex') {

Callers 1

serializeFunctionFunction · 0.85

Calls 5

operatorFunction · 0.90
machineValueFunction · 0.90
operandFunction · 0.90
toStringMethod · 0.65
isIntegerMethod · 0.45

Tested by

no test coverage detected