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 MANT_BITS_NUM = Number(MANT_BITS);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function normaliseInput(input) {
|
||||
if (input === null || input === undefined)
|
||||
throw new Error("Invalid decimal number");
|
||||
return String(input).trim();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function safeBigInt(str, context="number") {
|
||||
try {
|
||||
return BigInt(str);
|
||||
@ -36,22 +42,28 @@ function safeBigInt(str, context="number") {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function validateDecimal(input) {
|
||||
// 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))
|
||||
throw new Error("Invalid decimal number");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function validateBinary64(input) {
|
||||
input = normaliseInput(input);
|
||||
|
||||
if (!/^[01\s]+$/.test(input))
|
||||
throw new Error("Binary64 must contain only 0 and 1");
|
||||
|
||||
if (input.replace(/\s+/g,"").length !== 64)
|
||||
if (input.replace(/\s+/g, "").length !== 64)
|
||||
throw new Error("Binary64 must be exactly 64 bits");
|
||||
|
||||
return input.replace(/\s+/g,"");
|
||||
return input.replace(/\s+/g, "");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -37,6 +37,9 @@ class FromIEEEBinary extends Operation {
|
||||
* @returns {string}
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
run(input, args) {
|
||||
if (input === null || input === undefined)
|
||||
return "";
|
||||
@ -51,7 +54,7 @@ class FromIEEEBinary extends Operation {
|
||||
} catch (err) {
|
||||
throw new OperationError(err.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default FromIEEEBinary;
|
||||
|
||||
@ -50,7 +50,7 @@ class ToIEEEBinary extends Operation {
|
||||
throw new OperationError(err.message);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -69,14 +69,14 @@ TestRegister.addApiTests([
|
||||
it("BigIntUtils: egcd - coprime numbers", () => {
|
||||
const [g, x, y] = egcd(BigInt("3"), BigInt("11"));
|
||||
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);
|
||||
}),
|
||||
|
||||
it("BigIntUtils: egcd - non-coprime numbers", () => {
|
||||
const [g, x, y] = egcd(BigInt("240"), BigInt("46"));
|
||||
assert.strictEqual(g, BigInt("2"));
|
||||
// Verify Bézout identity
|
||||
// Verify B<EFBFBD>zout identity
|
||||
assert.strictEqual(BigInt("240") * x + BigInt("46") * y, g);
|
||||
}),
|
||||
|
||||
@ -90,7 +90,7 @@ TestRegister.addApiTests([
|
||||
it("BigIntUtils: egcd - identical numbers", () => {
|
||||
const [g, x, y] = egcd(BigInt("42"), 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);
|
||||
}),
|
||||
|
||||
@ -98,7 +98,7 @@ TestRegister.addApiTests([
|
||||
const a = BigInt("123456789012345678901234567890");
|
||||
const b = BigInt("987654321098765432109876543210");
|
||||
const [g, x, y] = egcd(a, b);
|
||||
// Verify Bézout identity
|
||||
// Verify B<EFBFBD>zout identity
|
||||
assert.strictEqual(a * x + b * y, g);
|
||||
}),
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user