fix: lint

This commit is contained in:
atsiv sivat 2026-03-21 18:51:36 +00:00
parent 5a5ef737ce
commit 64c0c97973
5 changed files with 62 additions and 47 deletions

View File

@ -1272,7 +1272,7 @@ class Utils {
* @returns {BigInt}
*/
static gcdBigInt(a, b) {
return b === 0n ? a : Utils.gcdBigInt(b, a % b);
return b === 0n ? a : Utils.gcdBigInt(b, a % b);
}

View File

@ -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, "");
}

View File

@ -37,21 +37,24 @@ class FromIEEEBinary extends Operation {
* @returns {string}
*/
/**
*
*/
run(input, args) {
if (input === null || input === undefined)
return "";
if (input === null || input === undefined)
return "";
input = String(input);
input = String(input);
if (input.trim().length === 0)
return "";
if (input.trim().length === 0)
return "";
try {
return FromIEEE754Float64(input);
} catch (err) {
throw new OperationError(err.message);
try {
return FromIEEE754Float64(input);
} catch (err) {
throw new OperationError(err.message);
}
}
}
}
export default FromIEEEBinary;

View File

@ -35,22 +35,22 @@ class ToIEEEBinary extends Operation {
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
if (input === null || input === undefined)
return "";
run(input, args) {
if (input === null || input === undefined)
return "";
input = String(input);
input = String(input);
if (input.trim().length === 0)
return "";
if (input.trim().length === 0)
return "";
try {
return ToIEEE754Float64(input);
} catch (err) {
throw new OperationError(err.message);
try {
return ToIEEE754Float64(input);
} catch (err) {
throw new OperationError(err.message);
}
}
}
}

View File

@ -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);
}),