(expr: Expression)
| 2 | import { operand, machineValue, symbol, operator, operands } from './utils.js'; |
| 3 | |
| 4 | function 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 | |
| 15 | function serializeNumber(expr: Expression): string | null { |
| 16 | if (operator(expr) === 'Complex') { |
no test coverage detected