@danielsimonjr/mathts-core 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +11 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -675,8 +675,17 @@ var Fraction = class _Fraction {
|
|
|
675
675
|
numerator;
|
|
676
676
|
denominator;
|
|
677
677
|
constructor(numerator, denominator = 1n) {
|
|
678
|
-
|
|
679
|
-
|
|
678
|
+
const toRatio = (x) => {
|
|
679
|
+
if (typeof x === "number" && !Number.isInteger(x)) {
|
|
680
|
+
const f = _Fraction.fromNumber(x);
|
|
681
|
+
return [f.numerator, f.denominator];
|
|
682
|
+
}
|
|
683
|
+
return [typeof x === "bigint" ? x : BigInt(x), 1n];
|
|
684
|
+
};
|
|
685
|
+
const [pn, qn] = toRatio(numerator);
|
|
686
|
+
const [pd, qd] = toRatio(denominator);
|
|
687
|
+
let num = pn * qd;
|
|
688
|
+
let den = qn * pd;
|
|
680
689
|
if (den === 0n) {
|
|
681
690
|
throw new Error("Fraction denominator cannot be zero");
|
|
682
691
|
}
|