Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
34 lines
939 B
Plaintext
34 lines
939 B
Plaintext
import { Decimal } from "decimal.js";
|
|
import { ToPrimitive } from "./262.js";
|
|
/**
|
|
* https://tc39.es/ecma402/#sec-tointlmathematicalvalue
|
|
* Converts input to a mathematical value, supporting BigInt
|
|
*/
|
|
export function ToIntlMathematicalValue(input) {
|
|
// Handle BigInt directly before ToPrimitive, since ToPrimitive doesn't
|
|
// handle bigint in its type signature (though the spec says it should return it as-is)
|
|
if (typeof input === "bigint") {
|
|
return new Decimal(input.toString());
|
|
}
|
|
let primValue = ToPrimitive(input, "number");
|
|
// Handle other primitive types
|
|
if (primValue === undefined) {
|
|
return new Decimal(NaN);
|
|
}
|
|
if (primValue === true) {
|
|
return new Decimal(1);
|
|
}
|
|
if (primValue === false) {
|
|
return new Decimal(0);
|
|
}
|
|
if (primValue === null) {
|
|
return new Decimal(0);
|
|
}
|
|
// Try to convert to Decimal (handles numbers and strings)
|
|
try {
|
|
return new Decimal(primValue);
|
|
} catch {
|
|
return new Decimal(NaN);
|
|
}
|
|
}
|