41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
import { Num, add, sub } from "./index.js";
|
|
|
|
const A = 123123;
|
|
const B = 879;
|
|
|
|
const a = Num.parse(A.toString());
|
|
const b = Num.parse(B.toString());
|
|
|
|
/**@type { { expression: string; correct: boolean; }[] } */
|
|
const results = [];
|
|
|
|
for (const radix of /**@type { const } */([10, 2, 8, 16])) {
|
|
const a1 = a.as(radix);
|
|
const b1 = b.as(radix);
|
|
// console.log(`a { radix: ${radix} } ${ a1.toString() } (${ Number(a1.toString()) == A })`);
|
|
results.push({
|
|
expression: `a { radix: ${radix} } ${ a1.toString() }`,
|
|
correct: Number(a1.toString()) == A
|
|
});
|
|
// console.log(`b { radix: ${radix} } ${ b1.toString() } (${ Number(b1.toString()) == B })`);
|
|
results.push({
|
|
expression: `b { radix: ${radix} } ${ b1.toString() }`,
|
|
correct: Number(b1.toString()) == B
|
|
});
|
|
const a2 = a1.copy()
|
|
const a3 = a1.copy();
|
|
add(a2, b1);
|
|
sub(a3, b1);
|
|
// console.log(`a + b = ${ a2.toString() } (${ Number(a2.toString()) == (A + B) })`);
|
|
results.push({
|
|
expression: `a + b = ${ a2.toString() }`,
|
|
correct: Number(a2.toString()) == (A + B)
|
|
});
|
|
// console.log(`a - b = ${ a3.toString() } (${ Number(a3.toString()) == (A - B) })`);
|
|
results.push({
|
|
expression: `a - b = ${ a3.toString() }`,
|
|
correct: Number(a3.toString()) == (A - B)
|
|
});
|
|
}
|
|
|
|
console.table(results); |