fix: lint
This commit is contained in:
parent
5a5ef737ce
commit
64c0c97973
@ -22,12 +22,18 @@ const MAX_EXP = (1n << EXP_BITS) - 1n;
|
|||||||
const EXP_BITS_NUM = Number(EXP_BITS);
|
const EXP_BITS_NUM = Number(EXP_BITS);
|
||||||
const MANT_BITS_NUM = Number(MANT_BITS);
|
const MANT_BITS_NUM = Number(MANT_BITS);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
function normaliseInput(input) {
|
function normaliseInput(input) {
|
||||||
if (input === null || input === undefined)
|
if (input === null || input === undefined)
|
||||||
throw new Error("Invalid decimal number");
|
throw new Error("Invalid decimal number");
|
||||||
return String(input).trim();
|
return String(input).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
function safeBigInt(str, context="number") {
|
function safeBigInt(str, context="number") {
|
||||||
try {
|
try {
|
||||||
return BigInt(str);
|
return BigInt(str);
|
||||||
@ -36,12 +42,18 @@ function safeBigInt(str, context="number") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
function validateDecimal(input) {
|
function validateDecimal(input) {
|
||||||
// validates optional-sign base-10 decimal input: integers, decimals with optional digits before or after the decimal point, and scientific notation
|
// validates optional-sign base-10 decimal input: integers, decimals with optional digits before or after the decimal point, and scientific notation
|
||||||
if (!/^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i.test(input))
|
if (!/^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i.test(input))
|
||||||
throw new Error("Invalid decimal number");
|
throw new Error("Invalid decimal number");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
function validateBinary64(input) {
|
function validateBinary64(input) {
|
||||||
input = normaliseInput(input);
|
input = normaliseInput(input);
|
||||||
|
|
||||||
|
|||||||
@ -37,6 +37,9 @@ class FromIEEEBinary extends Operation {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
if (input === null || input === undefined)
|
if (input === null || input === undefined)
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
@ -69,14 +69,14 @@ TestRegister.addApiTests([
|
|||||||
it("BigIntUtils: egcd - coprime numbers", () => {
|
it("BigIntUtils: egcd - coprime numbers", () => {
|
||||||
const [g, x, y] = egcd(BigInt("3"), BigInt("11"));
|
const [g, x, y] = egcd(BigInt("3"), BigInt("11"));
|
||||||
assert.strictEqual(g, BigInt("1"));
|
assert.strictEqual(g, BigInt("1"));
|
||||||
// Verify Bézout identity: a*x + b*y = gcd
|
// Verify B<EFBFBD>zout identity: a*x + b*y = gcd
|
||||||
assert.strictEqual(BigInt("3") * x + BigInt("11") * y, g);
|
assert.strictEqual(BigInt("3") * x + BigInt("11") * y, g);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
it("BigIntUtils: egcd - non-coprime numbers", () => {
|
it("BigIntUtils: egcd - non-coprime numbers", () => {
|
||||||
const [g, x, y] = egcd(BigInt("240"), BigInt("46"));
|
const [g, x, y] = egcd(BigInt("240"), BigInt("46"));
|
||||||
assert.strictEqual(g, BigInt("2"));
|
assert.strictEqual(g, BigInt("2"));
|
||||||
// Verify Bézout identity
|
// Verify B<EFBFBD>zout identity
|
||||||
assert.strictEqual(BigInt("240") * x + BigInt("46") * y, g);
|
assert.strictEqual(BigInt("240") * x + BigInt("46") * y, g);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ TestRegister.addApiTests([
|
|||||||
it("BigIntUtils: egcd - identical numbers", () => {
|
it("BigIntUtils: egcd - identical numbers", () => {
|
||||||
const [g, x, y] = egcd(BigInt("42"), BigInt("42"));
|
const [g, x, y] = egcd(BigInt("42"), BigInt("42"));
|
||||||
assert.strictEqual(g, BigInt("42"));
|
assert.strictEqual(g, BigInt("42"));
|
||||||
// Verify Bézout identity
|
// Verify B<EFBFBD>zout identity
|
||||||
assert.strictEqual(BigInt("42") * x + BigInt("42") * y, g);
|
assert.strictEqual(BigInt("42") * x + BigInt("42") * y, g);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ TestRegister.addApiTests([
|
|||||||
const a = BigInt("123456789012345678901234567890");
|
const a = BigInt("123456789012345678901234567890");
|
||||||
const b = BigInt("987654321098765432109876543210");
|
const b = BigInt("987654321098765432109876543210");
|
||||||
const [g, x, y] = egcd(a, b);
|
const [g, x, y] = egcd(a, b);
|
||||||
// Verify Bézout identity
|
// Verify B<EFBFBD>zout identity
|
||||||
assert.strictEqual(a * x + b * y, g);
|
assert.strictEqual(a * x + b * y, g);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user