continuedfraction.js 0.0.1 → 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../node_modules/fraction.js/dist/fraction.mjs", "../src/continuedfraction.ts"],
4
+ "sourcesContent": ["'use strict';\n\n/**\n *\n * This class offers the possibility to calculate fractions.\n * You can pass a fraction in different formats. Either as array, as double, as string or as an integer.\n *\n * Array/Object form\n * [ 0 => <numerator>, 1 => <denominator> ]\n * { n => <numerator>, d => <denominator> }\n *\n * Integer form\n * - Single integer value as BigInt or Number\n *\n * Double form\n * - Single double value as Number\n *\n * String form\n * 123.456 - a simple double\n * 123/456 - a string fraction\n * 123.'456' - a double with repeating decimal places\n * 123.(456) - synonym\n * 123.45'6' - a double with repeating last place\n * 123.45(6) - synonym\n *\n * Example:\n * let f = new Fraction(\"9.4'31'\");\n * f.mul([-4, 3]).div(4.9);\n *\n */\n\n// Set Identity function to downgrade BigInt to Number if needed\nif (typeof BigInt === 'undefined') BigInt = function (n) { if (isNaN(n)) throw new Error(\"\"); return n; };\n\nconst C_ZERO = BigInt(0);\nconst C_ONE = BigInt(1);\nconst C_TWO = BigInt(2);\nconst C_FIVE = BigInt(5);\nconst C_TEN = BigInt(10);\n\n// Maximum search depth for cyclic rational numbers. 2000 should be more than enough.\n// Example: 1/7 = 0.(142857) has 6 repeating decimal places.\n// If MAX_CYCLE_LEN gets reduced, long cycles will not be detected and toString() only gets the first 10 digits\nconst MAX_CYCLE_LEN = 2000;\n\n// Parsed data to avoid calling \"new\" all the time\nconst P = {\n \"s\": C_ONE,\n \"n\": C_ZERO,\n \"d\": C_ONE\n};\n\nfunction assign(n, s) {\n\n try {\n n = BigInt(n);\n } catch (e) {\n throw InvalidParameter();\n }\n return n * s;\n}\n\nfunction trunc(x) {\n return typeof x === 'bigint' ? x : Math.floor(x);\n}\n\n// Creates a new Fraction internally without the need of the bulky constructor\nfunction newFraction(n, d) {\n\n if (d === C_ZERO) {\n throw DivisionByZero();\n }\n\n const f = Object.create(Fraction.prototype);\n f[\"s\"] = n < C_ZERO ? -C_ONE : C_ONE;\n\n n = n < C_ZERO ? -n : n;\n\n const a = gcd(n, d);\n\n f[\"n\"] = n / a;\n f[\"d\"] = d / a;\n return f;\n}\n\nfunction factorize(num) {\n\n const factors = {};\n\n let n = num;\n let i = C_TWO;\n let s = C_FIVE - C_ONE;\n\n while (s <= n) {\n\n while (n % i === C_ZERO) {\n n /= i;\n factors[i] = (factors[i] || C_ZERO) + C_ONE;\n }\n s += C_ONE + C_TWO * i++;\n }\n\n if (n !== num) {\n if (n > 1)\n factors[n] = (factors[n] || C_ZERO) + C_ONE;\n } else {\n factors[num] = (factors[num] || C_ZERO) + C_ONE;\n }\n return factors;\n}\n\nconst parse = function (p1, p2) {\n\n let n = C_ZERO, d = C_ONE, s = C_ONE;\n\n if (p1 === undefined || p1 === null) { // No argument\n /* void */\n } else if (p2 !== undefined) { // Two arguments\n\n if (typeof p1 === \"bigint\") {\n n = p1;\n } else if (isNaN(p1)) {\n throw InvalidParameter();\n } else if (p1 % 1 !== 0) {\n throw NonIntegerParameter();\n } else {\n n = BigInt(p1);\n }\n\n if (typeof p2 === \"bigint\") {\n d = p2;\n } else if (isNaN(p2)) {\n throw InvalidParameter();\n } else if (p2 % 1 !== 0) {\n throw NonIntegerParameter();\n } else {\n d = BigInt(p2);\n }\n\n s = n * d;\n\n } else if (typeof p1 === \"object\") {\n if (\"d\" in p1 && \"n\" in p1) {\n n = BigInt(p1[\"n\"]);\n d = BigInt(p1[\"d\"]);\n if (\"s\" in p1)\n n *= BigInt(p1[\"s\"]);\n } else if (0 in p1) {\n n = BigInt(p1[0]);\n if (1 in p1)\n d = BigInt(p1[1]);\n } else if (typeof p1 === \"bigint\") {\n n = p1;\n } else {\n throw InvalidParameter();\n }\n s = n * d;\n } else if (typeof p1 === \"number\") {\n\n if (isNaN(p1)) {\n throw InvalidParameter();\n }\n\n if (p1 < 0) {\n s = -C_ONE;\n p1 = -p1;\n }\n\n if (p1 % 1 === 0) {\n n = BigInt(p1);\n } else {\n\n let z = 1;\n\n let A = 0, B = 1;\n let C = 1, D = 1;\n\n let N = 10000000;\n\n if (p1 >= 1) {\n z = 10 ** Math.floor(1 + Math.log10(p1));\n p1 /= z;\n }\n\n // Using Farey Sequences\n\n while (B <= N && D <= N) {\n let M = (A + C) / (B + D);\n\n if (p1 === M) {\n if (B + D <= N) {\n n = A + C;\n d = B + D;\n } else if (D > B) {\n n = C;\n d = D;\n } else {\n n = A;\n d = B;\n }\n break;\n\n } else {\n\n if (p1 > M) {\n A += C;\n B += D;\n } else {\n C += A;\n D += B;\n }\n\n if (B > N) {\n n = C;\n d = D;\n } else {\n n = A;\n d = B;\n }\n }\n }\n n = BigInt(n) * BigInt(z);\n d = BigInt(d);\n }\n\n } else if (typeof p1 === \"string\") {\n\n let ndx = 0;\n\n let v = C_ZERO, w = C_ZERO, x = C_ZERO, y = C_ONE, z = C_ONE;\n\n let match = p1.replace(/_/g, '').match(/\\d+|./g);\n\n if (match === null)\n throw InvalidParameter();\n\n if (match[ndx] === '-') {// Check for minus sign at the beginning\n s = -C_ONE;\n ndx++;\n } else if (match[ndx] === '+') {// Check for plus sign at the beginning\n ndx++;\n }\n\n if (match.length === ndx + 1) { // Check if it's just a simple number \"1234\"\n w = assign(match[ndx++], s);\n } else if (match[ndx + 1] === '.' || match[ndx] === '.') { // Check if it's a decimal number\n\n if (match[ndx] !== '.') { // Handle 0.5 and .5\n v = assign(match[ndx++], s);\n }\n ndx++;\n\n // Check for decimal places\n if (ndx + 1 === match.length || match[ndx + 1] === '(' && match[ndx + 3] === ')' || match[ndx + 1] === \"'\" && match[ndx + 3] === \"'\") {\n w = assign(match[ndx], s);\n y = C_TEN ** BigInt(match[ndx].length);\n ndx++;\n }\n\n // Check for repeating places\n if (match[ndx] === '(' && match[ndx + 2] === ')' || match[ndx] === \"'\" && match[ndx + 2] === \"'\") {\n x = assign(match[ndx + 1], s);\n z = C_TEN ** BigInt(match[ndx + 1].length) - C_ONE;\n ndx += 3;\n }\n\n } else if (match[ndx + 1] === '/' || match[ndx + 1] === ':') { // Check for a simple fraction \"123/456\" or \"123:456\"\n w = assign(match[ndx], s);\n y = assign(match[ndx + 2], C_ONE);\n ndx += 3;\n } else if (match[ndx + 3] === '/' && match[ndx + 1] === ' ') { // Check for a complex fraction \"123 1/2\"\n v = assign(match[ndx], s);\n w = assign(match[ndx + 2], s);\n y = assign(match[ndx + 4], C_ONE);\n ndx += 5;\n }\n\n if (match.length <= ndx) { // Check for more tokens on the stack\n d = y * z;\n s = /* void */\n n = x + d * v + z * w;\n } else {\n throw InvalidParameter();\n }\n\n } else if (typeof p1 === \"bigint\") {\n n = p1;\n s = p1;\n d = C_ONE;\n } else {\n throw InvalidParameter();\n }\n\n if (d === C_ZERO) {\n throw DivisionByZero();\n }\n\n P[\"s\"] = s < C_ZERO ? -C_ONE : C_ONE;\n P[\"n\"] = n < C_ZERO ? -n : n;\n P[\"d\"] = d < C_ZERO ? -d : d;\n};\n\nfunction modpow(b, e, m) {\n\n let r = C_ONE;\n for (; e > C_ZERO; b = (b * b) % m, e >>= C_ONE) {\n\n if (e & C_ONE) {\n r = (r * b) % m;\n }\n }\n return r;\n}\n\nfunction cycleLen(n, d) {\n\n for (; d % C_TWO === C_ZERO;\n d /= C_TWO) {\n }\n\n for (; d % C_FIVE === C_ZERO;\n d /= C_FIVE) {\n }\n\n if (d === C_ONE) // Catch non-cyclic numbers\n return C_ZERO;\n\n // If we would like to compute really large numbers quicker, we could make use of Fermat's little theorem:\n // 10^(d-1) % d == 1\n // However, we don't need such large numbers and MAX_CYCLE_LEN should be the capstone,\n // as we want to translate the numbers to strings.\n\n let rem = C_TEN % d;\n let t = 1;\n\n for (; rem !== C_ONE; t++) {\n rem = rem * C_TEN % d;\n\n if (t > MAX_CYCLE_LEN)\n return C_ZERO; // Returning 0 here means that we don't print it as a cyclic number. It's likely that the answer is `d-1`\n }\n return BigInt(t);\n}\n\nfunction cycleStart(n, d, len) {\n\n let rem1 = C_ONE;\n let rem2 = modpow(C_TEN, len, d);\n\n for (let t = 0; t < 300; t++) { // s < ~log10(Number.MAX_VALUE)\n // Solve 10^s == 10^(s+t) (mod d)\n\n if (rem1 === rem2)\n return BigInt(t);\n\n rem1 = rem1 * C_TEN % d;\n rem2 = rem2 * C_TEN % d;\n }\n return 0;\n}\n\nfunction gcd(a, b) {\n\n if (!a)\n return b;\n if (!b)\n return a;\n\n while (1) {\n a %= b;\n if (!a)\n return b;\n b %= a;\n if (!b)\n return a;\n }\n}\n\n/**\n * Module constructor\n *\n * @constructor\n * @param {number|Fraction=} a\n * @param {number=} b\n */\nfunction Fraction(a, b) {\n\n parse(a, b);\n\n if (this instanceof Fraction) {\n a = gcd(P[\"d\"], P[\"n\"]); // Abuse a\n this[\"s\"] = P[\"s\"];\n this[\"n\"] = P[\"n\"] / a;\n this[\"d\"] = P[\"d\"] / a;\n } else {\n return newFraction(P['s'] * P['n'], P['d']);\n }\n}\n\nvar DivisionByZero = function () { return new Error(\"Division by Zero\"); };\nvar InvalidParameter = function () { return new Error(\"Invalid argument\"); };\nvar NonIntegerParameter = function () { return new Error(\"Parameters must be integer\"); };\n\nFraction.prototype = {\n\n \"s\": C_ONE,\n \"n\": C_ZERO,\n \"d\": C_ONE,\n\n /**\n * Calculates the absolute value\n *\n * Ex: new Fraction(-4).abs() => 4\n **/\n \"abs\": function () {\n\n return newFraction(this[\"n\"], this[\"d\"]);\n },\n\n /**\n * Inverts the sign of the current fraction\n *\n * Ex: new Fraction(-4).neg() => 4\n **/\n \"neg\": function () {\n\n return newFraction(-this[\"s\"] * this[\"n\"], this[\"d\"]);\n },\n\n /**\n * Adds two rational numbers\n *\n * Ex: new Fraction({n: 2, d: 3}).add(\"14.9\") => 467 / 30\n **/\n \"add\": function (a, b) {\n\n parse(a, b);\n return newFraction(\n this[\"s\"] * this[\"n\"] * P[\"d\"] + P[\"s\"] * this[\"d\"] * P[\"n\"],\n this[\"d\"] * P[\"d\"]\n );\n },\n\n /**\n * Subtracts two rational numbers\n *\n * Ex: new Fraction({n: 2, d: 3}).add(\"14.9\") => -427 / 30\n **/\n \"sub\": function (a, b) {\n\n parse(a, b);\n return newFraction(\n this[\"s\"] * this[\"n\"] * P[\"d\"] - P[\"s\"] * this[\"d\"] * P[\"n\"],\n this[\"d\"] * P[\"d\"]\n );\n },\n\n /**\n * Multiplies two rational numbers\n *\n * Ex: new Fraction(\"-17.(345)\").mul(3) => 5776 / 111\n **/\n \"mul\": function (a, b) {\n\n parse(a, b);\n return newFraction(\n this[\"s\"] * P[\"s\"] * this[\"n\"] * P[\"n\"],\n this[\"d\"] * P[\"d\"]\n );\n },\n\n /**\n * Divides two rational numbers\n *\n * Ex: new Fraction(\"-17.(345)\").inverse().div(3)\n **/\n \"div\": function (a, b) {\n\n parse(a, b);\n return newFraction(\n this[\"s\"] * P[\"s\"] * this[\"n\"] * P[\"d\"],\n this[\"d\"] * P[\"n\"]\n );\n },\n\n /**\n * Clones the actual object\n *\n * Ex: new Fraction(\"-17.(345)\").clone()\n **/\n \"clone\": function () {\n return newFraction(this['s'] * this['n'], this['d']);\n },\n\n /**\n * Calculates the modulo of two rational numbers - a more precise fmod\n *\n * Ex: new Fraction('4.(3)').mod([7, 8]) => (13/3) % (7/8) = (5/6)\n * Ex: new Fraction(20, 10).mod().equals(0) ? \"is Integer\"\n **/\n \"mod\": function (a, b) {\n\n if (a === undefined) {\n return newFraction(this[\"s\"] * this[\"n\"] % this[\"d\"], C_ONE);\n }\n\n parse(a, b);\n if (C_ZERO === P[\"n\"] * this[\"d\"]) {\n throw DivisionByZero();\n }\n\n /**\n * I derived the rational modulo similar to the modulo for integers\n *\n * https://raw.org/book/analysis/rational-numbers/\n *\n * n1/d1 = (n2/d2) * q + r, where 0 \u2264 r < n2/d2\n * => d2 * n1 = n2 * d1 * q + d1 * d2 * r\n * => r = (d2 * n1 - n2 * d1 * q) / (d1 * d2)\n * = (d2 * n1 - n2 * d1 * floor((d2 * n1) / (n2 * d1))) / (d1 * d2)\n * = ((d2 * n1) % (n2 * d1)) / (d1 * d2)\n */\n return newFraction(\n this[\"s\"] * (P[\"d\"] * this[\"n\"]) % (P[\"n\"] * this[\"d\"]),\n P[\"d\"] * this[\"d\"]);\n },\n\n /**\n * Calculates the fractional gcd of two rational numbers\n *\n * Ex: new Fraction(5,8).gcd(3,7) => 1/56\n */\n \"gcd\": function (a, b) {\n\n parse(a, b);\n\n // https://raw.org/book/analysis/rational-numbers/\n // gcd(a / b, c / d) = gcd(a, c) / lcm(b, d)\n\n return newFraction(gcd(P[\"n\"], this[\"n\"]) * gcd(P[\"d\"], this[\"d\"]), P[\"d\"] * this[\"d\"]);\n },\n\n /**\n * Calculates the fractional lcm of two rational numbers\n *\n * Ex: new Fraction(5,8).lcm(3,7) => 15\n */\n \"lcm\": function (a, b) {\n\n parse(a, b);\n\n // https://raw.org/book/analysis/rational-numbers/\n // lcm(a / b, c / d) = lcm(a, c) / gcd(b, d)\n\n if (P[\"n\"] === C_ZERO && this[\"n\"] === C_ZERO) {\n return newFraction(C_ZERO, C_ONE);\n }\n return newFraction(P[\"n\"] * this[\"n\"], gcd(P[\"n\"], this[\"n\"]) * gcd(P[\"d\"], this[\"d\"]));\n },\n\n /**\n * Gets the inverse of the fraction, means numerator and denominator are exchanged\n *\n * Ex: new Fraction([-3, 4]).inverse() => -4 / 3\n **/\n \"inverse\": function () {\n return newFraction(this[\"s\"] * this[\"d\"], this[\"n\"]);\n },\n\n /**\n * Calculates the fraction to some integer exponent\n *\n * Ex: new Fraction(-1,2).pow(-3) => -8\n */\n \"pow\": function (a, b) {\n\n parse(a, b);\n\n // Trivial case when exp is an integer\n\n if (P['d'] === C_ONE) {\n\n if (P['s'] < C_ZERO) {\n return newFraction((this['s'] * this[\"d\"]) ** P['n'], this[\"n\"] ** P['n']);\n } else {\n return newFraction((this['s'] * this[\"n\"]) ** P['n'], this[\"d\"] ** P['n']);\n }\n }\n\n // Negative roots become complex\n // (-a/b)^(c/d) = x\n // \u21D4 (-1)^(c/d) * (a/b)^(c/d) = x\n // \u21D4 (cos(pi) + i*sin(pi))^(c/d) * (a/b)^(c/d) = x\n // \u21D4 (cos(c*pi/d) + i*sin(c*pi/d)) * (a/b)^(c/d) = x # DeMoivre's formula\n // From which follows that only for c=0 the root is non-complex\n if (this['s'] < C_ZERO) return null;\n\n // Now prime factor n and d\n let N = factorize(this['n']);\n let D = factorize(this['d']);\n\n // Exponentiate and take root for n and d individually\n let n = C_ONE;\n let d = C_ONE;\n for (let k in N) {\n if (k === '1') continue;\n if (k === '0') {\n n = C_ZERO;\n break;\n }\n N[k] *= P['n'];\n\n if (N[k] % P['d'] === C_ZERO) {\n N[k] /= P['d'];\n } else return null;\n n *= BigInt(k) ** N[k];\n }\n\n for (let k in D) {\n if (k === '1') continue;\n D[k] *= P['n'];\n\n if (D[k] % P['d'] === C_ZERO) {\n D[k] /= P['d'];\n } else return null;\n d *= BigInt(k) ** D[k];\n }\n\n if (P['s'] < C_ZERO) {\n return newFraction(d, n);\n }\n return newFraction(n, d);\n },\n\n /**\n * Calculates the logarithm of a fraction to a given rational base\n *\n * Ex: new Fraction(27, 8).log(9, 4) => 3/2\n */\n \"log\": function (a, b) {\n\n parse(a, b);\n\n if (this['s'] <= C_ZERO || P['s'] <= C_ZERO) return null;\n\n const allPrimes = {};\n\n const baseFactors = factorize(P['n']);\n const T1 = factorize(P['d']);\n\n const numberFactors = factorize(this['n']);\n const T2 = factorize(this['d']);\n\n for (const prime in T1) {\n baseFactors[prime] = (baseFactors[prime] || C_ZERO) - T1[prime];\n }\n for (const prime in T2) {\n numberFactors[prime] = (numberFactors[prime] || C_ZERO) - T2[prime];\n }\n\n for (const prime in baseFactors) {\n if (prime === '1') continue;\n allPrimes[prime] = true;\n }\n for (const prime in numberFactors) {\n if (prime === '1') continue;\n allPrimes[prime] = true;\n }\n\n let retN = null;\n let retD = null;\n\n // Iterate over all unique primes to determine if a consistent ratio exists\n for (const prime in allPrimes) {\n\n const baseExponent = baseFactors[prime] || C_ZERO;\n const numberExponent = numberFactors[prime] || C_ZERO;\n\n if (baseExponent === C_ZERO) {\n if (numberExponent !== C_ZERO) {\n return null; // Logarithm cannot be expressed as a rational number\n }\n continue; // Skip this prime since both exponents are zero\n }\n\n // Calculate the ratio of exponents for this prime\n let curN = numberExponent;\n let curD = baseExponent;\n\n // Simplify the current ratio\n const gcdValue = gcd(curN, curD);\n curN /= gcdValue;\n curD /= gcdValue;\n\n // Check if this is the first ratio; otherwise, ensure ratios are consistent\n if (retN === null && retD === null) {\n retN = curN;\n retD = curD;\n } else if (curN * retD !== retN * curD) {\n return null; // Ratios do not match, logarithm cannot be rational\n }\n }\n\n return retN !== null && retD !== null\n ? newFraction(retN, retD)\n : null;\n },\n\n /**\n * Check if two rational numbers are the same\n *\n * Ex: new Fraction(19.6).equals([98, 5]);\n **/\n \"equals\": function (a, b) {\n\n parse(a, b);\n return this[\"s\"] * this[\"n\"] * P[\"d\"] === P[\"s\"] * P[\"n\"] * this[\"d\"];\n },\n\n /**\n * Check if this rational number is less than another\n *\n * Ex: new Fraction(19.6).lt([98, 5]);\n **/\n \"lt\": function (a, b) {\n\n parse(a, b);\n return this[\"s\"] * this[\"n\"] * P[\"d\"] < P[\"s\"] * P[\"n\"] * this[\"d\"];\n },\n\n /**\n * Check if this rational number is less than or equal another\n *\n * Ex: new Fraction(19.6).lt([98, 5]);\n **/\n \"lte\": function (a, b) {\n\n parse(a, b);\n return this[\"s\"] * this[\"n\"] * P[\"d\"] <= P[\"s\"] * P[\"n\"] * this[\"d\"];\n },\n\n /**\n * Check if this rational number is greater than another\n *\n * Ex: new Fraction(19.6).lt([98, 5]);\n **/\n \"gt\": function (a, b) {\n\n parse(a, b);\n return this[\"s\"] * this[\"n\"] * P[\"d\"] > P[\"s\"] * P[\"n\"] * this[\"d\"];\n },\n\n /**\n * Check if this rational number is greater than or equal another\n *\n * Ex: new Fraction(19.6).lt([98, 5]);\n **/\n \"gte\": function (a, b) {\n\n parse(a, b);\n return this[\"s\"] * this[\"n\"] * P[\"d\"] >= P[\"s\"] * P[\"n\"] * this[\"d\"];\n },\n\n /**\n * Compare two rational numbers\n * < 0 iff this < that\n * > 0 iff this > that\n * = 0 iff this = that\n *\n * Ex: new Fraction(19.6).compare([98, 5]);\n **/\n \"compare\": function (a, b) {\n\n parse(a, b);\n let t = this[\"s\"] * this[\"n\"] * P[\"d\"] - P[\"s\"] * P[\"n\"] * this[\"d\"];\n\n return (C_ZERO < t) - (t < C_ZERO);\n },\n\n /**\n * Calculates the ceil of a rational number\n *\n * Ex: new Fraction('4.(3)').ceil() => (5 / 1)\n **/\n \"ceil\": function (places) {\n\n places = C_TEN ** BigInt(places || 0);\n\n return newFraction(trunc(this[\"s\"] * places * this[\"n\"] / this[\"d\"]) +\n (places * this[\"n\"] % this[\"d\"] > C_ZERO && this[\"s\"] >= C_ZERO ? C_ONE : C_ZERO),\n places);\n },\n\n /**\n * Calculates the floor of a rational number\n *\n * Ex: new Fraction('4.(3)').floor() => (4 / 1)\n **/\n \"floor\": function (places) {\n\n places = C_TEN ** BigInt(places || 0);\n\n return newFraction(trunc(this[\"s\"] * places * this[\"n\"] / this[\"d\"]) -\n (places * this[\"n\"] % this[\"d\"] > C_ZERO && this[\"s\"] < C_ZERO ? C_ONE : C_ZERO),\n places);\n },\n\n /**\n * Rounds a rational numbers\n *\n * Ex: new Fraction('4.(3)').round() => (4 / 1)\n **/\n \"round\": function (places) {\n\n places = C_TEN ** BigInt(places || 0);\n\n /* Derivation:\n\n s >= 0:\n round(n / d) = trunc(n / d) + (n % d) / d >= 0.5 ? 1 : 0\n = trunc(n / d) + 2(n % d) >= d ? 1 : 0\n s < 0:\n round(n / d) =-trunc(n / d) - (n % d) / d > 0.5 ? 1 : 0\n =-trunc(n / d) - 2(n % d) > d ? 1 : 0\n\n =>:\n\n round(s * n / d) = s * trunc(n / d) + s * (C + 2(n % d) > d ? 1 : 0)\n where C = s >= 0 ? 1 : 0, to fix the >= for the positve case.\n */\n\n return newFraction(trunc(this[\"s\"] * places * this[\"n\"] / this[\"d\"]) +\n this[\"s\"] * ((this[\"s\"] >= C_ZERO ? C_ONE : C_ZERO) + C_TWO * (places * this[\"n\"] % this[\"d\"]) > this[\"d\"] ? C_ONE : C_ZERO),\n places);\n },\n\n /**\n * Rounds a rational number to a multiple of another rational number\n *\n * Ex: new Fraction('0.9').roundTo(\"1/8\") => 7 / 8\n **/\n \"roundTo\": function (a, b) {\n\n /*\n k * x/y \u2264 a/b < (k+1) * x/y\n \u21D4 k \u2264 a/b / (x/y) < (k+1)\n \u21D4 k = floor(a/b * y/x)\n \u21D4 k = floor((a * y) / (b * x))\n */\n\n parse(a, b);\n\n const n = this['n'] * P['d'];\n const d = this['d'] * P['n'];\n const r = n % d;\n\n // round(n / d) = trunc(n / d) + 2(n % d) >= d ? 1 : 0\n let k = trunc(n / d);\n if (r + r >= d) {\n k++;\n }\n return newFraction(this['s'] * k * P['n'], P['d']);\n },\n\n /**\n * Check if two rational numbers are divisible\n *\n * Ex: new Fraction(19.6).divisible(1.5);\n */\n \"divisible\": function (a, b) {\n\n parse(a, b);\n return !(!(P[\"n\"] * this[\"d\"]) || ((this[\"n\"] * P[\"d\"]) % (P[\"n\"] * this[\"d\"])));\n },\n\n /**\n * Returns a decimal representation of the fraction\n *\n * Ex: new Fraction(\"100.'91823'\").valueOf() => 100.91823918239183\n **/\n 'valueOf': function () {\n // Best we can do so far\n return Number(this[\"s\"] * this[\"n\"]) / Number(this[\"d\"]);\n },\n\n /**\n * Creates a string representation of a fraction with all digits\n *\n * Ex: new Fraction(\"100.'91823'\").toString() => \"100.(91823)\"\n **/\n 'toString': function (dec) {\n\n let N = this[\"n\"];\n let D = this[\"d\"];\n\n dec = dec || 15; // 15 = decimal places when no repetition\n\n let cycLen = cycleLen(N, D); // Cycle length\n let cycOff = cycleStart(N, D, cycLen); // Cycle start\n\n let str = this['s'] < C_ZERO ? \"-\" : \"\";\n\n // Append integer part\n str += trunc(N / D);\n\n N %= D;\n N *= C_TEN;\n\n if (N)\n str += \".\";\n\n if (cycLen) {\n\n for (let i = cycOff; i--;) {\n str += trunc(N / D);\n N %= D;\n N *= C_TEN;\n }\n str += \"(\";\n for (let i = cycLen; i--;) {\n str += trunc(N / D);\n N %= D;\n N *= C_TEN;\n }\n str += \")\";\n } else {\n for (let i = dec; N && i--;) {\n str += trunc(N / D);\n N %= D;\n N *= C_TEN;\n }\n }\n return str;\n },\n\n /**\n * Returns a string-fraction representation of a Fraction object\n *\n * Ex: new Fraction(\"1.'3'\").toFraction() => \"4 1/3\"\n **/\n 'toFraction': function (showMixed) {\n\n let n = this[\"n\"];\n let d = this[\"d\"];\n let str = this['s'] < C_ZERO ? \"-\" : \"\";\n\n if (d === C_ONE) {\n str += n;\n } else {\n let whole = trunc(n / d);\n if (showMixed && whole > C_ZERO) {\n str += whole;\n str += \" \";\n n %= d;\n }\n\n str += n;\n str += '/';\n str += d;\n }\n return str;\n },\n\n /**\n * Returns a latex representation of a Fraction object\n *\n * Ex: new Fraction(\"1.'3'\").toLatex() => \"\\frac{4}{3}\"\n **/\n 'toLatex': function (showMixed) {\n\n let n = this[\"n\"];\n let d = this[\"d\"];\n let str = this['s'] < C_ZERO ? \"-\" : \"\";\n\n if (d === C_ONE) {\n str += n;\n } else {\n let whole = trunc(n / d);\n if (showMixed && whole > C_ZERO) {\n str += whole;\n n %= d;\n }\n\n str += \"\\\\frac{\";\n str += n;\n str += '}{';\n str += d;\n str += '}';\n }\n return str;\n },\n\n /**\n * Returns an array of continued fraction elements\n *\n * Ex: new Fraction(\"7/8\").toContinued() => [0,1,7]\n */\n 'toContinued': function () {\n\n let a = this['n'];\n let b = this['d'];\n let res = [];\n\n do {\n res.push(trunc(a / b));\n let t = a % b;\n a = b;\n b = t;\n } while (a !== C_ONE);\n\n return res;\n },\n\n \"simplify\": function (eps) {\n\n const ieps = BigInt(1 / (eps || 0.001) | 0);\n\n const thisABS = this['abs']();\n const cont = thisABS['toContinued']();\n\n for (let i = 1; i < cont.length; i++) {\n\n let s = newFraction(cont[i - 1], C_ONE);\n for (let k = i - 2; k >= 0; k--) {\n s = s['inverse']()['add'](cont[k]);\n }\n\n let t = s['sub'](thisABS);\n if (t['n'] * ieps < t['d']) { // More robust than Math.abs(t.valueOf()) < eps\n return s['mul'](this['s']);\n }\n }\n return this;\n }\n};\nexport {\n Fraction as default, Fraction\n};\n", "/**\n * @license ContinuedFraction.js v0.1.0\n * https://github.com/rawify/ContinuedFraction.js\n *\n * Copyright (c) 2026, Robert Eisele (https://raw.org/)\n * Licensed under the MIT license.\n **/\n\nimport FractionFactory, { type Fraction as FractionValue } from 'fraction.js';\n\n/** A value accepted by Fraction.js as a continued-fraction coefficient. */\nexport type Coefficient = number | string | bigint | FractionValue;\n\nconst Fraction = FractionFactory as unknown as (value: Coefficient) => FractionValue;\n\n/** A term of a generalized continued fraction. */\nexport interface CFTerm {\n /** The a_n coefficient. */\n a: Coefficient;\n /** The b_n coefficient. */\n b: Coefficient;\n}\n\n/** A simple or generalized continued-fraction term. */\nexport type ContinuedFractionTerm = Coefficient | CFTerm;\n\n/** A term iterator or a function that creates one. */\nexport type ContinuedFractionSource<T = ContinuedFractionTerm> = Iterator<T> | (() => Iterator<T>);\n\nfunction iteratorFrom<T>(source: ContinuedFractionSource<T>): Iterator<T> {\n return typeof source === 'function' ? source() : source;\n}\n\nfunction coefficientOf(term: ContinuedFractionTerm): Coefficient {\n return typeof term === 'object' && term !== null && 'a' in term ? term.a : term;\n}\n\nfunction numeratorOf(term: ContinuedFractionTerm): Coefficient {\n return typeof term === 'object' && term !== null && 'b' in term ? term.b : 1;\n}\n\nfunction validateSteps(steps: number): void {\n if (!Number.isSafeInteger(steps) || steps < 0) {\n throw new RangeError('steps must be a non-negative safe integer');\n }\n}\n\n/**\n * Utility class for generating and evaluating continued fractions.\n * All methods are static; the class cannot be instantiated.\n */\nexport class ContinuedFraction {\n private constructor() {\n throw new TypeError('ContinuedFraction is a static class');\n }\n\n /**\n * Infinite generator for the continued-fraction terms of sqrt(N).\n * sqrt(N) = [a0; (a1, a2, ..., a_p)], with a period boundary at ak = 2*a0.\n * For perfect squares, yields only a0 = floor(sqrt(N)) and then returns.\n *\n * @param N Integer whose square-root CF expansion is desired (N >= 0).\n * @yields Next continued-fraction term of sqrt(N).\n */\n static *sqrt(N: number): Generator<number, void, unknown> {\n if (!Number.isSafeInteger(N) || N < 0) {\n throw new RangeError('N must be a non-negative safe integer');\n }\n\n const a0 = Math.floor(Math.sqrt(N));\n yield a0;\n if (a0 * a0 === N) return; // perfect square: single-term CF\n\n let nk = 0;\n let dk = 1;\n let ak = a0;\n\n while (true) {\n nk = ak * dk - nk;\n dk = (N - nk * nk) / dk; // remains integer by construction\n ak = Math.floor((a0 + nk) / dk);\n yield ak;\n }\n }\n\n /**\n * Generator for continued-fraction terms of any real number via Fraction.js.\n *\n * @param n The real number to convert (as number, string, or bigint).\n * @yields Next continued-fraction term of n.\n */\n static *fromNumber(n: Coefficient): Generator<bigint, void, unknown> {\n yield* Fraction(n).toContinued();\n }\n\n /**\n * Generator for continued-fraction terms of a rational a/b via Fraction.js.\n *\n * @param a Numerator, Fraction, or complete fraction string.\n * @param b Optional denominator.\n * @yields Next continued-fraction term of a/b.\n */\n static *fromFraction(a: Coefficient, b?: Coefficient): Generator<bigint, void, unknown> {\n const fraction = b === undefined ? Fraction(a) : Fraction(a).div(Fraction(b));\n yield* fraction.toContinued();\n }\n\n /**\n * Yields a finite sequence of simple or generalized terms unchanged.\n *\n * @param terms Continued-fraction terms.\n * @yields Each supplied term in order.\n */\n static *fromTerms<T extends ContinuedFractionTerm>(terms: Iterable<T>): Generator<T, void, unknown> {\n yield* terms;\n }\n\n /**\n * Infinite generator of the golden ratio phi = [1; 1, 1, 1, ...].\n *\n * @yields Always 1.\n */\n static *PHI(): Generator<number, never, unknown> {\n while (true) {\n yield 1;\n }\n }\n\n /**\n * Infinite generator for Brouncker's generalized continued fraction of 4/pi:\n * 4/pi = 1 + 1^2/(2 + 3^2/(2 + 5^2/(2 + ...)))\n *\n * @yields Term pair (a_n, b_n) of the generalized continued fraction.\n * - first: a_0 = 1\n * - then: a_n = 2, b_n = (2n-1)^2 (n >= 1)\n */\n static *FOUR_OVER_PI(): Generator<CFTerm, never, unknown> {\n yield { a: 1, b: 0 }; // a_0 = 1\n\n for (let n = 1; true; n++) {\n yield { a: 2, b: (n * 2 - 1) ** 2 };\n }\n }\n\n /**\n * Infinite generator for a generalized continued fraction of pi:\n * pi = 3 + 1^2/(6 + 3^2/(6 + 5^2/(6 + ...)))\n *\n * @yields Term pair (a_n, b_n) of the generalized continued fraction.\n * - first: a_0 = 3\n * - then: a_n = 6, b_n = (2n-1)^2 (n >= 1)\n */\n static *PI(): Generator<CFTerm, never, unknown> {\n yield { a: 3, b: 0 }; // a_0 = 3\n\n for (let n = 1; true; n++) {\n yield { a: 6, b: (n * 2 - 1) ** 2 };\n }\n }\n\n /**\n * Infinite generator of e = [2; 1, 2, 1, 1, 4, 1, ...].\n * Terms follow the pattern [2; (1, 2m, 1) for m = 1, 2, 3, ...].\n *\n * @yields Next continued-fraction term of e.\n */\n static *E(): Generator<number, never, unknown> {\n yield 2; // a_0 = 2\n\n for (let m = 1; true; m++) {\n yield 1;\n yield 2 * m;\n yield 1;\n }\n }\n\n /**\n * Collects at most `steps` terms from a continued fraction.\n *\n * @param source Continued-fraction term iterator or a function returning one.\n * @param steps Maximum number of terms to collect.\n * @returns Collected terms in source order.\n */\n static toArray<T>(source: ContinuedFractionSource<T>, steps = 10): T[] {\n validateSteps(steps);\n\n const iterator = iteratorFrom(source);\n const terms: T[] = [];\n\n while (terms.length < steps) {\n const result = iterator.next();\n if (result.done) break;\n terms.push(result.value);\n }\n\n return terms;\n }\n\n /**\n * Generates every convergent of a simple or generalized continued fraction.\n *\n * @param source Continued-fraction term iterator or a function returning one.\n * @yields Exact convergents as Fraction instances.\n */\n static *convergents(source: ContinuedFractionSource): Generator<FractionValue, void, unknown> {\n const iterator = iteratorFrom(source);\n const first = iterator.next();\n if (first.done) return;\n\n let currentNumerator = Fraction(coefficientOf(first.value));\n let currentDenominator = Fraction(1);\n let previousNumerator = Fraction(1);\n let previousDenominator = Fraction(0);\n\n yield currentNumerator.div(currentDenominator);\n\n while (true) {\n const result = iterator.next();\n if (result.done) return;\n\n const coefficient = Fraction(coefficientOf(result.value));\n const numerator = Fraction(numeratorOf(result.value));\n\n [previousNumerator, currentNumerator] = [\n currentNumerator,\n coefficient.mul(currentNumerator).add(numerator.mul(previousNumerator))];\n [previousDenominator, currentDenominator] = [\n currentDenominator,\n coefficient.mul(currentDenominator).add(numerator.mul(previousDenominator))];\n\n yield currentNumerator.div(currentDenominator);\n }\n }\n\n /**\n * Evaluates a simple or generalized continued fraction generator.\n * For generalized fractions terms are objects `{ a, b }`; otherwise they are coefficients.\n *\n * @param source Continued-fraction term iterator or a function returning one.\n * @param steps Number of terms to evaluate.\n * @returns Rational approximation as Fraction.\n */\n static eval(source: ContinuedFractionSource, steps = 10): FractionValue {\n validateSteps(steps);\n if (steps === 0) return Fraction(0);\n\n let approximation = Fraction(0);\n let count = 0;\n\n for (const convergent of ContinuedFraction.convergents(source)) {\n approximation = convergent;\n count++;\n if (count === steps) break;\n }\n\n return approximation;\n }\n}\n\nexport default ContinuedFraction;"],
5
+ "mappings": ";AAgCA,IAAI,OAAO,WAAW,YAAa,UAAS,SAAU,GAAG;AAAE,MAAI,MAAM,CAAC,EAAG,OAAM,IAAI,MAAM,EAAE;AAAG,SAAO;AAAG;AAExG,IAAM,SAAS,OAAO,CAAC;AACvB,IAAM,QAAQ,OAAO,CAAC;AACtB,IAAM,QAAQ,OAAO,CAAC;AACtB,IAAM,SAAS,OAAO,CAAC;AACvB,IAAM,QAAQ,OAAO,EAAE;AAKvB,IAAM,gBAAgB;AAGtB,IAAM,IAAI;AAAA,EACR,KAAK;AAAA,EACL,KAAK;AAAA,EACL,K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,UAAS,CAAC;AAElC,QAAI,gBAAgBA,UAAS,CAAC;AAC9B,QAAI,QAAQ;AAEZ,eAAW,cAAc,mBAAkB,YAAY,MAAM,GAAG;AAC5D,sBAAgB;AAChB;AACA,UAAI,UAAU,MAAO;AAAA,IACzB;AAEA,WAAO;AAAA,EACX;AACJ;AAEA,IAAO,4BAAQ;",
6
+ "names": ["Fraction"]
7
+ }
package/package.json CHANGED
@@ -1,33 +1,51 @@
1
1
  {
2
2
  "name": "continuedfraction.js",
3
- "title": "ContinuedFraction.js",
4
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
+ "type": "commonjs",
5
+ "description": "Generator-based simple and generalized continued fractions with exact Fraction.js convergents",
5
6
  "homepage": "https://github.com/rawify/ContinuedFraction.js",
6
7
  "bugs": "https://github.com/rawify/ContinuedFraction.js/issues",
7
- "description": "The RAW continued fractions library",
8
8
  "keywords": [
9
9
  "math",
10
- "continued fraction",
10
+ "continued-fraction",
11
+ "convergents",
11
12
  "fraction",
12
- "bigint"
13
+ "bigint",
14
+ "rational-approximation",
15
+ "square-root",
16
+ "generator"
17
+ ],
18
+ "files": [
19
+ "dist",
20
+ "README.md",
21
+ "LICENSE"
13
22
  ],
14
- "private": false,
15
23
  "main": "./dist/continuedfraction.js",
16
24
  "module": "./dist/continuedfraction.mjs",
17
- "types": "./continuedfraction.d.ts",
18
- "browser": "./dist/continuedfraction.min.js",
19
25
  "unpkg": "./dist/continuedfraction.min.js",
20
- "readmeFilename": "README.md",
26
+ "jsdelivr": "./dist/continuedfraction.min.js",
27
+ "types": "./dist/continuedfraction.d.ts",
21
28
  "exports": {
22
29
  ".": {
23
- "types": "./continuedfraction.d.ts",
24
- "require": "./dist/continuedfraction.js",
25
- "import": "./dist/continuedfraction.mjs"
26
- }
30
+ "import": {
31
+ "types": "./dist/continuedfraction.d.mts",
32
+ "default": "./dist/continuedfraction.mjs"
33
+ },
34
+ "require": {
35
+ "types": "./dist/continuedfraction.d.ts",
36
+ "default": "./dist/continuedfraction.js"
37
+ },
38
+ "default": {
39
+ "types": "./dist/continuedfraction.d.ts",
40
+ "default": "./dist/continuedfraction.js"
41
+ }
42
+ },
43
+ "./package.json": "./package.json"
27
44
  },
45
+ "sideEffects": false,
28
46
  "repository": {
29
47
  "type": "git",
30
- "url": "git@github.com:rawify/ContinuedFraction.js.git"
48
+ "url": "git+ssh://git@github.com/rawify/ContinuedFraction.js.git"
31
49
  },
32
50
  "funding": {
33
51
  "type": "github",
@@ -40,18 +58,22 @@
40
58
  },
41
59
  "license": "MIT",
42
60
  "engines": {
43
- "node": "*"
44
- },
45
- "directories": {
46
- "test": "tests"
61
+ "node": ">=20"
47
62
  },
48
63
  "scripts": {
49
- "build": "crude-build ContinuedFraction",
50
- "test": "mocha tests/*.js"
64
+ "clean": "node scripts/clean.mjs",
65
+ "typecheck": "tsc --noEmit",
66
+ "build:types": "tsc -p tsconfig.build.json",
67
+ "build:js": "node scripts/build.mjs",
68
+ "build": "npm run clean && npm run build:types && npm run build:js",
69
+ "test:types": "tsc -p tests/types/tsconfig.json",
70
+ "test:runtime": "node --test tests/*.test.js tests/*.test.mjs",
71
+ "test": "npm run build && npm run test:types && npm run test:runtime",
72
+ "prepublishOnly": "npm test"
51
73
  },
52
74
  "devDependencies": {
53
- "crude-build": "^0.1.0",
54
- "mocha": "^11.1.0"
75
+ "esbuild": "^0.25.9",
76
+ "typescript": "^5.9.2"
55
77
  },
56
78
  "dependencies": {
57
79
  "fraction.js": "^5.2.2"
@@ -1,80 +0,0 @@
1
-
2
- import type Fraction from 'fraction.js';
3
-
4
- /**
5
- * A term of a generalized continued fraction.
6
- */
7
- export interface CFTerm {
8
- /** The aₙ coefficient */
9
- a: number;
10
- /** The bₙ coefficient */
11
- b: number;
12
- }
13
-
14
- /**
15
- * Utility class for generating continued-fraction expansions of various constants.
16
- * All methods are static.
17
- */
18
- export default class ContinuedFraction {
19
- /**
20
- * Infinite generator for the continued‐fraction terms of √N.
21
- * @param N Integer whose square‐root CF expansion is desired (N ≥ 0)
22
- * @yields Next continued‐fraction term of √N
23
- */
24
- static sqrt(N: number): Generator<number, void, unknown>;
25
-
26
- /**
27
- * Generator for continued‐fraction terms of any real number via Fraction.js.
28
- * @param n The real number to convert (as number, string, or bigint)
29
- * @yields Next continued‐fraction term of n
30
- */
31
- static fromNumber(n: number | string | bigint): Generator<number, void, unknown>;
32
-
33
- /**
34
- * Generator for continued‐fraction terms of a rational a/b via Fraction.js.
35
- * @param a Numerator (number, string, bigint, or Fraction)
36
- * @param b Denominator (number, string, or bigint)
37
- * @yields Next continued‐fraction term of a/b
38
- */
39
- static fromFraction(
40
- a: number | string | bigint | Fraction,
41
- b: number | string | bigint
42
- ): Generator<number, void, unknown>;
43
-
44
- /**
45
- * Infinite generator of the golden ratio φ = [1; 1, 1, 1, …].
46
- * @yields Always 1
47
- */
48
- static PHI(): Generator<number, void, unknown>;
49
-
50
- /**
51
- * Infinite generator for the generalized continued‐fraction terms of 4/π.
52
- * @yields Term pairs { a, b } for the continued‐fraction
53
- */
54
- static FOUR_OVER_PI(): Generator<CFTerm, void, unknown>;
55
-
56
- /**
57
- * Infinite generator for the generalized continued‐fraction terms of π.
58
- * @yields Term pairs { a, b } for the continued‐fraction
59
- */
60
- static PI(): Generator<CFTerm, void, unknown>;
61
-
62
- /**
63
- * Infinite generator of e = [2; 1, 2, 1, 1, 4, 1, …].
64
- * @yields Next continued‐fraction term of e
65
- */
66
- static E(): Generator<number, void, unknown>;
67
-
68
- /**
69
- * Evaluate a (simple or generalized) continued fraction generator.
70
- * @param generator A CF term generator or a function returning one
71
- * @param steps Number of terms to include (default 10)
72
- * @returns Rational approximation as a Fraction
73
- */
74
- static eval(
75
- generator:
76
- | Generator<number | CFTerm, any, any>
77
- | (() => Generator<number | CFTerm, any, any>),
78
- steps?: number
79
- ): Fraction;
80
- }
@@ -1,179 +0,0 @@
1
- /**
2
- * @license ContinuedFraction.js v0.0.1 4/18/2025
3
- * https://github.com/rawify/ContinuedFraction.js
4
- *
5
- * Copyright (c) 2025, Robert Eisele (https://raw.org/)
6
- * Licensed under the MIT license.
7
- **/
8
-
9
- import Fraction from 'fraction.js';
10
-
11
- /**
12
- * Utility class for generating continued-fraction expansions of various constants.
13
- */
14
- const ContinuedFraction = {
15
-
16
- /**
17
- * Infinite generator for the continued-fraction terms of sqrt(N).
18
- * √N = [a0; (a1, a2, ..., a_p)], where the period ends when ak = 2*a0.
19
- * For perfect squares, yields only a0 = floor(sqrt(N)) and then returns.
20
- *
21
- * @param {number} N - Integer whose square root CF expansion is desired (N ≥ 0).
22
- * @yields {number} - Next continued-fraction term of √N.
23
- */
24
- "sqrt": function* (N) {
25
-
26
- const a0 = Math.floor(Math.sqrt(N));
27
- yield a0;
28
- if (a0 * a0 === N) return; // perfect square: single-term CF
29
-
30
- //while (true) {
31
- let nk = 0;
32
- let dk = 1;
33
- let ak = a0;
34
-
35
- do {
36
- nk = ak * dk - nk;
37
- dk = (N - nk * nk) / dk; // remains integer by construction
38
- ak = Math.floor((a0 + nk) / dk);
39
- yield ak;
40
- } while (/* 2 * a0 !== ak */ true);
41
- //}
42
- },
43
-
44
- /**
45
- * Generator for continued-fraction terms of any real number via Fraction.js.
46
- *
47
- * @exports
48
- * @param {number|string|BigInt} n - The real number to convert (as number or string).
49
- * @yields {number} - Next continued-fraction term of n.
50
- */
51
- "fromNumber": function* (n) {
52
-
53
- yield* Fraction(n)['toContinued']();
54
- },
55
-
56
- /**
57
- * Generator for continued-fraction terms of a rational a/b via Fraction.js.
58
- *
59
- * @param {number|string|BigInt|Fraction} a - Numerator.
60
- * @param {number|string|BigInt} b - Denominator.
61
- * @yields {number} - Next continued-fraction term of a/b.
62
- */
63
- "fromFraction": function* (a, b) {
64
-
65
- yield* Fraction(a, b)['toContinued']();
66
- },
67
-
68
- /**
69
- * Infinite generator of the golden ratio φ = [1; 1, 1, 1, …].
70
- *
71
- * @yields {number} - Always 1.
72
- */
73
- "PHI": function* () {
74
-
75
- while (true) {
76
- yield 1;
77
- }
78
- },
79
-
80
- /**
81
- * Infinite generator for Continued‐fraction terms of 4/π:
82
- * 4/π = 1 + 1²/(3 + 2²/(5 + 3²/(7 + …)))
83
- * @yields {{a:number,b:number}} - Term pair (aₙ, bₙ) of the generalized continued fraction.
84
- * - first: a₀ = 1
85
- * - then: aₙ = 2n+1, bₙ = n² (n ≥ 1)
86
- */
87
- "FOUR_OVER_PI": function* () {
88
-
89
- yield { "a": 1, "b": 0 }; // a₀ = 1
90
-
91
- for (let n = 0; true; n++) {
92
- yield { "a": 2, "b": (n * 2 + 1) ** 2 };
93
- }
94
- },
95
-
96
- /**
97
- * Infinite generator for Continued‐fraction terms of π:
98
- * π = 3 + 1²/(6 + 3²/(6 + 5²/(6 + …)))
99
- * @yields {{a:number,b:number}} - Term pair (aₙ, bₙ) of the generalized continued fraction.
100
- * - first: a₀ = 3
101
- * - then: aₙ = 6, bₙ = (2n-1)² (n ≥ 1)
102
- */
103
- "PI": function* () {
104
-
105
- yield { "a": 3, "b": 0 }; // a₀ = 3
106
-
107
- for (let n = 1; true; n++) {
108
- yield { "a": 6, "b": (n * 2 - 1) ** 2 };
109
- }
110
- },
111
-
112
- /**
113
- * Infinite generator of e = [2; 1, 2, 1, 1, 4, 1, …].
114
- * Terms follow the pattern [2; (1,2m,1) for m = 1,2,3,…].
115
- *
116
- * @yields {number} - Next continued-fraction term of e.
117
- */
118
- "E": function* () {
119
-
120
- yield 2; // a₀ = 2
121
-
122
- for (let m = 1; ; m++) {
123
- yield 1;
124
- yield 2 * m;
125
- yield 1;
126
- }
127
-
128
- /* Alternative:
129
- yield { a: 2, b: 0 }; // a₀ = 2
130
- yield { a: 1, b: 1 }; // a₁ = 1
131
-
132
- for (let m = 2; ; m++) {
133
- yield { a: n, b: m - 1 };
134
- }
135
- */
136
- },
137
-
138
- /**
139
- * Evaluate a (simple or generalized) continued fraction generator.
140
- * For generalized: terms are objects { a, b }, else regular numbers.
141
- *
142
- * @param {Generator|Function} generator - Continued fraction term generator.
143
- * @param {number} steps - Number of terms to evaluate.
144
- * @returns {Fraction} - Rational approximation as Fraction.
145
- */
146
- "eval": function (generator, steps = 10) {
147
-
148
- if (typeof generator === "function") {
149
- generator = generator();
150
- }
151
-
152
- // pull off a₀ (with its b₀)
153
- const first = generator['next']();
154
- if (first['done']) return Fraction(0);
155
-
156
- const a0 = Fraction(first['value']['a'] ?? first['value']);
157
-
158
- // initialize convergents p₋₁/q₋₁ = 1/0, p₀/q₀ = a₀/1
159
- let pCurr = a0, qCurr = Fraction(1);
160
- let pPrev = Fraction(1), qPrev = Fraction(0);
161
-
162
- // run through a₁… up to `steps-1` more
163
- for (let k = 1; k < steps; k++) {
164
- const { value, done } = generator['next']();
165
- if (done) break;
166
-
167
- const ak = Fraction(value['a'] ?? value),
168
- bk = Fraction(value['b'] ?? 1);
169
-
170
- // pₖ = aₖ·pₖ₋₁ + bₖ·pₖ₋₂
171
- // qₖ = aₖ·qₖ₋₁ + bₖ·qₖ₋₂
172
- [pPrev, pCurr] = [pCurr, ak['mul'](pCurr)['add'](bk['mul'](pPrev))];
173
- [qPrev, qCurr] = [qCurr, ak['mul'](qCurr)['add'](bk['mul'](qPrev))];
174
- }
175
-
176
- // final convergent = pCurr/qCurr
177
- return pCurr['div'](qCurr);
178
- }
179
- }
@@ -1,50 +0,0 @@
1
-
2
- const ContinuedFraction = require("continuedfraction.js");
3
- const assert = require('assert');
4
-
5
- function get(gen, num = 10) {
6
-
7
- const res = [];
8
- for (let i = 0; i < num; i++) {
9
- let x = gen.next();
10
- if (x.done) break;
11
- res.push(x.value);
12
- }
13
- return res;
14
- }
15
-
16
- const tests = [
17
-
18
- { label: "sqrt(2)", generator: ContinuedFraction.sqrt(2), expect: [1, 2, 2, 2, 2, 2, 2, 2, 2, 2] },
19
- { label: "sqrt(3)", generator: ContinuedFraction.sqrt(3), expect: [1, 1, 2, 1, 2, 1, 2, 1, 2, 1] },
20
- { label: "sqrt(5)", generator: ContinuedFraction.sqrt(5), expect: [2, 4, 4, 4, 4, 4, 4, 4, 4, 4] },
21
- { label: "sqrt(7)", generator: ContinuedFraction.sqrt(7), expect: [2, 1, 1, 1, 4, 1, 1, 1, 4, 1] },
22
-
23
- { label: "fromNumber(23.43)", generator: ContinuedFraction.fromNumber(23.43), expect: [23, 2, 3, 14] },
24
- { label: "fromNumber(77)", generator: ContinuedFraction.fromNumber(77), expect: [77] },
25
-
26
- { label: "PHI", generator: ContinuedFraction.PHI(), expect: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] },
27
- { label: "PI", generator: ContinuedFraction.PI(), expect: [{ a: 3, b: 0 }, { a: 6, b: 1 }, { a: 6, b: 9 }, { a: 6, b: 25 }, { a: 6, b: 49 }, { a: 6, b: 81 }, { a: 6, b: 121 },{ a: 6, b: 169 },{ a: 6, b: 225 },{ a: 6, b: 289 }] },
28
- { label: "FOUR_OVER_PI", generator: ContinuedFraction.FOUR_OVER_PI(), expect: [{ a: 1, b: 0 }, { a: 2, b: 1 }, { a: 2, b: 9 }, { a: 2, b: 25 }, { a: 2, b: 49 }, { a: 2, b: 81 }, { a: 2, b: 121 },{ a: 2, b: 169 },{ a: 2, b: 225 },{ a: 2, b: 289 }] },
29
- { label: "E", generator: ContinuedFraction.E(), expect: [2, 1, 2, 1, 1, 4, 1, 1, 6, 1] },
30
-
31
- { label: "eval(Fraction(271/13))", input: ContinuedFraction.eval(ContinuedFraction.fromFraction("271/13"), 10).toFraction(), expect: "271/13" },
32
- { label: "eval(PHI)", input: ContinuedFraction.eval(ContinuedFraction.PHI, 21).toFraction(), expect: "17711/10946" }
33
- ];
34
-
35
- describe('Continued Fraction', function () {
36
-
37
- for (var i = 0; i < tests.length; i++) {
38
-
39
- (function (test) {
40
-
41
- it(test.label, function () {
42
- if (test.generator)
43
- assert.deepEqual(get(test.generator, 10), test.expect);
44
- else
45
- assert.deepEqual(test.input, test.expect);
46
- });
47
-
48
- })(tests[i]);
49
- }
50
- });