functionalscript
Version:
FunctionalScript is a purely functional subset of JavaScript
349 lines (348 loc) • 11.3 kB
JavaScript
import { decToBin } from "./module.f.js";
export default {
decToBin: [
() => {
const result = decToBin([0n, 0]);
if (result[0] !== 0n) {
throw result[0].toString(2);
}
if (result[1] !== 0) {
throw result[1];
}
},
() => {
const result = decToBin([0n, 10]);
if (result[0] !== 0n) {
throw result[0].toString(2);
}
if (result[1] !== 0) {
throw result[1];
}
},
() => {
const result = decToBin([0n, -10]);
if (result[0] !== 0n) {
throw result[0].toString(2);
}
if (result[1] !== 0) {
throw result[1];
}
},
() => {
const result = decToBin([1n, 0]);
if (result[0] !== 4503599627370496n) {
throw result[0].toString(2);
}
if (result[1] !== -52) {
throw result[1];
}
},
() => {
const result = decToBin([1n, 1]);
if (result[0] !== 5629499534213120n) {
throw result[0].toString(2);
}
if (result[1] !== -49) {
throw result[1];
}
},
() => {
const result = decToBin([1000n, -2]);
if (result[0] !== 5629499534213120n) {
throw result[0].toString(2);
}
if (result[1] !== -49) {
throw result[1];
}
},
() => {
const result = decToBin([1n, -1]);
if (result[0] !== 7205759403792794n) {
throw result[0].toString(2);
} //+1
if (result[1] !== -56) {
throw result[1];
}
},
() => {
const result = decToBin([-1n, 0]);
if (result[0] !== -4503599627370496n) {
throw result[0].toString(2);
}
if (result[1] !== -52) {
throw result[1];
}
},
() => {
const result = decToBin([-1n, 1]);
if (result[0] !== -5629499534213120n) {
throw result[0].toString(2);
}
if (result[1] !== -49) {
throw result[1];
}
},
() => {
const result = decToBin([-1000n, -2]);
if (result[0] !== -5629499534213120n) {
throw result[0].toString(2);
}
if (result[1] !== -49) {
throw result[1];
}
},
() => {
const result = decToBin([-1n, -1]);
if (result[0] !== -7205759403792794n) {
throw result[0].toString(2);
} //+1
if (result[1] !== -56) {
throw result[1];
}
},
() => {
const result = decToBin([9007199254740993n, 0]); //54bits (...0.1)
if (result[0] !== 4503599627370496n) {
throw result[0].toString(2);
}
if (result[1] !== 1) {
throw result[1];
}
},
() => {
const result = decToBin([-9007199254740995n, 0]); //54bits (...1.1)
if (result[0] !== -4503599627370498n) {
throw result[0].toString(2);
}
if (result[1] !== 1) {
throw result[1];
}
},
() => {
const result = decToBin([-9007199254740993n, 0]); //54bits (...0.1)
if (result[0] !== -4503599627370496n) {
throw result[0].toString(2);
}
if (result[1] !== 1) {
throw result[1];
}
},
() => {
const result = decToBin([-9007199254740995n, 0]); //54bits (...1.1)
if (result[0] !== -4503599627370498n) {
throw result[0].toString(2);
}
if (result[1] !== 1) {
throw result[1];
}
},
() => {
const result = decToBin([18014398509481985n, 0]); //55bits (...0.01)
if (result[0] !== 4503599627370496n) {
throw result[0].toString(2);
}
if (result[1] !== 2) {
throw result[1];
}
},
() => {
const result = decToBin([18014398509481986n, 0]); //55bits (...0.10)
if (result[0] !== 4503599627370496n) {
throw result[0].toString(2);
}
if (result[1] !== 2) {
throw result[1];
}
},
() => {
const result = decToBin([18014398509481990n, 0]); //55bits (...1.10)
if (result[0] !== 4503599627370498n) {
throw result[0].toString(2);
}
if (result[1] !== 2) {
throw result[1];
}
},
() => {
const result = decToBin([18014398509481987n, 0]); //55bits (0.11)
if (result[0] !== 4503599627370497n) {
throw result[0].toString(2);
}
if (result[1] !== 2) {
throw result[1];
}
},
],
roundingPositive: [
() => {
const result = decToBin([288230376151711745n, -1]);
// reminder = 0
// m = 11001100110011001100110011001100110011001100110011001.101
// rounding up
if (result[0] !== 7205759403792794n) {
throw result[0].toString(2);
}
if (result[1] !== 2) {
throw result[1];
}
},
() => {
const result = decToBin([288230376151711760n, -1]);
// reminder = 0
// m = 11001100110011001100110011001100110011001100110011010.000
// rounding down
if (result[0] !== 7205759403792794n) {
throw result[0].toString(2);
}
if (result[1] !== 2) {
throw result[1];
}
},
() => {
const result = decToBin([288230376151711780n, -1]);
// reminder = 0
// m = 11001100110011001100110011001100110011001100110011010.100
// rounding down (to even)
if (result[0] !== 7205759403792794n) {
throw result[0].toString(2);
}
if (result[1] !== 2) {
throw result[1];
}
},
() => {
const result = decToBin([288230376151711781n, -1]);
// reminder = 1
// m = 11001100110011001100110011001100110011001100110011010.100
// rounding up
if (result[0] !== 7205759403792795n) {
throw result[0].toString(2);
}
if (result[1] !== 2) {
throw result[1];
}
},
() => {
const result = decToBin([288230376151711785n, -1]);
// reminder = 0
// m = 11001100110011001100110011001100110011001100110011010.101
// rounding up
if (result[0] !== 7205759403792795n) {
throw result[0].toString(2);
}
if (result[1] !== 2) {
throw result[1];
}
},
() => {
const result = decToBin([288230376151711805n, -1]);
// reminder = 0
// m = 11001100110011001100110011001100110011001100110011011.001
// rounding down
if (result[0] !== 7205759403792795n) {
throw result[0].toString(2);
}
if (result[1] !== 2) {
throw result[1];
}
},
() => {
const result = decToBin([288230376151711820n, -1]);
// reminder = 0
// m = 11001100110011001100110011001100110011001100110011011.100
// rounding up (to even)
if (result[0] !== 7205759403792796n) {
throw result[0].toString(2);
}
if (result[1] !== 2) {
throw result[1];
}
}
],
roundingNegative: [
() => {
const result = decToBin([-288230376151711745n, -1]);
// reminder = 0
// m = -11001100110011001100110011001100110011001100110011001.101
// rounding down
if (result[0] !== -7205759403792794n) {
throw result[0].toString(2);
}
if (result[1] !== 2) {
throw result[1];
}
},
() => {
const result = decToBin([-288230376151711760n, -1]);
// reminder = 0
// m = -11001100110011001100110011001100110011001100110011010.000
// rounding up
if (result[0] !== -7205759403792794n) {
throw result[0].toString(2);
}
if (result[1] !== 2) {
throw result[1];
}
},
() => {
const result = decToBin([-288230376151711780n, -1]);
// reminder = 0
// m = -11001100110011001100110011001100110011001100110011010.100
// rounding up (to even)
if (result[0] !== -7205759403792794n) {
throw result[0].toString(2);
}
if (result[1] !== 2) {
throw result[1];
}
},
() => {
const result = decToBin([-288230376151711781n, -1]);
// reminder = 1
// m = -11001100110011001100110011001100110011001100110011010.100
// rounding down
if (result[0] !== -7205759403792795n) {
throw result[0].toString(2);
}
if (result[1] !== 2) {
throw result[1];
}
},
() => {
const result = decToBin([-288230376151711785n, -1]);
// reminder = 0
// m = -11001100110011001100110011001100110011001100110011010.101
// rounding down
if (result[0] !== -7205759403792795n) {
throw result[0].toString(2);
}
if (result[1] !== 2) {
throw result[1];
}
},
() => {
const result = decToBin([-288230376151711805n, -1]);
// reminder = 0
// m = -11001100110011001100110011001100110011001100110011011.001
// rounding up
if (result[0] !== -7205759403792795n) {
throw result[0].toString(2);
}
if (result[1] !== 2) {
throw result[1];
}
},
() => {
const result = decToBin([-288230376151711820n, -1]);
// reminder = 0
// m = -11001100110011001100110011001100110011001100110011011.100
// rounding down (to even)
if (result[0] !== -7205759403792796n) {
throw result[0].toString(2);
}
if (result[1] !== 2) {
throw result[1];
}
}
]
};