v1.0 with SW PWA enabled

This commit is contained in:
Blomios
2026-01-01 17:40:53 +01:00
parent 1c0e22aac1
commit 3c8bebb2ad
29775 changed files with 2197201 additions and 119080 deletions

38
frontend/node_modules/fraction.js/CHANGELOG.md generated vendored Normal file
View File

@ -0,0 +1,38 @@
# CHANGELOG
v5.2.2
- Improved documentation and removed unecessary check
v5.2.1:
- 2bb7b05: Added negative sign check
v5.2:
- 6f9d124: Implemented log and improved simplify
- b773e7a: Added named export to TS definition
- 70304f9: Fixed merge conflict
- 3b940d3: Implemented other comparing functions
- 10acdfc: Update README.md
- ba41d00: Update README.md
- 73ded97: Update README.md
- acabc39: Fixed param parsing
v5.0.5:
- 2c9d4c2: Improved roundTo() and param parser
v5.0.4:
- 39e61e7: Fixed bignum param passing
v5.0.3:
- 7d9a3ec: Upgraded bundler for code quality
v5.0.2:
- c64b1d6: fixed esm export
v5.0.1:
- e440f9c: Fixed CJS export
- 9bbdd29: Fixed CJS export
v5.0.0:
- ac7cd06: Fixed readme
- 33cc9e5: Added crude build
- 1adcc76: Release breaking v5.0. Fraction.js now builds on BigInt. The API stays the same as v4, except that the object attributes `n`, `d`, and `s`, are not Number but BigInt and may break code that directly accesses these attributes.

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2023 Robert Eisele
Copyright (c) 2025 Robert Eisele
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -3,87 +3,102 @@
[![NPM Package](https://img.shields.io/npm/v/fraction.js.svg?style=flat)](https://npmjs.org/package/fraction.js "View this project on npm")
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
Tired of inprecise numbers represented by doubles, which have to store rational and irrational numbers like PI or sqrt(2) the same way? Obviously the following problem is preventable:
Do you find the limitations of floating-point arithmetic frustrating, especially when rational and irrational numbers like π or √2 are stored within the same finite precision? This can lead to avoidable inaccuracies such as:
```javascript
1 / 98 * 98 // = 0.9999999999999999
1 / 98 * 98 // Results in 0.9999999999999999
```
If you need more precision or just want a fraction as a result, just include *Fraction.js*:
For applications requiring higher precision or where working with fractions is preferable, consider incorporating *Fraction.js* into your project.
The library effectively addresses precision issues, as demonstrated below:
```javascript
var Fraction = require('fraction.js');
// or
import Fraction from 'fraction.js';
Fraction(1).div(98).mul(98) // Returns 1
```
and give it a trial:
*Fraction.js* uses a `BigInt` representation for both the numerator and denominator, ensuring minimal performance overhead while maximizing accuracy. Its design is optimized for precision, making it an ideal choice as a foundational library for other math tools, such as [Polynomial.js](https://github.com/rawify/Polynomial.js) and [Math.js](https://github.com/josdejong/mathjs).
## Convert Decimal to Fraction
One of the core features of *Fraction.js* is its ability to seamlessly convert decimal numbers into fractions.
```javascript
Fraction(1).div(98).mul(98) // = 1
let x = new Fraction(1.88);
let res = x.toFraction(true); // Returns "1 22/25" as a string
```
Internally, numbers are represented as *numerator / denominator*, which adds just a little overhead. However, the library is written with performance and accuracy in mind, which makes it the perfect basis for [Polynomial.js](https://github.com/infusion/Polynomial.js) and [Math.js](https://github.com/josdejong/mathjs).
This is particularly useful when you need precise fraction representations instead of dealing with the limitations of floating-point arithmetic. What if you allow some error tolerance?
Convert decimal to fraction
===
The simplest job for fraction.js is to get a fraction out of a decimal:
```javascript
var x = new Fraction(1.88);
var res = x.toFraction(true); // String "1 22/25"
let x = new Fraction(0.33333);
let res = x.simplify(0.001) // Error < 0.001
.toFraction(); // Returns "1/3" as a string
```
Examples / Motivation
===
A simple example might be
## Precision
As native `BigInt` support in JavaScript becomes more common, libraries like *Fraction.js* use it to handle calculations with higher precision. This improves the speed and accuracy of math operations with large numbers, providing a better solution for tasks that need more precision than floating-point numbers can offer.
## Examples / Motivation
A simple example of using *Fraction.js* might look like this:
```javascript
var f = new Fraction("9.4'31'"); // 9.4313131313131...
f.mul([-4, 3]).mod("4.'8'"); // 4.88888888888888...
```
The result is
The result can then be displayed as:
```javascript
console.log(f.toFraction()); // -4154 / 1485
```
You could of course also access the sign (s), numerator (n) and denominator (d) on your own:
Additionally, you can access the internal attributes of the fraction, such as the sign (s), numerator (n), and denominator (d). Keep in mind that these values are stored as `BigInt`:
```javascript
f.s * f.n / f.d = -1 * 4154 / 1485 = -2.797306...
Number(f.s) * Number(f.n) / Number(f.d) = -1 * 4154 / 1485 = -2.797306...
```
If you would try to calculate it yourself, you would come up with something like:
If you attempted to calculate this manually using floating-point arithmetic, you'd get something like:
```javascript
(9.4313131 * (-4 / 3)) % 4.888888 = -2.797308133...
```
Quite okay, but yea - not as accurate as it could be.
While the result is reasonably close, its not as accurate as the fraction-based approach that *Fraction.js* provides, especially when dealing with repeating decimals or complex operations. This highlights the value of precision that the library brings.
### Laplace Probability
Laplace Probability
===
Simple example. What's the probability of throwing a 3, and 1 or 4, and 2 or 4 or 6 with a fair dice?
Here's a straightforward example of using *Fraction.js* to calculate probabilities. Let's determine the probability of rolling a specific outcome on a fair die:
- **P({3})**: The probability of rolling a 3.
- **P({1, 4})**: The probability of rolling either 1 or 4.
- **P({2, 4, 6})**: The probability of rolling 2, 4, or 6.
#### P({3}):
P({3}):
```javascript
var p = new Fraction([3].length, 6).toString(); // 0.1(6)
var p = new Fraction([3].length, 6).toString(); // "0.1(6)"
```
P({1, 4}):
#### P({1, 4}):
```javascript
var p = new Fraction([1, 4].length, 6).toString(); // 0.(3)
var p = new Fraction([1, 4].length, 6).toString(); // "0.(3)"
```
P({2, 4, 6}):
#### P({2, 4, 6}):
```javascript
var p = new Fraction([2, 4, 6].length, 6).toString(); // 0.5
var p = new Fraction([2, 4, 6].length, 6).toString(); // "0.5"
```
Convert degrees/minutes/seconds to precise rational representation:
===
### Convert degrees/minutes/seconds to precise rational representation:
57+45/60+17/3600
```javascript
var deg = 57; // 57°
var min = 45; // 45 Minutes
@ -93,10 +108,9 @@ new Fraction(deg).add(min, 60).add(sec, 3600).toString() // -> 57.7547(2)
```
Rational approximation of irrational numbers
===
### Rational approximation of irrational numbers
Now it's getting messy ;d To approximate a number like *sqrt(5) - 2* with a numerator and denominator, you can reformat the equation as follows: *pow(n / d + 2, 2) = 5*.
To approximate a number like *sqrt(5) - 2* with a numerator and denominator, you can reformat the equation as follows: *pow(n / d + 2, 2) = 5*.
Then the following algorithm will generate the rational number besides the binary representation.
@ -111,7 +125,7 @@ for (var n = 0; n <= 10; n++) {
console.log(n + "\t" + a + "\t" + b + "\t" + c + "\t" + x);
if (c.add(2).pow(2) < 5) {
if (c.add(2).pow(2).valueOf() < 5) {
a = c;
x = "1";
} else {
@ -139,21 +153,21 @@ n a[n] b[n] c[n] x[n]
9 15/64 121/512 241/1024 0
10 241/1024 121/512 483/2048 1
```
Thus the approximation after 11 iterations of the bisection method is *483 / 2048* and the binary representation is 0.00111100011 (see [WolframAlpha](http://www.wolframalpha.com/input/?i=sqrt%285%29-2+binary))
I published another example on how to approximate PI with fraction.js on my [blog](http://www.xarg.org/2014/03/precise-calculations-in-javascript/) (Still not the best idea to approximate irrational numbers, but it illustrates the capabilities of Fraction.js perfectly).
I published another example on how to approximate PI with fraction.js on my [blog](https://raw.org/article/rational-numbers-in-javascript/) (Still not the best idea to approximate irrational numbers, but it illustrates the capabilities of Fraction.js perfectly).
Get the exact fractional part of a number
---
### Get the exact fractional part of a number
```javascript
var f = new Fraction("-6.(3416)");
console.log("" + f.mod(1).abs()); // 0.(3416)
console.log(f.mod(1).abs().toFraction()); // = 3416/9999
```
Mathematical correct modulo
---
### Mathematical correct modulo
The behaviour on negative congruences is different to most modulo implementations in computer science. Even the *mod()* function of Fraction.js behaves in the typical way. To solve the problem of having the mathematical correct modulo with Fraction.js you could come up with this:
```javascript
@ -167,36 +181,35 @@ console.log(new Fraction(a)
.mod(b).add(b).mod(b)); // Correct! Mathematical Modulo
```
fmod() impreciseness circumvented
fmod() imprecision circumvented
---
It turns out that Fraction.js outperforms almost any fmod() implementation, including JavaScript itself, [php.js](http://phpjs.org/functions/fmod/), C++, Python, Java and even Wolframalpha due to the fact that numbers like 0.05, 0.1, ... are infinite decimal in base 2.
The equation *fmod(4.55, 0.05)* gives *0.04999999999999957*, wolframalpha says *1/20*. The correct answer should be **zero**, as 0.05 divides 4.55 without any remainder.
Parser
===
## Parser
Any function (see below) as well as the constructor of the *Fraction* class parses its input and reduce it to the smallest term.
You can pass either Arrays, Objects, Integers, Doubles or Strings.
Arrays / Objects
---
### Arrays / Objects
```javascript
new Fraction(numerator, denominator);
new Fraction([numerator, denominator]);
new Fraction({n: numerator, d: denominator});
```
Integers
---
### Integers
```javascript
new Fraction(123);
```
Doubles
---
### Doubles
```javascript
new Fraction(55.4);
```
@ -206,8 +219,8 @@ new Fraction(55.4);
The method is really precise, but too large exact numbers, like 1234567.9991829 will result in a wrong approximation. If you want to keep the number as it is, convert it to a string, as the string parser will not perform any further observations. If you have problems with the approximation, in the file `examples/approx.js` is a different approximation algorithm, which might work better in some more specific use-cases.
Strings
---
### Strings
```javascript
new Fraction("123.45");
new Fraction("123/45"); // A rational number represented as two decimals, separated by a slash
@ -219,14 +232,14 @@ new Fraction("123.45'6'"); // Note the quotes, see below!
new Fraction("123.45(6)"); // Note the brackets, see below!
```
Two arguments
---
### Two arguments
```javascript
new Fraction(3, 2); // 3/2 = 1.5
```
Repeating decimal places
---
### Repeating decimal places
*Fraction.js* can easily handle repeating decimal places. For example *1/3* is *0.3333...*. There is only one repeating digit. As you can see in the examples above, you can pass a number like *1/3* as "0.'3'" or "0.(3)", which are synonym. There are no tests to parse something like 0.166666666 to 1/6! If you really want to handle this number, wrap around brackets on your own with the function below for example: 0.1(66666666)
Assume you want to divide 123.32 / 33.6(567). [WolframAlpha](http://www.wolframalpha.com/input/?i=123.32+%2F+%2812453%2F370%29) states that you'll get a period of 1776 digits. *Fraction.js* comes to the same result. Give it a try:
@ -275,8 +288,8 @@ if (x !== null) {
}
```
Attributes
===
## Attributes
The Fraction object allows direct access to the numerator, denominator and sign attributes. It is ensured that only the sign-attribute holds sign information so that a sign comparison is only necessary against this attribute.
@ -288,83 +301,102 @@ console.log(f.s); // Sign: -1
```
Functions
===
## Functions
### Fraction abs()
Fraction abs()
---
Returns the actual number without any sign information
Fraction neg()
---
### Fraction neg()
Returns the actual number with flipped sign in order to get the additive inverse
Fraction add(n)
---
### Fraction add(n)
Returns the sum of the actual number and the parameter n
Fraction sub(n)
---
### Fraction sub(n)
Returns the difference of the actual number and the parameter n
Fraction mul(n)
---
### Fraction mul(n)
Returns the product of the actual number and the parameter n
Fraction div(n)
---
### Fraction div(n)
Returns the quotient of the actual number and the parameter n
Fraction pow(exp)
---
### Fraction pow(exp)
Returns the power of the actual number, raised to an possible rational exponent. If the result becomes non-rational the function returns `null`.
Fraction mod(n)
---
### Fraction log(base)
Returns the logarithm of the actual number to a given rational base. If the result becomes non-rational the function returns `null`.
### Fraction mod(n)
Returns the modulus (rest of the division) of the actual object and n (this % n). It's a much more precise [fmod()](#fmod-impreciseness-circumvented) if you like. Please note that *mod()* is just like the modulo operator of most programming languages. If you want a mathematical correct modulo, see [here](#mathematical-correct-modulo).
Fraction mod()
---
### Fraction mod()
Returns the modulus (rest of the division) of the actual object (numerator mod denominator)
Fraction gcd(n)
---
### Fraction gcd(n)
Returns the fractional greatest common divisor
Fraction lcm(n)
---
### Fraction lcm(n)
Returns the fractional least common multiple
Fraction ceil([places=0-16])
---
### Fraction ceil([places=0-16])
Returns the ceiling of a rational number with Math.ceil
Fraction floor([places=0-16])
---
### Fraction floor([places=0-16])
Returns the floor of a rational number with Math.floor
Fraction round([places=0-16])
---
### Fraction round([places=0-16])
Returns the rational number rounded with Math.round
Fraction roundTo(multiple)
---
### Fraction roundTo(multiple)
Rounds a fraction to the closest multiple of another fraction.
Fraction inverse()
---
### Fraction inverse()
Returns the multiplicative inverse of the actual number (n / d becomes d / n) in order to get the reciprocal
Fraction simplify([eps=0.001])
---
### Fraction simplify([eps=0.001])
Simplifies the rational number under a certain error threshold. Ex. `0.333` will be `1/3` with `eps=0.001`
boolean equals(n)
---
Check if two numbers are equal
### boolean equals(n)
Check if two rational numbers are equal
### boolean lt(n)
Check if this rational number is less than another
### boolean lte(n)
Check if this rational number is less than or equal another
### boolean gt(n)
Check if this rational number is greater than another
### boolean gte(n)
Check if this rational number is greater than or equal another
### int compare(n)
int compare(n)
---
Compare two numbers.
```
result < 0: n is greater than actual number
@ -372,34 +404,34 @@ result > 0: n is smaller than actual number
result = 0: n is equal to the actual number
```
boolean divisible(n)
---
### boolean divisible(n)
Check if two numbers are divisible (n divides this)
double valueOf()
---
### double valueOf()
Returns a decimal representation of the fraction
String toString([decimalPlaces=15])
---
Generates an exact string representation of the actual object. For repeated decimal places all digits are collected within brackets, like `1/3 = "0.(3)"`. For all other numbers, up to `decimalPlaces` significant digits are collected - which includes trailing zeros if the number is getting truncated. However, `1/2 = "0.5"` without trailing zeros of course.
### String toString([decimalPlaces=15])
**Note:** As `valueOf()` and `toString()` are provided, `toString()` is only called implicitly in a real string context. Using the plus-operator like `"123" + new Fraction` will call valueOf(), because JavaScript tries to combine two primitives first and concatenates them later, as string will be the more dominant type. `alert(new Fraction)` or `String(new Fraction)` on the other hand will do what you expect. If you really want to have control, you should call `toString()` or `valueOf()` explicitly!
Generates an exact string representation of the given object. For repeating decimal places, digits within repeating cycles are enclosed in parentheses, e.g., `1/3 = "0.(3)"`. For other numbers, the string will include up to the specified `decimalPlaces` significant digits, including any trailing zeros if truncation occurs. For example, `1/2` will be represented as `"0.5"`, without additional trailing zeros.
String toLatex(excludeWhole=false)
---
Generates an exact LaTeX representation of the actual object. You can see a [live demo](http://www.xarg.org/2014/03/precise-calculations-in-javascript/) on my blog.
**Note:** Since both `valueOf()` and `toString()` are provided, `toString()` will only be invoked implicitly when the object is used in a string context. For instance, when using the plus operator like `"123" + new Fraction`, `valueOf()` will be called first, as JavaScript attempts to combine primitives before concatenating them, with the string type taking precedence. However, `alert(new Fraction)` or `String(new Fraction)` will behave as expected. To ensure specific behavior, explicitly call either `toString()` or `valueOf()`.
The optional boolean parameter indicates if you want to exclude the whole part. "1 1/3" instead of "4/3"
### String toLatex(showMixed=false)
Generates an exact LaTeX representation of the actual object. You can see a [live demo](https://raw.org/article/rational-numbers-in-javascript/) on my blog.
The optional boolean parameter indicates if you want to show the a mixed fraction. "1 1/3" instead of "4/3"
### String toFraction(showMixed=false)
String toFraction(excludeWhole=false)
---
Gets a string representation of the fraction
The optional boolean parameter indicates if you want to exclude the whole part. "1 1/3" instead of "4/3"
The optional boolean parameter indicates if you want to showa mixed fraction. "1 1/3" instead of "4/3"
### Array toContinued()
Array toContinued()
---
Gets an array of the fraction represented as a continued fraction. The first element always contains the whole part.
```javascript
@ -407,60 +439,82 @@ var f = new Fraction('88/33');
var c = f.toContinued(); // [2, 1, 2]
```
Fraction clone()
---
### Fraction clone()
Creates a copy of the actual Fraction object
Exceptions
===
If a really hard error occurs (parsing error, division by zero), *fraction.js* throws exceptions! Please make sure you handle them correctly.
## Exceptions
If a really hard error occurs (parsing error, division by zero), *Fraction.js* throws exceptions! Please make sure you handle them correctly.
## Installation
Installation
===
Installing fraction.js is as easy as cloning this repo or use the following command:
You can install `Fraction.js` via npm:
```
```bash
npm install fraction.js
```
Using Fraction.js with the browser
===
Or with yarn:
```bash
yarn add fraction.js
```
Alternatively, download or clone the repository:
```bash
git clone https://github.com/rawify/Fraction.js
```
## Usage
Include the `fraction.min.js` file in your project:
```html
<script src="fraction.js"></script>
<script src="path/to/fraction.min.js"></script>
<script>
console.log(Fraction("123/456"));
var x = new Fraction("13/4");
</script>
```
Using Fraction.js with TypeScript
===
```js
import Fraction from "fraction.js";
console.log(Fraction("123/456"));
Or in a Node.js project:
```javascript
const Fraction = require('fraction.js');
```
Coding Style
===
As every library I publish, fraction.js is also built to be as small as possible after compressing it with Google Closure Compiler in advanced mode. Thus the coding style orientates a little on maxing-out the compression rate. Please make sure you keep this style if you plan to extend the library.
or
Precision
===
Fraction.js tries to circumvent floating point errors, by having an internal representation of numerator and denominator. As it relies on JavaScript, there is also a limit. The biggest number representable is `Number.MAX_SAFE_INTEGER / 1` and the smallest is `-1 / Number.MAX_SAFE_INTEGER`, with `Number.MAX_SAFE_INTEGER=9007199254740991`. If this is not enough, there is `bigfraction.js` shipped experimentally, which relies on `BigInt` and should become the new Fraction.js eventually.
Testing
===
If you plan to enhance the library, make sure you add test cases and all the previous tests are passing. You can test the library with
```
npm test
```javascript
import Fraction from 'fraction.js';
```
Copyright and licensing
===
Copyright (c) 2023, [Robert Eisele](https://raw.org/)
## Coding Style
As every library I publish, Fraction.js is also built to be as small as possible after compressing it with Google Closure Compiler in advanced mode. Thus the coding style orientates a little on maxing-out the compression rate. Please make sure you keep this style if you plan to extend the library.
## Building the library
After cloning the Git repository run:
```bash
npm install
npm run build
```
## Run a test
Testing the source against the shipped test suite is as easy as
```bash
npm run test
```
## Copyright and Licensing
Copyright (c) 2025, [Robert Eisele](https://raw.org/)
Licensed under the MIT license.

View File

@ -1,899 +0,0 @@
/**
* @license Fraction.js v4.2.1 20/08/2023
* https://www.xarg.org/2014/03/rational-numbers-in-javascript/
*
* Copyright (c) 2023, Robert Eisele (robert@raw.org)
* Dual licensed under the MIT or GPL Version 2 licenses.
**/
/**
*
* This class offers the possibility to calculate fractions.
* You can pass a fraction in different formats. Either as array, as double, as string or as an integer.
*
* Array/Object form
* [ 0 => <numerator>, 1 => <denominator> ]
* [ n => <numerator>, d => <denominator> ]
*
* Integer form
* - Single integer value
*
* Double form
* - Single double value
*
* String form
* 123.456 - a simple double
* 123/456 - a string fraction
* 123.'456' - a double with repeating decimal places
* 123.(456) - synonym
* 123.45'6' - a double with repeating last place
* 123.45(6) - synonym
*
* Example:
*
* let f = new Fraction("9.4'31'");
* f.mul([-4, 3]).div(4.9);
*
*/
(function(root) {
"use strict";
// Set Identity function to downgrade BigInt to Number if needed
if (typeof BigInt === 'undefined') BigInt = function(n) { if (isNaN(n)) throw new Error(""); return n; };
const C_ONE = BigInt(1);
const C_ZERO = BigInt(0);
const C_TEN = BigInt(10);
const C_TWO = BigInt(2);
const C_FIVE = BigInt(5);
// Maximum search depth for cyclic rational numbers. 2000 should be more than enough.
// Example: 1/7 = 0.(142857) has 6 repeating decimal places.
// If MAX_CYCLE_LEN gets reduced, long cycles will not be detected and toString() only gets the first 10 digits
const MAX_CYCLE_LEN = 2000;
// Parsed data to avoid calling "new" all the time
const P = {
"s": C_ONE,
"n": C_ZERO,
"d": C_ONE
};
function assign(n, s) {
try {
n = BigInt(n);
} catch (e) {
throw InvalidParameter();
}
return n * s;
}
// Creates a new Fraction internally without the need of the bulky constructor
function newFraction(n, d) {
if (d === C_ZERO) {
throw DivisionByZero();
}
const f = Object.create(Fraction.prototype);
f["s"] = n < C_ZERO ? -C_ONE : C_ONE;
n = n < C_ZERO ? -n : n;
const a = gcd(n, d);
f["n"] = n / a;
f["d"] = d / a;
return f;
}
function factorize(num) {
const factors = {};
let n = num;
let i = C_TWO;
let s = C_FIVE - C_ONE;
while (s <= n) {
while (n % i === C_ZERO) {
n/= i;
factors[i] = (factors[i] || C_ZERO) + C_ONE;
}
s+= C_ONE + C_TWO * i++;
}
if (n !== num) {
if (n > 1)
factors[n] = (factors[n] || C_ZERO) + C_ONE;
} else {
factors[num] = (factors[num] || C_ZERO) + C_ONE;
}
return factors;
}
const parse = function(p1, p2) {
let n = C_ZERO, d = C_ONE, s = C_ONE;
if (p1 === undefined || p1 === null) {
/* void */
} else if (p2 !== undefined) {
n = BigInt(p1);
d = BigInt(p2);
s = n * d;
if (n % C_ONE !== C_ZERO || d % C_ONE !== C_ZERO) {
throw NonIntegerParameter();
}
} else if (typeof p1 === "object") {
if ("d" in p1 && "n" in p1) {
n = BigInt(p1["n"]);
d = BigInt(p1["d"]);
if ("s" in p1)
n*= BigInt(p1["s"]);
} else if (0 in p1) {
n = BigInt(p1[0]);
if (1 in p1)
d = BigInt(p1[1]);
} else if (p1 instanceof BigInt) {
n = BigInt(p1);
} else {
throw InvalidParameter();
}
s = n * d;
} else if (typeof p1 === "bigint") {
n = p1;
s = p1;
d = C_ONE;
} else if (typeof p1 === "number") {
if (isNaN(p1)) {
throw InvalidParameter();
}
if (p1 < 0) {
s = -C_ONE;
p1 = -p1;
}
if (p1 % 1 === 0) {
n = BigInt(p1);
} else if (p1 > 0) { // check for != 0, scale would become NaN (log(0)), which converges really slow
let z = 1;
let A = 0, B = 1;
let C = 1, D = 1;
let N = 10000000;
if (p1 >= 1) {
z = 10 ** Math.floor(1 + Math.log10(p1));
p1/= z;
}
// Using Farey Sequences
while (B <= N && D <= N) {
let M = (A + C) / (B + D);
if (p1 === M) {
if (B + D <= N) {
n = A + C;
d = B + D;
} else if (D > B) {
n = C;
d = D;
} else {
n = A;
d = B;
}
break;
} else {
if (p1 > M) {
A+= C;
B+= D;
} else {
C+= A;
D+= B;
}
if (B > N) {
n = C;
d = D;
} else {
n = A;
d = B;
}
}
}
n = BigInt(n) * BigInt(z);
d = BigInt(d);
}
} else if (typeof p1 === "string") {
let ndx = 0;
let v = C_ZERO, w = C_ZERO, x = C_ZERO, y = C_ONE, z = C_ONE;
let match = p1.match(/\d+|./g);
if (match === null)
throw InvalidParameter();
if (match[ndx] === '-') {// Check for minus sign at the beginning
s = -C_ONE;
ndx++;
} else if (match[ndx] === '+') {// Check for plus sign at the beginning
ndx++;
}
if (match.length === ndx + 1) { // Check if it's just a simple number "1234"
w = assign(match[ndx++], s);
} else if (match[ndx + 1] === '.' || match[ndx] === '.') { // Check if it's a decimal number
if (match[ndx] !== '.') { // Handle 0.5 and .5
v = assign(match[ndx++], s);
}
ndx++;
// Check for decimal places
if (ndx + 1 === match.length || match[ndx + 1] === '(' && match[ndx + 3] === ')' || match[ndx + 1] === "'" && match[ndx + 3] === "'") {
w = assign(match[ndx], s);
y = C_TEN ** BigInt(match[ndx].length);
ndx++;
}
// Check for repeating places
if (match[ndx] === '(' && match[ndx + 2] === ')' || match[ndx] === "'" && match[ndx + 2] === "'") {
x = assign(match[ndx + 1], s);
z = C_TEN ** BigInt(match[ndx + 1].length) - C_ONE;
ndx+= 3;
}
} else if (match[ndx + 1] === '/' || match[ndx + 1] === ':') { // Check for a simple fraction "123/456" or "123:456"
w = assign(match[ndx], s);
y = assign(match[ndx + 2], C_ONE);
ndx+= 3;
} else if (match[ndx + 3] === '/' && match[ndx + 1] === ' ') { // Check for a complex fraction "123 1/2"
v = assign(match[ndx], s);
w = assign(match[ndx + 2], s);
y = assign(match[ndx + 4], C_ONE);
ndx+= 5;
}
if (match.length <= ndx) { // Check for more tokens on the stack
d = y * z;
s = /* void */
n = x + d * v + z * w;
} else {
throw InvalidParameter();
}
} else {
throw InvalidParameter();
}
if (d === C_ZERO) {
throw DivisionByZero();
}
P["s"] = s < C_ZERO ? -C_ONE : C_ONE;
P["n"] = n < C_ZERO ? -n : n;
P["d"] = d < C_ZERO ? -d : d;
};
function modpow(b, e, m) {
let r = C_ONE;
for (; e > C_ZERO; b = (b * b) % m, e >>= C_ONE) {
if (e & C_ONE) {
r = (r * b) % m;
}
}
return r;
}
function cycleLen(n, d) {
for (; d % C_TWO === C_ZERO;
d/= C_TWO) {
}
for (; d % C_FIVE === C_ZERO;
d/= C_FIVE) {
}
if (d === C_ONE) // Catch non-cyclic numbers
return C_ZERO;
// If we would like to compute really large numbers quicker, we could make use of Fermat's little theorem:
// 10^(d-1) % d == 1
// However, we don't need such large numbers and MAX_CYCLE_LEN should be the capstone,
// as we want to translate the numbers to strings.
let rem = C_TEN % d;
let t = 1;
for (; rem !== C_ONE; t++) {
rem = rem * C_TEN % d;
if (t > MAX_CYCLE_LEN)
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`
}
return BigInt(t);
}
function cycleStart(n, d, len) {
let rem1 = C_ONE;
let rem2 = modpow(C_TEN, len, d);
for (let t = 0; t < 300; t++) { // s < ~log10(Number.MAX_VALUE)
// Solve 10^s == 10^(s+t) (mod d)
if (rem1 === rem2)
return BigInt(t);
rem1 = rem1 * C_TEN % d;
rem2 = rem2 * C_TEN % d;
}
return 0;
}
function gcd(a, b) {
if (!a)
return b;
if (!b)
return a;
while (1) {
a%= b;
if (!a)
return b;
b%= a;
if (!b)
return a;
}
}
/**
* Module constructor
*
* @constructor
* @param {number|Fraction=} a
* @param {number=} b
*/
function Fraction(a, b) {
parse(a, b);
if (this instanceof Fraction) {
a = gcd(P["d"], P["n"]); // Abuse a
this["s"] = P["s"];
this["n"] = P["n"] / a;
this["d"] = P["d"] / a;
} else {
return newFraction(P['s'] * P['n'], P['d']);
}
}
var DivisionByZero = function() {return new Error("Division by Zero");};
var InvalidParameter = function() {return new Error("Invalid argument");};
var NonIntegerParameter = function() {return new Error("Parameters must be integer");};
Fraction.prototype = {
"s": C_ONE,
"n": C_ZERO,
"d": C_ONE,
/**
* Calculates the absolute value
*
* Ex: new Fraction(-4).abs() => 4
**/
"abs": function() {
return newFraction(this["n"], this["d"]);
},
/**
* Inverts the sign of the current fraction
*
* Ex: new Fraction(-4).neg() => 4
**/
"neg": function() {
return newFraction(-this["s"] * this["n"], this["d"]);
},
/**
* Adds two rational numbers
*
* Ex: new Fraction({n: 2, d: 3}).add("14.9") => 467 / 30
**/
"add": function(a, b) {
parse(a, b);
return newFraction(
this["s"] * this["n"] * P["d"] + P["s"] * this["d"] * P["n"],
this["d"] * P["d"]
);
},
/**
* Subtracts two rational numbers
*
* Ex: new Fraction({n: 2, d: 3}).add("14.9") => -427 / 30
**/
"sub": function(a, b) {
parse(a, b);
return newFraction(
this["s"] * this["n"] * P["d"] - P["s"] * this["d"] * P["n"],
this["d"] * P["d"]
);
},
/**
* Multiplies two rational numbers
*
* Ex: new Fraction("-17.(345)").mul(3) => 5776 / 111
**/
"mul": function(a, b) {
parse(a, b);
return newFraction(
this["s"] * P["s"] * this["n"] * P["n"],
this["d"] * P["d"]
);
},
/**
* Divides two rational numbers
*
* Ex: new Fraction("-17.(345)").inverse().div(3)
**/
"div": function(a, b) {
parse(a, b);
return newFraction(
this["s"] * P["s"] * this["n"] * P["d"],
this["d"] * P["n"]
);
},
/**
* Clones the actual object
*
* Ex: new Fraction("-17.(345)").clone()
**/
"clone": function() {
return newFraction(this['s'] * this['n'], this['d']);
},
/**
* Calculates the modulo of two rational numbers - a more precise fmod
*
* Ex: new Fraction('4.(3)').mod([7, 8]) => (13/3) % (7/8) = (5/6)
**/
"mod": function(a, b) {
if (a === undefined) {
return newFraction(this["s"] * this["n"] % this["d"], C_ONE);
}
parse(a, b);
if (0 === P["n"] && 0 === this["d"]) {
throw DivisionByZero();
}
/*
* First silly attempt, kinda slow
*
return that["sub"]({
"n": num["n"] * Math.floor((this.n / this.d) / (num.n / num.d)),
"d": num["d"],
"s": this["s"]
});*/
/*
* New attempt: a1 / b1 = a2 / b2 * q + r
* => b2 * a1 = a2 * b1 * q + b1 * b2 * r
* => (b2 * a1 % a2 * b1) / (b1 * b2)
*/
return newFraction(
this["s"] * (P["d"] * this["n"]) % (P["n"] * this["d"]),
P["d"] * this["d"]
);
},
/**
* Calculates the fractional gcd of two rational numbers
*
* Ex: new Fraction(5,8).gcd(3,7) => 1/56
*/
"gcd": function(a, b) {
parse(a, b);
// gcd(a / b, c / d) = gcd(a, c) / lcm(b, d)
return newFraction(gcd(P["n"], this["n"]) * gcd(P["d"], this["d"]), P["d"] * this["d"]);
},
/**
* Calculates the fractional lcm of two rational numbers
*
* Ex: new Fraction(5,8).lcm(3,7) => 15
*/
"lcm": function(a, b) {
parse(a, b);
// lcm(a / b, c / d) = lcm(a, c) / gcd(b, d)
if (P["n"] === C_ZERO && this["n"] === C_ZERO) {
return newFraction(C_ZERO, C_ONE);
}
return newFraction(P["n"] * this["n"], gcd(P["n"], this["n"]) * gcd(P["d"], this["d"]));
},
/**
* Gets the inverse of the fraction, means numerator and denominator are exchanged
*
* Ex: new Fraction([-3, 4]).inverse() => -4 / 3
**/
"inverse": function() {
return newFraction(this["s"] * this["d"], this["n"]);
},
/**
* Calculates the fraction to some integer exponent
*
* Ex: new Fraction(-1,2).pow(-3) => -8
*/
"pow": function(a, b) {
parse(a, b);
// Trivial case when exp is an integer
if (P['d'] === C_ONE) {
if (P['s'] < C_ZERO) {
return newFraction((this['s'] * this["d"]) ** P['n'], this["n"] ** P['n']);
} else {
return newFraction((this['s'] * this["n"]) ** P['n'], this["d"] ** P['n']);
}
}
// Negative roots become complex
// (-a/b)^(c/d) = x
// <=> (-1)^(c/d) * (a/b)^(c/d) = x
// <=> (cos(pi) + i*sin(pi))^(c/d) * (a/b)^(c/d) = x
// <=> (cos(c*pi/d) + i*sin(c*pi/d)) * (a/b)^(c/d) = x # DeMoivre's formula
// From which follows that only for c=0 the root is non-complex
if (this['s'] < C_ZERO) return null;
// Now prime factor n and d
let N = factorize(this['n']);
let D = factorize(this['d']);
// Exponentiate and take root for n and d individually
let n = C_ONE;
let d = C_ONE;
for (let k in N) {
if (k === '1') continue;
if (k === '0') {
n = C_ZERO;
break;
}
N[k]*= P['n'];
if (N[k] % P['d'] === C_ZERO) {
N[k]/= P['d'];
} else return null;
n*= BigInt(k) ** N[k];
}
for (let k in D) {
if (k === '1') continue;
D[k]*= P['n'];
if (D[k] % P['d'] === C_ZERO) {
D[k]/= P['d'];
} else return null;
d*= BigInt(k) ** D[k];
}
if (P['s'] < C_ZERO) {
return newFraction(d, n);
}
return newFraction(n, d);
},
/**
* Check if two rational numbers are the same
*
* Ex: new Fraction(19.6).equals([98, 5]);
**/
"equals": function(a, b) {
parse(a, b);
return this["s"] * this["n"] * P["d"] === P["s"] * P["n"] * this["d"]; // Same as compare() === 0
},
/**
* Check if two rational numbers are the same
*
* Ex: new Fraction(19.6).equals([98, 5]);
**/
"compare": function(a, b) {
parse(a, b);
let t = (this["s"] * this["n"] * P["d"] - P["s"] * P["n"] * this["d"]);
return (C_ZERO < t) - (t < C_ZERO);
},
/**
* Calculates the ceil of a rational number
*
* Ex: new Fraction('4.(3)').ceil() => (5 / 1)
**/
"ceil": function(places) {
places = C_TEN ** BigInt(places || 0);
return newFraction(this["s"] * places * this["n"] / this["d"] +
(places * this["n"] % this["d"] > C_ZERO && this["s"] >= C_ZERO ? C_ONE : C_ZERO),
places);
},
/**
* Calculates the floor of a rational number
*
* Ex: new Fraction('4.(3)').floor() => (4 / 1)
**/
"floor": function(places) {
places = C_TEN ** BigInt(places || 0);
return newFraction(this["s"] * places * this["n"] / this["d"] -
(places * this["n"] % this["d"] > C_ZERO && this["s"] < C_ZERO ? C_ONE : C_ZERO),
places);
},
/**
* Rounds a rational numbers
*
* Ex: new Fraction('4.(3)').round() => (4 / 1)
**/
"round": function(places) {
places = C_TEN ** BigInt(places || 0);
/* Derivation:
s >= 0:
round(n / d) = trunc(n / d) + (n % d) / d >= 0.5 ? 1 : 0
= trunc(n / d) + 2(n % d) >= d ? 1 : 0
s < 0:
round(n / d) =-trunc(n / d) - (n % d) / d > 0.5 ? 1 : 0
=-trunc(n / d) - 2(n % d) > d ? 1 : 0
=>:
round(s * n / d) = s * trunc(n / d) + s * (C + 2(n % d) > d ? 1 : 0)
where C = s >= 0 ? 1 : 0, to fix the >= for the positve case.
*/
return newFraction(this["s"] * places * this["n"] / this["d"] +
this["s"] * ((this["s"] >= C_ZERO ? C_ONE : C_ZERO) + C_TWO * (places * this["n"] % this["d"]) > this["d"] ? C_ONE : C_ZERO),
places);
},
/**
* Check if two rational numbers are divisible
*
* Ex: new Fraction(19.6).divisible(1.5);
*/
"divisible": function(a, b) {
parse(a, b);
return !(!(P["n"] * this["d"]) || ((this["n"] * P["d"]) % (P["n"] * this["d"])));
},
/**
* Returns a decimal representation of the fraction
*
* Ex: new Fraction("100.'91823'").valueOf() => 100.91823918239183
**/
'valueOf': function() {
// Best we can do so far
return Number(this["s"] * this["n"]) / Number(this["d"]);
},
/**
* Creates a string representation of a fraction with all digits
*
* Ex: new Fraction("100.'91823'").toString() => "100.(91823)"
**/
'toString': function(dec) {
let N = this["n"];
let D = this["d"];
function trunc(x) {
return typeof x === 'bigint' ? x : Math.floor(x);
}
dec = dec || 15; // 15 = decimal places when no repetition
let cycLen = cycleLen(N, D); // Cycle length
let cycOff = cycleStart(N, D, cycLen); // Cycle start
let str = this['s'] < C_ZERO ? "-" : "";
// Append integer part
str+= trunc(N / D);
N%= D;
N*= C_TEN;
if (N)
str+= ".";
if (cycLen) {
for (let i = cycOff; i--;) {
str+= trunc(N / D);
N%= D;
N*= C_TEN;
}
str+= "(";
for (let i = cycLen; i--;) {
str+= trunc(N / D);
N%= D;
N*= C_TEN;
}
str+= ")";
} else {
for (let i = dec; N && i--;) {
str+= trunc(N / D);
N%= D;
N*= C_TEN;
}
}
return str;
},
/**
* Returns a string-fraction representation of a Fraction object
*
* Ex: new Fraction("1.'3'").toFraction() => "4 1/3"
**/
'toFraction': function(excludeWhole) {
let n = this["n"];
let d = this["d"];
let str = this['s'] < C_ZERO ? "-" : "";
if (d === C_ONE) {
str+= n;
} else {
let whole = n / d;
if (excludeWhole && whole > C_ZERO) {
str+= whole;
str+= " ";
n%= d;
}
str+= n;
str+= '/';
str+= d;
}
return str;
},
/**
* Returns a latex representation of a Fraction object
*
* Ex: new Fraction("1.'3'").toLatex() => "\frac{4}{3}"
**/
'toLatex': function(excludeWhole) {
let n = this["n"];
let d = this["d"];
let str = this['s'] < C_ZERO ? "-" : "";
if (d === C_ONE) {
str+= n;
} else {
let whole = n / d;
if (excludeWhole && whole > C_ZERO) {
str+= whole;
n%= d;
}
str+= "\\frac{";
str+= n;
str+= '}{';
str+= d;
str+= '}';
}
return str;
},
/**
* Returns an array of continued fraction elements
*
* Ex: new Fraction("7/8").toContinued() => [0,1,7]
*/
'toContinued': function() {
let a = this['n'];
let b = this['d'];
let res = [];
do {
res.push(a / b);
let t = a % b;
a = b;
b = t;
} while (a !== C_ONE);
return res;
},
"simplify": function(eps) {
eps = eps || 0.001;
const thisABS = this['abs']();
const cont = thisABS['toContinued']();
for (let i = 1; i < cont.length; i++) {
let s = newFraction(cont[i - 1], C_ONE);
for (let k = i - 2; k >= 0; k--) {
s = s['inverse']()['add'](cont[k]);
}
if (Math.abs(s['sub'](thisABS).valueOf()) < eps) {
return s['mul'](this['s']);
}
}
return this;
}
};
if (typeof define === "function" && define["amd"]) {
define([], function() {
return Fraction;
});
} else if (typeof exports === "object") {
Object.defineProperty(exports, "__esModule", { 'value': true });
Fraction['default'] = Fraction;
Fraction['Fraction'] = Fraction;
module['exports'] = Fraction;
} else {
root['Fraction'] = Fraction;
}
})(this);

1045
frontend/node_modules/fraction.js/dist/fraction.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

21
frontend/node_modules/fraction.js/dist/fraction.min.js generated vendored Normal file
View File

@ -0,0 +1,21 @@
/*
Fraction.js v5.3.4 8/22/2025
https://raw.org/article/rational-numbers-in-javascript/
Copyright (c) 2025, Robert Eisele (https://raw.org/)
Licensed under the MIT license.
*/
'use strict';(function(F){function D(){return Error("Parameters must be integer")}function x(){return Error("Invalid argument")}function C(){return Error("Division by Zero")}function q(a,b){var d=g,c=h;let f=h;if(void 0!==a&&null!==a)if(void 0!==b){if("bigint"===typeof a)d=a;else{if(isNaN(a))throw x();if(0!==a%1)throw D();d=BigInt(a)}if("bigint"===typeof b)c=b;else{if(isNaN(b))throw x();if(0!==b%1)throw D();c=BigInt(b)}f=d*c}else if("object"===typeof a){if("d"in a&&"n"in a)d=BigInt(a.n),c=BigInt(a.d),
"s"in a&&(d*=BigInt(a.s));else if(0 in a)d=BigInt(a[0]),1 in a&&(c=BigInt(a[1]));else if("bigint"===typeof a)d=a;else throw x();f=d*c}else if("number"===typeof a){if(isNaN(a))throw x();0>a&&(f=-h,a=-a);if(0===a%1)d=BigInt(a);else{b=1;var k=0,l=1,m=1;let r=1;1<=a&&(b=10**Math.floor(1+Math.log10(a)),a/=b);for(;1E7>=l&&1E7>=r;)if(c=(k+m)/(l+r),a===c){1E7>=l+r?(d=k+m,c=l+r):r>l?(d=m,c=r):(d=k,c=l);break}else a>c?(k+=m,l+=r):(m+=k,r+=l),1E7<l?(d=m,c=r):(d=k,c=l);d=BigInt(d)*BigInt(b);c=BigInt(c)}}else if("string"===
typeof a){c=0;k=b=d=g;l=m=h;a=a.replace(/_/g,"").match(/\d+|./g);if(null===a)throw x();"-"===a[c]?(f=-h,c++):"+"===a[c]&&c++;if(a.length===c+1)b=w(a[c++],f);else if("."===a[c+1]||"."===a[c]){"."!==a[c]&&(d=w(a[c++],f));c++;if(c+1===a.length||"("===a[c+1]&&")"===a[c+3]||"'"===a[c+1]&&"'"===a[c+3])b=w(a[c],f),m=t**BigInt(a[c].length),c++;if("("===a[c]&&")"===a[c+2]||"'"===a[c]&&"'"===a[c+2])k=w(a[c+1],f),l=t**BigInt(a[c+1].length)-h,c+=3}else"/"===a[c+1]||":"===a[c+1]?(b=w(a[c],f),m=w(a[c+2],h),c+=
3):"/"===a[c+3]&&" "===a[c+1]&&(d=w(a[c],f),b=w(a[c+2],f),m=w(a[c+4],h),c+=5);if(a.length<=c)c=m*l,f=d=k+c*d+l*b;else throw x();}else if("bigint"===typeof a)f=d=a,c=h;else throw x();if(c===g)throw C();e.s=f<g?-h:h;e.n=d<g?-d:d;e.d=c<g?-c:c}function w(a,b){try{a=BigInt(a)}catch(d){throw x();}return a*b}function u(a){return"bigint"===typeof a?a:Math.floor(a)}function n(a,b){if(b===g)throw C();const d=Object.create(v.prototype);d.s=a<g?-h:h;a=a<g?-a:a;const c=y(a,b);d.n=a/c;d.d=b/c;return d}function A(a){const b=
Object.create(null);if(a<=h)return b[a]=h,b;for(;a%p===g;)b[p]=(b[p]||g)+h,a/=p;for(;a%B===g;)b[B]=(b[B]||g)+h,a/=B;for(;a%z===g;)b[z]=(b[z]||g)+h,a/=z;for(let d=0,c=p+z;c*c<=a;){for(;a%c===g;)b[c]=(b[c]||g)+h,a/=c;c+=G[d];d=d+1&7}a>h&&(b[a]=(b[a]||g)+h);return b}function y(a,b){if(!a)return b;if(!b)return a;for(;;){a%=b;if(!a)return b;b%=a;if(!b)return a}}function v(a,b){q(a,b);if(this instanceof v)a=y(e.d,e.n),this.s=e.s,this.n=e.n/a,this.d=e.d/a;else return n(e.s*e.n,e.d)}"undefined"===typeof BigInt&&
(BigInt=function(a){if(isNaN(a))throw Error("");return a});const g=BigInt(0),h=BigInt(1),p=BigInt(2),B=BigInt(3),z=BigInt(5),t=BigInt(10),e={s:h,n:g,d:h},G=[p*p,p,p*p,p,p*p,p*B,p,p*B];v.prototype={s:h,n:g,d:h,abs:function(){return n(this.n,this.d)},neg:function(){return n(-this.s*this.n,this.d)},add:function(a,b){q(a,b);return n(this.s*this.n*e.d+e.s*this.d*e.n,this.d*e.d)},sub:function(a,b){q(a,b);return n(this.s*this.n*e.d-e.s*this.d*e.n,this.d*e.d)},mul:function(a,b){q(a,b);return n(this.s*e.s*
this.n*e.n,this.d*e.d)},div:function(a,b){q(a,b);return n(this.s*e.s*this.n*e.d,this.d*e.n)},clone:function(){return n(this.s*this.n,this.d)},mod:function(a,b){if(void 0===a)return n(this.s*this.n%this.d,h);q(a,b);if(g===e.n*this.d)throw C();return n(this.s*e.d*this.n%(e.n*this.d),e.d*this.d)},gcd:function(a,b){q(a,b);return n(y(e.n,this.n)*y(e.d,this.d),e.d*this.d)},lcm:function(a,b){q(a,b);return e.n===g&&this.n===g?n(g,h):n(e.n*this.n,y(e.n,this.n)*y(e.d,this.d))},inverse:function(){return n(this.s*
this.d,this.n)},pow:function(a,b){q(a,b);if(e.d===h)return e.s<g?n((this.s*this.d)**e.n,this.n**e.n):n((this.s*this.n)**e.n,this.d**e.n);if(this.s<g)return null;a=A(this.n);b=A(this.d);let d=h,c=h;for(let f in a)if("1"!==f){if("0"===f){d=g;break}a[f]*=e.n;if(a[f]%e.d===g)a[f]/=e.d;else return null;d*=BigInt(f)**a[f]}for(let f in b)if("1"!==f){b[f]*=e.n;if(b[f]%e.d===g)b[f]/=e.d;else return null;c*=BigInt(f)**b[f]}return e.s<g?n(c,d):n(d,c)},log:function(a,b){q(a,b);if(this.s<=g||e.s<=g)return null;
var d=Object.create(null);a=A(e.n);const c=A(e.d);b=A(this.n);const f=A(this.d);for(var k in c)a[k]=(a[k]||g)-c[k];for(var l in f)b[l]=(b[l]||g)-f[l];for(var m in a)"1"!==m&&(d[m]=!0);for(var r in b)"1"!==r&&(d[r]=!0);l=k=null;for(const E in d)if(m=a[E]||g,d=b[E]||g,m===g){if(d!==g)return null}else if(r=y(d,m),d/=r,m/=r,null===k&&null===l)k=d,l=m;else if(d*l!==k*m)return null;return null!==k&&null!==l?n(k,l):null},equals:function(a,b){q(a,b);return this.s*this.n*e.d===e.s*e.n*this.d},lt:function(a,
b){q(a,b);return this.s*this.n*e.d<e.s*e.n*this.d},lte:function(a,b){q(a,b);return this.s*this.n*e.d<=e.s*e.n*this.d},gt:function(a,b){q(a,b);return this.s*this.n*e.d>e.s*e.n*this.d},gte:function(a,b){q(a,b);return this.s*this.n*e.d>=e.s*e.n*this.d},compare:function(a,b){q(a,b);a=this.s*this.n*e.d-e.s*e.n*this.d;return(g<a)-(a<g)},ceil:function(a){a=t**BigInt(a||0);return n(u(this.s*a*this.n/this.d)+(a*this.n%this.d>g&&this.s>=g?h:g),a)},floor:function(a){a=t**BigInt(a||0);return n(u(this.s*a*this.n/
this.d)-(a*this.n%this.d>g&&this.s<g?h:g),a)},round:function(a){a=t**BigInt(a||0);return n(u(this.s*a*this.n/this.d)+this.s*((this.s>=g?h:g)+a*this.n%this.d*p>this.d?h:g),a)},roundTo:function(a,b){q(a,b);var d=this.n*e.d;a=this.d*e.n;b=d%a;d=u(d/a);b+b>=a&&d++;return n(this.s*d*e.n,e.d)},divisible:function(a,b){q(a,b);return e.n===g?!1:this.n*e.d%(e.n*this.d)===g},valueOf:function(){return Number(this.s*this.n)/Number(this.d)},toString:function(a=15){let b=this.n,d=this.d;var c;a:{for(c=d;c%p===g;c/=
p);for(;c%z===g;c/=z);if(c===h)c=g;else{for(var f=t%c,k=1;f!==h;k++)if(f=f*t%c,2E3<k){c=g;break a}c=BigInt(k)}}a:{f=h;k=t;var l=c;let m=h;for(;l>g;k=k*k%d,l>>=h)l&h&&(m=m*k%d);k=m;for(l=0;300>l;l++){if(f===k){f=BigInt(l);break a}f=f*t%d;k=k*t%d}f=0}k=f;f=this.s<g?"-":"";f+=u(b/d);(b=b%d*t)&&(f+=".");if(c){for(a=k;a--;)f+=u(b/d),b%=d,b*=t;f+="(";for(a=c;a--;)f+=u(b/d),b%=d,b*=t;f+=")"}else for(;b&&a--;)f+=u(b/d),b%=d,b*=t;return f},toFraction:function(a=!1){let b=this.n,d=this.d,c=this.s<g?"-":"";
if(d===h)c+=b;else{const f=u(b/d);a&&f>g&&(c+=f,c+=" ",b%=d);c=c+b+"/"+d}return c},toLatex:function(a=!1){let b=this.n,d=this.d,c=this.s<g?"-":"";if(d===h)c+=b;else{const f=u(b/d);a&&f>g&&(c+=f,b%=d);c=c+"\\frac{"+b+"}{"+d;c+="}"}return c},toContinued:function(){let a=this.n,b=this.d;const d=[];for(;b;){d.push(u(a/b));const c=a%b;a=b;b=c}return d},simplify:function(a=.001){a=BigInt(Math.ceil(1/a));const b=this.abs(),d=b.toContinued();for(let f=1;f<d.length;f++){let k=n(d[f-1],h);for(var c=f-2;0<=
c;c--)k=k.inverse().add(d[c]);c=k.sub(b);if(c.n*a<c.d)return k.mul(this.s)}return this}};"function"===typeof define&&define.amd?define([],function(){return v}):"object"===typeof exports?(Object.defineProperty(v,"__esModule",{value:!0}),v["default"]=v,v.Fraction=v,module.exports=v):F.Fraction=v})(this);

1043
frontend/node_modules/fraction.js/dist/fraction.mjs generated vendored Normal file

File diff suppressed because it is too large Load Diff

26
frontend/node_modules/fraction.js/examples/angles.js generated vendored Normal file
View File

@ -0,0 +1,26 @@
/*
Fraction.js v5.0.0 10/1/2024
https://raw.org/article/rational-numbers-in-javascript/
Copyright (c) 2024, Robert Eisele (https://raw.org/)
Licensed under the MIT license.
*/
// This example generates a list of angles with human readable radians
var Fraction = require('fraction.js');
var tab = [];
for (var d = 1; d <= 360; d++) {
var pi = Fraction(2, 360).mul(d);
var tau = Fraction(1, 360).mul(d);
if (pi.d <= 6n && pi.d != 5n)
tab.push([
d,
pi.toFraction() + "pi",
tau.toFraction() + "tau"]);
}
console.table(tab);

54
frontend/node_modules/fraction.js/examples/approx.js generated vendored Normal file
View File

@ -0,0 +1,54 @@
/*
Fraction.js v5.0.0 10/1/2024
https://raw.org/article/rational-numbers-in-javascript/
Copyright (c) 2024, Robert Eisele (https://raw.org/)
Licensed under the MIT license.
*/
const Fraction = require('fraction.js');
// Another rational approximation, not using Farey Sequences but Binary Search using the mediant
function approximate(p, precision) {
var num1 = Math.floor(p);
var den1 = 1;
var num2 = num1 + 1;
var den2 = 1;
if (p !== num1) {
while (den1 <= precision && den2 <= precision) {
var m = (num1 + num2) / (den1 + den2);
if (p === m) {
if (den1 + den2 <= precision) {
den1 += den2;
num1 += num2;
den2 = precision + 1;
} else if (den1 > den2) {
den2 = precision + 1;
} else {
den1 = precision + 1;
}
break;
} else if (p < m) {
num2 += num1;
den2 += den1;
} else {
num1 += num2;
den1 += den2;
}
}
}
if (den1 > precision) {
den1 = den2;
num1 = num2;
}
return new Fraction(num1, den1);
}

24
frontend/node_modules/fraction.js/examples/egyptian.js generated vendored Normal file
View File

@ -0,0 +1,24 @@
/*
Fraction.js v5.0.0 10/1/2024
https://raw.org/article/rational-numbers-in-javascript/
Copyright (c) 2024, Robert Eisele (https://raw.org/)
Licensed under the MIT license.
*/
const Fraction = require('fraction.js');
// Based on http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fractions/egyptian.html
function egyptian(a, b) {
var res = [];
do {
var t = Math.ceil(b / a);
var x = new Fraction(a, b).sub(1, t);
res.push(t);
a = Number(x.n);
b = Number(x.d);
} while (a !== 0n);
return res;
}
console.log("1 / " + egyptian(521, 1050).join(" + 1 / "));

View File

@ -0,0 +1,111 @@
/*
Fraction.js v5.0.0 10/1/2024
https://raw.org/article/rational-numbers-in-javascript/
Copyright (c) 2024, Robert Eisele (https://raw.org/)
Licensed under the MIT license.
*/
const Fraction = require('fraction.js');
/*
We have the polynom f(x) = 1/3x_1^2 + x_2^2 + x_1 * x_2 + 3
The gradient of f(x):
grad(x) = | x_1^2+x_2 |
| 2x_2+x_1 |
And thus the Hesse-Matrix H:
| 2x_1 1 |
| 1 2 |
The inverse Hesse-Matrix H^-1 is
| -2 / (1-4x_1) 1 / (1 - 4x_1) |
| 1 / (1 - 4x_1) -2x_1 / (1 - 4x_1) |
We now want to find lim ->oo x[n], with the starting element of (3 2)^T
*/
// Get the Hesse Matrix
function H(x) {
var z = Fraction(1).sub(Fraction(4).mul(x[0]));
return [
Fraction(-2).div(z),
Fraction(1).div(z),
Fraction(1).div(z),
Fraction(-2).mul(x[0]).div(z),
];
}
// Get the gradient of f(x)
function grad(x) {
return [
Fraction(x[0]).mul(x[0]).add(x[1]),
Fraction(2).mul(x[1]).add(x[0])
];
}
// A simple matrix multiplication helper
function matrMult(m, v) {
return [
Fraction(m[0]).mul(v[0]).add(Fraction(m[1]).mul(v[1])),
Fraction(m[2]).mul(v[0]).add(Fraction(m[3]).mul(v[1]))
];
}
// A simple vector subtraction helper
function vecSub(a, b) {
return [
Fraction(a[0]).sub(b[0]),
Fraction(a[1]).sub(b[1])
];
}
// Main function, gets a vector and the actual index
function run(V, j) {
var t = H(V);
//console.log("H(X)");
for (var i in t) {
// console.log(t[i].toFraction());
}
var s = grad(V);
//console.log("vf(X)");
for (var i in s) {
// console.log(s[i].toFraction());
}
//console.log("multiplication");
var r = matrMult(t, s);
for (var i in r) {
// console.log(r[i].toFraction());
}
var R = (vecSub(V, r));
console.log("X" + j);
console.log(R[0].toFraction(), "= " + R[0].valueOf());
console.log(R[1].toFraction(), "= " + R[1].valueOf());
console.log("\n");
return R;
}
// Set the starting vector
var v = [3, 2];
for (var i = 0; i < 15; i++) {
v = run(v, i);
}

View File

@ -0,0 +1,67 @@
/*
Fraction.js v5.0.0 10/1/2024
https://raw.org/article/rational-numbers-in-javascript/
Copyright (c) 2024, Robert Eisele (https://raw.org/)
Licensed under the MIT license.
*/
const Fraction = require('fraction.js');
// NOTE: This is a nice example, but a stable version of this is served with Polynomial.js:
// https://github.com/rawify/Polynomial.js
function integrate(poly) {
poly = poly.replace(/\s+/g, "");
var regex = /(\([+-]?[0-9/]+\)|[+-]?[0-9/]+)x(?:\^(\([+-]?[0-9/]+\)|[+-]?[0-9]+))?/g;
var arr;
var res = {};
while (null !== (arr = regex.exec(poly))) {
var a = (arr[1] || "1").replace("(", "").replace(")", "").split("/");
var b = (arr[2] || "1").replace("(", "").replace(")", "").split("/");
var exp = new Fraction(b).add(1);
var key = "" + exp;
if (res[key] !== undefined) {
res[key] = { x: new Fraction(a).div(exp).add(res[key].x), e: exp };
} else {
res[key] = { x: new Fraction(a).div(exp), e: exp };
}
}
var str = "";
var c = 0;
for (var i in res) {
if (res[i].x.s !== -1n && c > 0) {
str += "+";
} else if (res[i].x.s === -1n) {
str += "-";
}
if (res[i].x.n !== res[i].x.d) {
if (res[i].x.d !== 1n) {
str += res[i].x.n + "/" + res[i].x.d;
} else {
str += res[i].x.n;
}
}
str += "x";
if (res[i].e.n !== res[i].e.d) {
str += "^";
if (res[i].e.d !== 1n) {
str += "(" + res[i].e.n + "/" + res[i].e.d + ")";
} else {
str += res[i].e.n;
}
}
c++;
}
return str;
}
var poly = "-2/3x^3-2x^2+3x+8x^3-1/3x^(4/8)";
console.log("f(x): " + poly);
console.log("F(x): " + integrate(poly));

View File

@ -0,0 +1,24 @@
/*
Given the ratio a : b : c = 2 : 3 : 4
What is c, given a = 40?
A general ratio chain is a_1 : a_2 : a_3 : ... : a_n = r_1 : r2 : r_3 : ... : r_n.
Now each term can be expressed as a_i = r_i * x for some unknown proportional constant x.
If a_k is known it follows that x = a_k / r_k. Substituting x into the first equation yields
a_i = r_i / r_k * a_k.
Given an array r and a given value a_k, the following function calculates all a_i:
*/
function calculateRatios(r, a_k, k) {
const x = Fraction(a_k).div(r[k]);
return r.map(r_i => x.mul(r_i));
}
// Example usage:
const r = [2, 3, 4]; // Ratio array representing a : b : c = 2 : 3 : 4
const a_k = 40; // Given value of a (corresponding to r[0])
const k = 0; // Index of the known value (a corresponds to r[0])
const result = calculateRatios(r, a_k, k);
console.log(result); // Output: [40, 60, 80]

View File

@ -0,0 +1,29 @@
/*
Fraction.js v5.0.0 10/1/2024
https://raw.org/article/rational-numbers-in-javascript/
Copyright (c) 2024, Robert Eisele (https://raw.org/)
Licensed under the MIT license.
*/
const Fraction = require('fraction.js');
// Calculates (a/b)^(c/d) if result is rational
// Derivation: https://raw.org/book/analysis/rational-numbers/
function root(a, b, c, d) {
// Initial estimate
let x = Fraction(100 * (Math.floor(Math.pow(a / b, c / d)) || 1), 100);
const abc = Fraction(a, b).pow(c);
for (let i = 0; i < 30; i++) {
const n = abc.mul(x.pow(1 - d)).sub(x).div(d).add(x)
if (x.n === n.n && x.d === n.d) {
return n;
}
x = n;
}
return null;
}
root(18, 2, 1, 2); // 3/1

View File

@ -0,0 +1,16 @@
/*
Fraction.js v5.0.0 10/1/2024
https://raw.org/article/rational-numbers-in-javascript/
Copyright (c) 2024, Robert Eisele (https://raw.org/)
Licensed under the MIT license.
*/
const Fraction = require('fraction.js');
function closestTapeMeasure(frac) {
// A tape measure is usually divided in parts of 1/16
return Fraction(frac).roundTo("1/16");
}
console.log(closestTapeMeasure("1/3")); // 5/16

View File

@ -0,0 +1,35 @@
/*
Fraction.js v5.0.0 10/1/2024
https://raw.org/article/rational-numbers-in-javascript/
Copyright (c) 2024, Robert Eisele (https://raw.org/)
Licensed under the MIT license.
*/
const Fraction = require('fraction.js');
function toFraction(frac) {
var map = {
'1:4': "¼",
'1:2': "½",
'3:4': "¾",
'1:7': "⅐",
'1:9': "⅑",
'1:10': "⅒",
'1:3': "⅓",
'2:3': "⅔",
'1:5': "⅕",
'2:5': "⅖",
'3:5': "⅗",
'4:5': "⅘",
'1:6': "⅙",
'5:6': "⅚",
'1:8': "⅛",
'3:8': "⅜",
'5:8': "⅝",
'7:8': "⅞"
};
return map[frac.n + ":" + frac.d] || frac.toFraction(false);
}
console.log(toFraction(Fraction(0.25))); // ¼

View File

@ -0,0 +1,42 @@
/*
Fraction.js v5.0.0 10/1/2024
https://raw.org/article/rational-numbers-in-javascript/
Copyright (c) 2024, Robert Eisele (https://raw.org/)
Licensed under the MIT license.
*/
var Fraction = require("fraction.js")
function valueOfPi(val) {
let minLen = Infinity, minI = 0, min = null;
const choose = [val, val * Math.PI, val / Math.PI];
for (let i = 0; i < choose.length; i++) {
let el = new Fraction(choose[i]).simplify(1e-13);
let len = Math.log(Number(el.n) + 1) + Math.log(Number(el.d));
if (len < minLen) {
minLen = len;
minI = i;
min = el;
}
}
if (minI == 2) {
return min.toFraction().replace(/(\d+)(\/\d+)?/, (_, p, q) =>
(p == "1" ? "" : p) + "π" + (q || ""));
}
if (minI == 1) {
return min.toFraction().replace(/(\d+)(\/\d+)?/, (_, p, q) =>
p + (!q ? "/π" : "/(" + q.slice(1) + "π)"));
}
return min.toFraction();
}
console.log(valueOfPi(-3)); // -3
console.log(valueOfPi(4 * Math.PI)); // 4π
console.log(valueOfPi(3.14)); // 157/50
console.log(valueOfPi(3 / 2 * Math.PI)); // 3π/2
console.log(valueOfPi(Math.PI / 2)); // π/2
console.log(valueOfPi(-1 / (2 * Math.PI))); // -1/(2π)

View File

@ -1,904 +0,0 @@
/**
* @license Fraction.js v4.3.7 31/08/2023
* https://www.xarg.org/2014/03/rational-numbers-in-javascript/
*
* Copyright (c) 2023, Robert Eisele (robert@raw.org)
* Dual licensed under the MIT or GPL Version 2 licenses.
**/
/**
*
* This class offers the possibility to calculate fractions.
* You can pass a fraction in different formats. Either as array, as double, as string or as an integer.
*
* Array/Object form
* [ 0 => <numerator>, 1 => <denominator> ]
* [ n => <numerator>, d => <denominator> ]
*
* Integer form
* - Single integer value
*
* Double form
* - Single double value
*
* String form
* 123.456 - a simple double
* 123/456 - a string fraction
* 123.'456' - a double with repeating decimal places
* 123.(456) - synonym
* 123.45'6' - a double with repeating last place
* 123.45(6) - synonym
*
* Example:
*
* var f = new Fraction("9.4'31'");
* f.mul([-4, 3]).div(4.9);
*
*/
(function(root) {
"use strict";
// Maximum search depth for cyclic rational numbers. 2000 should be more than enough.
// Example: 1/7 = 0.(142857) has 6 repeating decimal places.
// If MAX_CYCLE_LEN gets reduced, long cycles will not be detected and toString() only gets the first 10 digits
var MAX_CYCLE_LEN = 2000;
// Parsed data to avoid calling "new" all the time
var P = {
"s": 1,
"n": 0,
"d": 1
};
function assign(n, s) {
if (isNaN(n = parseInt(n, 10))) {
throw InvalidParameter();
}
return n * s;
}
// Creates a new Fraction internally without the need of the bulky constructor
function newFraction(n, d) {
if (d === 0) {
throw DivisionByZero();
}
var f = Object.create(Fraction.prototype);
f["s"] = n < 0 ? -1 : 1;
n = n < 0 ? -n : n;
var a = gcd(n, d);
f["n"] = n / a;
f["d"] = d / a;
return f;
}
function factorize(num) {
var factors = {};
var n = num;
var i = 2;
var s = 4;
while (s <= n) {
while (n % i === 0) {
n/= i;
factors[i] = (factors[i] || 0) + 1;
}
s+= 1 + 2 * i++;
}
if (n !== num) {
if (n > 1)
factors[n] = (factors[n] || 0) + 1;
} else {
factors[num] = (factors[num] || 0) + 1;
}
return factors;
}
var parse = function(p1, p2) {
var n = 0, d = 1, s = 1;
var v = 0, w = 0, x = 0, y = 1, z = 1;
var A = 0, B = 1;
var C = 1, D = 1;
var N = 10000000;
var M;
if (p1 === undefined || p1 === null) {
/* void */
} else if (p2 !== undefined) {
n = p1;
d = p2;
s = n * d;
if (n % 1 !== 0 || d % 1 !== 0) {
throw NonIntegerParameter();
}
} else
switch (typeof p1) {
case "object":
{
if ("d" in p1 && "n" in p1) {
n = p1["n"];
d = p1["d"];
if ("s" in p1)
n*= p1["s"];
} else if (0 in p1) {
n = p1[0];
if (1 in p1)
d = p1[1];
} else {
throw InvalidParameter();
}
s = n * d;
break;
}
case "number":
{
if (p1 < 0) {
s = p1;
p1 = -p1;
}
if (p1 % 1 === 0) {
n = p1;
} else if (p1 > 0) { // check for != 0, scale would become NaN (log(0)), which converges really slow
if (p1 >= 1) {
z = Math.pow(10, Math.floor(1 + Math.log(p1) / Math.LN10));
p1/= z;
}
// Using Farey Sequences
// http://www.johndcook.com/blog/2010/10/20/best-rational-approximation/
while (B <= N && D <= N) {
M = (A + C) / (B + D);
if (p1 === M) {
if (B + D <= N) {
n = A + C;
d = B + D;
} else if (D > B) {
n = C;
d = D;
} else {
n = A;
d = B;
}
break;
} else {
if (p1 > M) {
A+= C;
B+= D;
} else {
C+= A;
D+= B;
}
if (B > N) {
n = C;
d = D;
} else {
n = A;
d = B;
}
}
}
n*= z;
} else if (isNaN(p1) || isNaN(p2)) {
d = n = NaN;
}
break;
}
case "string":
{
B = p1.match(/\d+|./g);
if (B === null)
throw InvalidParameter();
if (B[A] === '-') {// Check for minus sign at the beginning
s = -1;
A++;
} else if (B[A] === '+') {// Check for plus sign at the beginning
A++;
}
if (B.length === A + 1) { // Check if it's just a simple number "1234"
w = assign(B[A++], s);
} else if (B[A + 1] === '.' || B[A] === '.') { // Check if it's a decimal number
if (B[A] !== '.') { // Handle 0.5 and .5
v = assign(B[A++], s);
}
A++;
// Check for decimal places
if (A + 1 === B.length || B[A + 1] === '(' && B[A + 3] === ')' || B[A + 1] === "'" && B[A + 3] === "'") {
w = assign(B[A], s);
y = Math.pow(10, B[A].length);
A++;
}
// Check for repeating places
if (B[A] === '(' && B[A + 2] === ')' || B[A] === "'" && B[A + 2] === "'") {
x = assign(B[A + 1], s);
z = Math.pow(10, B[A + 1].length) - 1;
A+= 3;
}
} else if (B[A + 1] === '/' || B[A + 1] === ':') { // Check for a simple fraction "123/456" or "123:456"
w = assign(B[A], s);
y = assign(B[A + 2], 1);
A+= 3;
} else if (B[A + 3] === '/' && B[A + 1] === ' ') { // Check for a complex fraction "123 1/2"
v = assign(B[A], s);
w = assign(B[A + 2], s);
y = assign(B[A + 4], 1);
A+= 5;
}
if (B.length <= A) { // Check for more tokens on the stack
d = y * z;
s = /* void */
n = x + d * v + z * w;
break;
}
/* Fall through on error */
}
default:
throw InvalidParameter();
}
if (d === 0) {
throw DivisionByZero();
}
P["s"] = s < 0 ? -1 : 1;
P["n"] = Math.abs(n);
P["d"] = Math.abs(d);
};
function modpow(b, e, m) {
var r = 1;
for (; e > 0; b = (b * b) % m, e >>= 1) {
if (e & 1) {
r = (r * b) % m;
}
}
return r;
}
function cycleLen(n, d) {
for (; d % 2 === 0;
d/= 2) {
}
for (; d % 5 === 0;
d/= 5) {
}
if (d === 1) // Catch non-cyclic numbers
return 0;
// If we would like to compute really large numbers quicker, we could make use of Fermat's little theorem:
// 10^(d-1) % d == 1
// However, we don't need such large numbers and MAX_CYCLE_LEN should be the capstone,
// as we want to translate the numbers to strings.
var rem = 10 % d;
var t = 1;
for (; rem !== 1; t++) {
rem = rem * 10 % d;
if (t > MAX_CYCLE_LEN)
return 0; // Returning 0 here means that we don't print it as a cyclic number. It's likely that the answer is `d-1`
}
return t;
}
function cycleStart(n, d, len) {
var rem1 = 1;
var rem2 = modpow(10, len, d);
for (var t = 0; t < 300; t++) { // s < ~log10(Number.MAX_VALUE)
// Solve 10^s == 10^(s+t) (mod d)
if (rem1 === rem2)
return t;
rem1 = rem1 * 10 % d;
rem2 = rem2 * 10 % d;
}
return 0;
}
function gcd(a, b) {
if (!a)
return b;
if (!b)
return a;
while (1) {
a%= b;
if (!a)
return b;
b%= a;
if (!b)
return a;
}
};
/**
* Module constructor
*
* @constructor
* @param {number|Fraction=} a
* @param {number=} b
*/
function Fraction(a, b) {
parse(a, b);
if (this instanceof Fraction) {
a = gcd(P["d"], P["n"]); // Abuse variable a
this["s"] = P["s"];
this["n"] = P["n"] / a;
this["d"] = P["d"] / a;
} else {
return newFraction(P['s'] * P['n'], P['d']);
}
}
var DivisionByZero = function() { return new Error("Division by Zero"); };
var InvalidParameter = function() { return new Error("Invalid argument"); };
var NonIntegerParameter = function() { return new Error("Parameters must be integer"); };
Fraction.prototype = {
"s": 1,
"n": 0,
"d": 1,
/**
* Calculates the absolute value
*
* Ex: new Fraction(-4).abs() => 4
**/
"abs": function() {
return newFraction(this["n"], this["d"]);
},
/**
* Inverts the sign of the current fraction
*
* Ex: new Fraction(-4).neg() => 4
**/
"neg": function() {
return newFraction(-this["s"] * this["n"], this["d"]);
},
/**
* Adds two rational numbers
*
* Ex: new Fraction({n: 2, d: 3}).add("14.9") => 467 / 30
**/
"add": function(a, b) {
parse(a, b);
return newFraction(
this["s"] * this["n"] * P["d"] + P["s"] * this["d"] * P["n"],
this["d"] * P["d"]
);
},
/**
* Subtracts two rational numbers
*
* Ex: new Fraction({n: 2, d: 3}).add("14.9") => -427 / 30
**/
"sub": function(a, b) {
parse(a, b);
return newFraction(
this["s"] * this["n"] * P["d"] - P["s"] * this["d"] * P["n"],
this["d"] * P["d"]
);
},
/**
* Multiplies two rational numbers
*
* Ex: new Fraction("-17.(345)").mul(3) => 5776 / 111
**/
"mul": function(a, b) {
parse(a, b);
return newFraction(
this["s"] * P["s"] * this["n"] * P["n"],
this["d"] * P["d"]
);
},
/**
* Divides two rational numbers
*
* Ex: new Fraction("-17.(345)").inverse().div(3)
**/
"div": function(a, b) {
parse(a, b);
return newFraction(
this["s"] * P["s"] * this["n"] * P["d"],
this["d"] * P["n"]
);
},
/**
* Clones the actual object
*
* Ex: new Fraction("-17.(345)").clone()
**/
"clone": function() {
return newFraction(this['s'] * this['n'], this['d']);
},
/**
* Calculates the modulo of two rational numbers - a more precise fmod
*
* Ex: new Fraction('4.(3)').mod([7, 8]) => (13/3) % (7/8) = (5/6)
**/
"mod": function(a, b) {
if (isNaN(this['n']) || isNaN(this['d'])) {
return new Fraction(NaN);
}
if (a === undefined) {
return newFraction(this["s"] * this["n"] % this["d"], 1);
}
parse(a, b);
if (0 === P["n"] && 0 === this["d"]) {
throw DivisionByZero();
}
/*
* First silly attempt, kinda slow
*
return that["sub"]({
"n": num["n"] * Math.floor((this.n / this.d) / (num.n / num.d)),
"d": num["d"],
"s": this["s"]
});*/
/*
* New attempt: a1 / b1 = a2 / b2 * q + r
* => b2 * a1 = a2 * b1 * q + b1 * b2 * r
* => (b2 * a1 % a2 * b1) / (b1 * b2)
*/
return newFraction(
this["s"] * (P["d"] * this["n"]) % (P["n"] * this["d"]),
P["d"] * this["d"]
);
},
/**
* Calculates the fractional gcd of two rational numbers
*
* Ex: new Fraction(5,8).gcd(3,7) => 1/56
*/
"gcd": function(a, b) {
parse(a, b);
// gcd(a / b, c / d) = gcd(a, c) / lcm(b, d)
return newFraction(gcd(P["n"], this["n"]) * gcd(P["d"], this["d"]), P["d"] * this["d"]);
},
/**
* Calculates the fractional lcm of two rational numbers
*
* Ex: new Fraction(5,8).lcm(3,7) => 15
*/
"lcm": function(a, b) {
parse(a, b);
// lcm(a / b, c / d) = lcm(a, c) / gcd(b, d)
if (P["n"] === 0 && this["n"] === 0) {
return newFraction(0, 1);
}
return newFraction(P["n"] * this["n"], gcd(P["n"], this["n"]) * gcd(P["d"], this["d"]));
},
/**
* Calculates the ceil of a rational number
*
* Ex: new Fraction('4.(3)').ceil() => (5 / 1)
**/
"ceil": function(places) {
places = Math.pow(10, places || 0);
if (isNaN(this["n"]) || isNaN(this["d"])) {
return new Fraction(NaN);
}
return newFraction(Math.ceil(places * this["s"] * this["n"] / this["d"]), places);
},
/**
* Calculates the floor of a rational number
*
* Ex: new Fraction('4.(3)').floor() => (4 / 1)
**/
"floor": function(places) {
places = Math.pow(10, places || 0);
if (isNaN(this["n"]) || isNaN(this["d"])) {
return new Fraction(NaN);
}
return newFraction(Math.floor(places * this["s"] * this["n"] / this["d"]), places);
},
/**
* Rounds a rational numbers
*
* Ex: new Fraction('4.(3)').round() => (4 / 1)
**/
"round": function(places) {
places = Math.pow(10, places || 0);
if (isNaN(this["n"]) || isNaN(this["d"])) {
return new Fraction(NaN);
}
return newFraction(Math.round(places * this["s"] * this["n"] / this["d"]), places);
},
/**
* Rounds a rational number to a multiple of another rational number
*
* Ex: new Fraction('0.9').roundTo("1/8") => 7 / 8
**/
"roundTo": function(a, b) {
/*
k * x/y ≤ a/b < (k+1) * x/y
⇔ k ≤ a/b / (x/y) < (k+1)
⇔ k = floor(a/b * y/x)
*/
parse(a, b);
return newFraction(this['s'] * Math.round(this['n'] * P['d'] / (this['d'] * P['n'])) * P['n'], P['d']);
},
/**
* Gets the inverse of the fraction, means numerator and denominator are exchanged
*
* Ex: new Fraction([-3, 4]).inverse() => -4 / 3
**/
"inverse": function() {
return newFraction(this["s"] * this["d"], this["n"]);
},
/**
* Calculates the fraction to some rational exponent, if possible
*
* Ex: new Fraction(-1,2).pow(-3) => -8
*/
"pow": function(a, b) {
parse(a, b);
// Trivial case when exp is an integer
if (P['d'] === 1) {
if (P['s'] < 0) {
return newFraction(Math.pow(this['s'] * this["d"], P['n']), Math.pow(this["n"], P['n']));
} else {
return newFraction(Math.pow(this['s'] * this["n"], P['n']), Math.pow(this["d"], P['n']));
}
}
// Negative roots become complex
// (-a/b)^(c/d) = x
// <=> (-1)^(c/d) * (a/b)^(c/d) = x
// <=> (cos(pi) + i*sin(pi))^(c/d) * (a/b)^(c/d) = x # rotate 1 by 180°
// <=> (cos(c*pi/d) + i*sin(c*pi/d)) * (a/b)^(c/d) = x # DeMoivre's formula in Q ( https://proofwiki.org/wiki/De_Moivre%27s_Formula/Rational_Index )
// From which follows that only for c=0 the root is non-complex. c/d is a reduced fraction, so that sin(c/dpi)=0 occurs for d=1, which is handled by our trivial case.
if (this['s'] < 0) return null;
// Now prime factor n and d
var N = factorize(this['n']);
var D = factorize(this['d']);
// Exponentiate and take root for n and d individually
var n = 1;
var d = 1;
for (var k in N) {
if (k === '1') continue;
if (k === '0') {
n = 0;
break;
}
N[k]*= P['n'];
if (N[k] % P['d'] === 0) {
N[k]/= P['d'];
} else return null;
n*= Math.pow(k, N[k]);
}
for (var k in D) {
if (k === '1') continue;
D[k]*= P['n'];
if (D[k] % P['d'] === 0) {
D[k]/= P['d'];
} else return null;
d*= Math.pow(k, D[k]);
}
if (P['s'] < 0) {
return newFraction(d, n);
}
return newFraction(n, d);
},
/**
* Check if two rational numbers are the same
*
* Ex: new Fraction(19.6).equals([98, 5]);
**/
"equals": function(a, b) {
parse(a, b);
return this["s"] * this["n"] * P["d"] === P["s"] * P["n"] * this["d"]; // Same as compare() === 0
},
/**
* Check if two rational numbers are the same
*
* Ex: new Fraction(19.6).equals([98, 5]);
**/
"compare": function(a, b) {
parse(a, b);
var t = (this["s"] * this["n"] * P["d"] - P["s"] * P["n"] * this["d"]);
return (0 < t) - (t < 0);
},
"simplify": function(eps) {
if (isNaN(this['n']) || isNaN(this['d'])) {
return this;
}
eps = eps || 0.001;
var thisABS = this['abs']();
var cont = thisABS['toContinued']();
for (var i = 1; i < cont.length; i++) {
var s = newFraction(cont[i - 1], 1);
for (var k = i - 2; k >= 0; k--) {
s = s['inverse']()['add'](cont[k]);
}
if (Math.abs(s['sub'](thisABS).valueOf()) < eps) {
return s['mul'](this['s']);
}
}
return this;
},
/**
* Check if two rational numbers are divisible
*
* Ex: new Fraction(19.6).divisible(1.5);
*/
"divisible": function(a, b) {
parse(a, b);
return !(!(P["n"] * this["d"]) || ((this["n"] * P["d"]) % (P["n"] * this["d"])));
},
/**
* Returns a decimal representation of the fraction
*
* Ex: new Fraction("100.'91823'").valueOf() => 100.91823918239183
**/
'valueOf': function() {
return this["s"] * this["n"] / this["d"];
},
/**
* Returns a string-fraction representation of a Fraction object
*
* Ex: new Fraction("1.'3'").toFraction(true) => "4 1/3"
**/
'toFraction': function(excludeWhole) {
var whole, str = "";
var n = this["n"];
var d = this["d"];
if (this["s"] < 0) {
str+= '-';
}
if (d === 1) {
str+= n;
} else {
if (excludeWhole && (whole = Math.floor(n / d)) > 0) {
str+= whole;
str+= " ";
n%= d;
}
str+= n;
str+= '/';
str+= d;
}
return str;
},
/**
* Returns a latex representation of a Fraction object
*
* Ex: new Fraction("1.'3'").toLatex() => "\frac{4}{3}"
**/
'toLatex': function(excludeWhole) {
var whole, str = "";
var n = this["n"];
var d = this["d"];
if (this["s"] < 0) {
str+= '-';
}
if (d === 1) {
str+= n;
} else {
if (excludeWhole && (whole = Math.floor(n / d)) > 0) {
str+= whole;
n%= d;
}
str+= "\\frac{";
str+= n;
str+= '}{';
str+= d;
str+= '}';
}
return str;
},
/**
* Returns an array of continued fraction elements
*
* Ex: new Fraction("7/8").toContinued() => [0,1,7]
*/
'toContinued': function() {
var t;
var a = this['n'];
var b = this['d'];
var res = [];
if (isNaN(a) || isNaN(b)) {
return res;
}
do {
res.push(Math.floor(a / b));
t = a % b;
a = b;
b = t;
} while (a !== 1);
return res;
},
/**
* Creates a string representation of a fraction with all digits
*
* Ex: new Fraction("100.'91823'").toString() => "100.(91823)"
**/
'toString': function(dec) {
var N = this["n"];
var D = this["d"];
if (isNaN(N) || isNaN(D)) {
return "NaN";
}
dec = dec || 15; // 15 = decimal places when no repetation
var cycLen = cycleLen(N, D); // Cycle length
var cycOff = cycleStart(N, D, cycLen); // Cycle start
var str = this['s'] < 0 ? "-" : "";
str+= N / D | 0;
N%= D;
N*= 10;
if (N)
str+= ".";
if (cycLen) {
for (var i = cycOff; i--;) {
str+= N / D | 0;
N%= D;
N*= 10;
}
str+= "(";
for (var i = cycLen; i--;) {
str+= N / D | 0;
N%= D;
N*= 10;
}
str+= ")";
} else {
for (var i = dec; N && i--;) {
str+= N / D | 0;
N%= D;
N*= 10;
}
}
return str;
}
};
if (typeof exports === "object") {
Object.defineProperty(exports, "__esModule", { 'value': true });
exports['default'] = Fraction;
module['exports'] = Fraction;
} else {
root['Fraction'] = Fraction;
}
})(this);

79
frontend/node_modules/fraction.js/fraction.d.mts generated vendored Normal file
View File

@ -0,0 +1,79 @@
/**
* Interface representing a fraction with numerator and denominator.
*/
export interface NumeratorDenominator {
n: number | bigint;
d: number | bigint;
}
/**
* Type for handling multiple types of input for Fraction operations.
*/
export type FractionInput =
| Fraction
| number
| bigint
| string
| [number | bigint | string, number | bigint | string]
| NumeratorDenominator;
/**
* Function signature for Fraction operations like add, sub, mul, etc.
*/
export type FractionParam = {
(numerator: number | bigint, denominator: number | bigint): Fraction;
(num: FractionInput): Fraction;
};
/**
* Fraction class representing a rational number with numerator and denominator.
*/
declare class Fraction {
constructor();
constructor(num: FractionInput);
constructor(numerator: number | bigint, denominator: number | bigint);
s: bigint;
n: bigint;
d: bigint;
abs(): Fraction;
neg(): Fraction;
add: FractionParam;
sub: FractionParam;
mul: FractionParam;
div: FractionParam;
pow: FractionParam;
log: FractionParam;
gcd: FractionParam;
lcm: FractionParam;
mod(): Fraction;
mod(num: FractionInput): Fraction;
ceil(places?: number): Fraction;
floor(places?: number): Fraction;
round(places?: number): Fraction;
roundTo: FractionParam;
inverse(): Fraction;
simplify(eps?: number): Fraction;
equals(num: FractionInput): boolean;
lt(num: FractionInput): boolean;
lte(num: FractionInput): boolean;
gt(num: FractionInput): boolean;
gte(num: FractionInput): boolean;
compare(num: FractionInput): number;
divisible(num: FractionInput): boolean;
valueOf(): number;
toString(decimalPlaces?: number): string;
toLatex(showMixed?: boolean): string;
toFraction(showMixed?: boolean): string;
toContinued(): bigint[];
clone(): Fraction;
}
export { Fraction as default, Fraction };

View File

@ -1,60 +1,79 @@
declare module 'Fraction';
declare class Fraction {
constructor();
constructor(num: Fraction.FractionInput);
constructor(numerator: number | bigint, denominator: number | bigint);
export interface NumeratorDenominator {
n: number;
d: number;
}
type FractionConstructor = {
(fraction: Fraction): Fraction;
(num: number | string): Fraction;
(numerator: number, denominator: number): Fraction;
(numbers: [number | string, number | string]): Fraction;
(fraction: NumeratorDenominator): Fraction;
(firstValue: Fraction | number | string | [number | string, number | string] | NumeratorDenominator, secondValue?: number): Fraction;
};
export default class Fraction {
constructor (fraction: Fraction);
constructor (num: number | string);
constructor (numerator: number, denominator: number);
constructor (numbers: [number | string, number | string]);
constructor (fraction: NumeratorDenominator);
constructor (firstValue: Fraction | number | string | [number | string, number | string] | NumeratorDenominator, secondValue?: number);
s: number;
n: number;
d: number;
s: bigint;
n: bigint;
d: bigint;
abs(): Fraction;
neg(): Fraction;
add: FractionConstructor;
sub: FractionConstructor;
mul: FractionConstructor;
div: FractionConstructor;
pow: FractionConstructor;
gcd: FractionConstructor;
lcm: FractionConstructor;
mod(n?: number | string | Fraction): Fraction;
add: Fraction.FractionParam;
sub: Fraction.FractionParam;
mul: Fraction.FractionParam;
div: Fraction.FractionParam;
pow: Fraction.FractionParam;
log: Fraction.FractionParam;
gcd: Fraction.FractionParam;
lcm: Fraction.FractionParam;
mod(): Fraction;
mod(num: Fraction.FractionInput): Fraction;
ceil(places?: number): Fraction;
floor(places?: number): Fraction;
round(places?: number): Fraction;
roundTo: Fraction.FractionParam;
inverse(): Fraction;
simplify(eps?: number): Fraction;
equals(n: number | string | Fraction): boolean;
compare(n: number | string | Fraction): number;
divisible(n: number | string | Fraction): boolean;
equals(num: Fraction.FractionInput): boolean;
lt(num: Fraction.FractionInput): boolean;
lte(num: Fraction.FractionInput): boolean;
gt(num: Fraction.FractionInput): boolean;
gte(num: Fraction.FractionInput): boolean;
compare(num: Fraction.FractionInput): number;
divisible(num: Fraction.FractionInput): boolean;
valueOf(): number;
toString(decimalPlaces?: number): string;
toLatex(excludeWhole?: boolean): string;
toFraction(excludeWhole?: boolean): string;
toContinued(): number[];
toLatex(showMixed?: boolean): string;
toFraction(showMixed?: boolean): string;
toContinued(): bigint[];
clone(): Fraction;
static default: typeof Fraction;
static Fraction: typeof Fraction;
}
declare namespace Fraction {
interface NumeratorDenominator { n: number | bigint; d: number | bigint; }
type FractionInput =
| Fraction
| number
| bigint
| string
| [number | bigint | string, number | bigint | string]
| NumeratorDenominator;
type FractionParam = {
(numerator: number | bigint, denominator: number | bigint): Fraction;
(num: FractionInput): Fraction;
};
}
/**
* Export matches CJS runtime:
* module.exports = Fraction;
* module.exports.default = Fraction;
* module.exports.Fraction = Fraction;
*/
declare const FractionExport: typeof Fraction & {
default: typeof Fraction;
Fraction: typeof Fraction;
};
export = FractionExport;

View File

@ -1,891 +0,0 @@
/**
* @license Fraction.js v4.3.7 31/08/2023
* https://www.xarg.org/2014/03/rational-numbers-in-javascript/
*
* Copyright (c) 2023, Robert Eisele (robert@raw.org)
* Dual licensed under the MIT or GPL Version 2 licenses.
**/
/**
*
* This class offers the possibility to calculate fractions.
* You can pass a fraction in different formats. Either as array, as double, as string or as an integer.
*
* Array/Object form
* [ 0 => <numerator>, 1 => <denominator> ]
* [ n => <numerator>, d => <denominator> ]
*
* Integer form
* - Single integer value
*
* Double form
* - Single double value
*
* String form
* 123.456 - a simple double
* 123/456 - a string fraction
* 123.'456' - a double with repeating decimal places
* 123.(456) - synonym
* 123.45'6' - a double with repeating last place
* 123.45(6) - synonym
*
* Example:
*
* var f = new Fraction("9.4'31'");
* f.mul([-4, 3]).div(4.9);
*
*/
// Maximum search depth for cyclic rational numbers. 2000 should be more than enough.
// Example: 1/7 = 0.(142857) has 6 repeating decimal places.
// If MAX_CYCLE_LEN gets reduced, long cycles will not be detected and toString() only gets the first 10 digits
var MAX_CYCLE_LEN = 2000;
// Parsed data to avoid calling "new" all the time
var P = {
"s": 1,
"n": 0,
"d": 1
};
function assign(n, s) {
if (isNaN(n = parseInt(n, 10))) {
throw InvalidParameter();
}
return n * s;
}
// Creates a new Fraction internally without the need of the bulky constructor
function newFraction(n, d) {
if (d === 0) {
throw DivisionByZero();
}
var f = Object.create(Fraction.prototype);
f["s"] = n < 0 ? -1 : 1;
n = n < 0 ? -n : n;
var a = gcd(n, d);
f["n"] = n / a;
f["d"] = d / a;
return f;
}
function factorize(num) {
var factors = {};
var n = num;
var i = 2;
var s = 4;
while (s <= n) {
while (n % i === 0) {
n/= i;
factors[i] = (factors[i] || 0) + 1;
}
s+= 1 + 2 * i++;
}
if (n !== num) {
if (n > 1)
factors[n] = (factors[n] || 0) + 1;
} else {
factors[num] = (factors[num] || 0) + 1;
}
return factors;
}
var parse = function(p1, p2) {
var n = 0, d = 1, s = 1;
var v = 0, w = 0, x = 0, y = 1, z = 1;
var A = 0, B = 1;
var C = 1, D = 1;
var N = 10000000;
var M;
if (p1 === undefined || p1 === null) {
/* void */
} else if (p2 !== undefined) {
n = p1;
d = p2;
s = n * d;
if (n % 1 !== 0 || d % 1 !== 0) {
throw NonIntegerParameter();
}
} else
switch (typeof p1) {
case "object":
{
if ("d" in p1 && "n" in p1) {
n = p1["n"];
d = p1["d"];
if ("s" in p1)
n*= p1["s"];
} else if (0 in p1) {
n = p1[0];
if (1 in p1)
d = p1[1];
} else {
throw InvalidParameter();
}
s = n * d;
break;
}
case "number":
{
if (p1 < 0) {
s = p1;
p1 = -p1;
}
if (p1 % 1 === 0) {
n = p1;
} else if (p1 > 0) { // check for != 0, scale would become NaN (log(0)), which converges really slow
if (p1 >= 1) {
z = Math.pow(10, Math.floor(1 + Math.log(p1) / Math.LN10));
p1/= z;
}
// Using Farey Sequences
// http://www.johndcook.com/blog/2010/10/20/best-rational-approximation/
while (B <= N && D <= N) {
M = (A + C) / (B + D);
if (p1 === M) {
if (B + D <= N) {
n = A + C;
d = B + D;
} else if (D > B) {
n = C;
d = D;
} else {
n = A;
d = B;
}
break;
} else {
if (p1 > M) {
A+= C;
B+= D;
} else {
C+= A;
D+= B;
}
if (B > N) {
n = C;
d = D;
} else {
n = A;
d = B;
}
}
}
n*= z;
} else if (isNaN(p1) || isNaN(p2)) {
d = n = NaN;
}
break;
}
case "string":
{
B = p1.match(/\d+|./g);
if (B === null)
throw InvalidParameter();
if (B[A] === '-') {// Check for minus sign at the beginning
s = -1;
A++;
} else if (B[A] === '+') {// Check for plus sign at the beginning
A++;
}
if (B.length === A + 1) { // Check if it's just a simple number "1234"
w = assign(B[A++], s);
} else if (B[A + 1] === '.' || B[A] === '.') { // Check if it's a decimal number
if (B[A] !== '.') { // Handle 0.5 and .5
v = assign(B[A++], s);
}
A++;
// Check for decimal places
if (A + 1 === B.length || B[A + 1] === '(' && B[A + 3] === ')' || B[A + 1] === "'" && B[A + 3] === "'") {
w = assign(B[A], s);
y = Math.pow(10, B[A].length);
A++;
}
// Check for repeating places
if (B[A] === '(' && B[A + 2] === ')' || B[A] === "'" && B[A + 2] === "'") {
x = assign(B[A + 1], s);
z = Math.pow(10, B[A + 1].length) - 1;
A+= 3;
}
} else if (B[A + 1] === '/' || B[A + 1] === ':') { // Check for a simple fraction "123/456" or "123:456"
w = assign(B[A], s);
y = assign(B[A + 2], 1);
A+= 3;
} else if (B[A + 3] === '/' && B[A + 1] === ' ') { // Check for a complex fraction "123 1/2"
v = assign(B[A], s);
w = assign(B[A + 2], s);
y = assign(B[A + 4], 1);
A+= 5;
}
if (B.length <= A) { // Check for more tokens on the stack
d = y * z;
s = /* void */
n = x + d * v + z * w;
break;
}
/* Fall through on error */
}
default:
throw InvalidParameter();
}
if (d === 0) {
throw DivisionByZero();
}
P["s"] = s < 0 ? -1 : 1;
P["n"] = Math.abs(n);
P["d"] = Math.abs(d);
};
function modpow(b, e, m) {
var r = 1;
for (; e > 0; b = (b * b) % m, e >>= 1) {
if (e & 1) {
r = (r * b) % m;
}
}
return r;
}
function cycleLen(n, d) {
for (; d % 2 === 0;
d/= 2) {
}
for (; d % 5 === 0;
d/= 5) {
}
if (d === 1) // Catch non-cyclic numbers
return 0;
// If we would like to compute really large numbers quicker, we could make use of Fermat's little theorem:
// 10^(d-1) % d == 1
// However, we don't need such large numbers and MAX_CYCLE_LEN should be the capstone,
// as we want to translate the numbers to strings.
var rem = 10 % d;
var t = 1;
for (; rem !== 1; t++) {
rem = rem * 10 % d;
if (t > MAX_CYCLE_LEN)
return 0; // Returning 0 here means that we don't print it as a cyclic number. It's likely that the answer is `d-1`
}
return t;
}
function cycleStart(n, d, len) {
var rem1 = 1;
var rem2 = modpow(10, len, d);
for (var t = 0; t < 300; t++) { // s < ~log10(Number.MAX_VALUE)
// Solve 10^s == 10^(s+t) (mod d)
if (rem1 === rem2)
return t;
rem1 = rem1 * 10 % d;
rem2 = rem2 * 10 % d;
}
return 0;
}
function gcd(a, b) {
if (!a)
return b;
if (!b)
return a;
while (1) {
a%= b;
if (!a)
return b;
b%= a;
if (!b)
return a;
}
};
/**
* Module constructor
*
* @constructor
* @param {number|Fraction=} a
* @param {number=} b
*/
export default function Fraction(a, b) {
parse(a, b);
if (this instanceof Fraction) {
a = gcd(P["d"], P["n"]); // Abuse variable a
this["s"] = P["s"];
this["n"] = P["n"] / a;
this["d"] = P["d"] / a;
} else {
return newFraction(P['s'] * P['n'], P['d']);
}
}
var DivisionByZero = function() { return new Error("Division by Zero"); };
var InvalidParameter = function() { return new Error("Invalid argument"); };
var NonIntegerParameter = function() { return new Error("Parameters must be integer"); };
Fraction.prototype = {
"s": 1,
"n": 0,
"d": 1,
/**
* Calculates the absolute value
*
* Ex: new Fraction(-4).abs() => 4
**/
"abs": function() {
return newFraction(this["n"], this["d"]);
},
/**
* Inverts the sign of the current fraction
*
* Ex: new Fraction(-4).neg() => 4
**/
"neg": function() {
return newFraction(-this["s"] * this["n"], this["d"]);
},
/**
* Adds two rational numbers
*
* Ex: new Fraction({n: 2, d: 3}).add("14.9") => 467 / 30
**/
"add": function(a, b) {
parse(a, b);
return newFraction(
this["s"] * this["n"] * P["d"] + P["s"] * this["d"] * P["n"],
this["d"] * P["d"]
);
},
/**
* Subtracts two rational numbers
*
* Ex: new Fraction({n: 2, d: 3}).add("14.9") => -427 / 30
**/
"sub": function(a, b) {
parse(a, b);
return newFraction(
this["s"] * this["n"] * P["d"] - P["s"] * this["d"] * P["n"],
this["d"] * P["d"]
);
},
/**
* Multiplies two rational numbers
*
* Ex: new Fraction("-17.(345)").mul(3) => 5776 / 111
**/
"mul": function(a, b) {
parse(a, b);
return newFraction(
this["s"] * P["s"] * this["n"] * P["n"],
this["d"] * P["d"]
);
},
/**
* Divides two rational numbers
*
* Ex: new Fraction("-17.(345)").inverse().div(3)
**/
"div": function(a, b) {
parse(a, b);
return newFraction(
this["s"] * P["s"] * this["n"] * P["d"],
this["d"] * P["n"]
);
},
/**
* Clones the actual object
*
* Ex: new Fraction("-17.(345)").clone()
**/
"clone": function() {
return newFraction(this['s'] * this['n'], this['d']);
},
/**
* Calculates the modulo of two rational numbers - a more precise fmod
*
* Ex: new Fraction('4.(3)').mod([7, 8]) => (13/3) % (7/8) = (5/6)
**/
"mod": function(a, b) {
if (isNaN(this['n']) || isNaN(this['d'])) {
return new Fraction(NaN);
}
if (a === undefined) {
return newFraction(this["s"] * this["n"] % this["d"], 1);
}
parse(a, b);
if (0 === P["n"] && 0 === this["d"]) {
throw DivisionByZero();
}
/*
* First silly attempt, kinda slow
*
return that["sub"]({
"n": num["n"] * Math.floor((this.n / this.d) / (num.n / num.d)),
"d": num["d"],
"s": this["s"]
});*/
/*
* New attempt: a1 / b1 = a2 / b2 * q + r
* => b2 * a1 = a2 * b1 * q + b1 * b2 * r
* => (b2 * a1 % a2 * b1) / (b1 * b2)
*/
return newFraction(
this["s"] * (P["d"] * this["n"]) % (P["n"] * this["d"]),
P["d"] * this["d"]
);
},
/**
* Calculates the fractional gcd of two rational numbers
*
* Ex: new Fraction(5,8).gcd(3,7) => 1/56
*/
"gcd": function(a, b) {
parse(a, b);
// gcd(a / b, c / d) = gcd(a, c) / lcm(b, d)
return newFraction(gcd(P["n"], this["n"]) * gcd(P["d"], this["d"]), P["d"] * this["d"]);
},
/**
* Calculates the fractional lcm of two rational numbers
*
* Ex: new Fraction(5,8).lcm(3,7) => 15
*/
"lcm": function(a, b) {
parse(a, b);
// lcm(a / b, c / d) = lcm(a, c) / gcd(b, d)
if (P["n"] === 0 && this["n"] === 0) {
return newFraction(0, 1);
}
return newFraction(P["n"] * this["n"], gcd(P["n"], this["n"]) * gcd(P["d"], this["d"]));
},
/**
* Calculates the ceil of a rational number
*
* Ex: new Fraction('4.(3)').ceil() => (5 / 1)
**/
"ceil": function(places) {
places = Math.pow(10, places || 0);
if (isNaN(this["n"]) || isNaN(this["d"])) {
return new Fraction(NaN);
}
return newFraction(Math.ceil(places * this["s"] * this["n"] / this["d"]), places);
},
/**
* Calculates the floor of a rational number
*
* Ex: new Fraction('4.(3)').floor() => (4 / 1)
**/
"floor": function(places) {
places = Math.pow(10, places || 0);
if (isNaN(this["n"]) || isNaN(this["d"])) {
return new Fraction(NaN);
}
return newFraction(Math.floor(places * this["s"] * this["n"] / this["d"]), places);
},
/**
* Rounds a rational number
*
* Ex: new Fraction('4.(3)').round() => (4 / 1)
**/
"round": function(places) {
places = Math.pow(10, places || 0);
if (isNaN(this["n"]) || isNaN(this["d"])) {
return new Fraction(NaN);
}
return newFraction(Math.round(places * this["s"] * this["n"] / this["d"]), places);
},
/**
* Rounds a rational number to a multiple of another rational number
*
* Ex: new Fraction('0.9').roundTo("1/8") => 7 / 8
**/
"roundTo": function(a, b) {
/*
k * x/y ≤ a/b < (k+1) * x/y
⇔ k ≤ a/b / (x/y) < (k+1)
⇔ k = floor(a/b * y/x)
*/
parse(a, b);
return newFraction(this['s'] * Math.round(this['n'] * P['d'] / (this['d'] * P['n'])) * P['n'], P['d']);
},
/**
* Gets the inverse of the fraction, means numerator and denominator are exchanged
*
* Ex: new Fraction([-3, 4]).inverse() => -4 / 3
**/
"inverse": function() {
return newFraction(this["s"] * this["d"], this["n"]);
},
/**
* Calculates the fraction to some rational exponent, if possible
*
* Ex: new Fraction(-1,2).pow(-3) => -8
*/
"pow": function(a, b) {
parse(a, b);
// Trivial case when exp is an integer
if (P['d'] === 1) {
if (P['s'] < 0) {
return newFraction(Math.pow(this['s'] * this["d"], P['n']), Math.pow(this["n"], P['n']));
} else {
return newFraction(Math.pow(this['s'] * this["n"], P['n']), Math.pow(this["d"], P['n']));
}
}
// Negative roots become complex
// (-a/b)^(c/d) = x
// <=> (-1)^(c/d) * (a/b)^(c/d) = x
// <=> (cos(pi) + i*sin(pi))^(c/d) * (a/b)^(c/d) = x # rotate 1 by 180°
// <=> (cos(c*pi/d) + i*sin(c*pi/d)) * (a/b)^(c/d) = x # DeMoivre's formula in Q ( https://proofwiki.org/wiki/De_Moivre%27s_Formula/Rational_Index )
// From which follows that only for c=0 the root is non-complex. c/d is a reduced fraction, so that sin(c/dpi)=0 occurs for d=1, which is handled by our trivial case.
if (this['s'] < 0) return null;
// Now prime factor n and d
var N = factorize(this['n']);
var D = factorize(this['d']);
// Exponentiate and take root for n and d individually
var n = 1;
var d = 1;
for (var k in N) {
if (k === '1') continue;
if (k === '0') {
n = 0;
break;
}
N[k]*= P['n'];
if (N[k] % P['d'] === 0) {
N[k]/= P['d'];
} else return null;
n*= Math.pow(k, N[k]);
}
for (var k in D) {
if (k === '1') continue;
D[k]*= P['n'];
if (D[k] % P['d'] === 0) {
D[k]/= P['d'];
} else return null;
d*= Math.pow(k, D[k]);
}
if (P['s'] < 0) {
return newFraction(d, n);
}
return newFraction(n, d);
},
/**
* Check if two rational numbers are the same
*
* Ex: new Fraction(19.6).equals([98, 5]);
**/
"equals": function(a, b) {
parse(a, b);
return this["s"] * this["n"] * P["d"] === P["s"] * P["n"] * this["d"]; // Same as compare() === 0
},
/**
* Check if two rational numbers are the same
*
* Ex: new Fraction(19.6).equals([98, 5]);
**/
"compare": function(a, b) {
parse(a, b);
var t = (this["s"] * this["n"] * P["d"] - P["s"] * P["n"] * this["d"]);
return (0 < t) - (t < 0);
},
"simplify": function(eps) {
if (isNaN(this['n']) || isNaN(this['d'])) {
return this;
}
eps = eps || 0.001;
var thisABS = this['abs']();
var cont = thisABS['toContinued']();
for (var i = 1; i < cont.length; i++) {
var s = newFraction(cont[i - 1], 1);
for (var k = i - 2; k >= 0; k--) {
s = s['inverse']()['add'](cont[k]);
}
if (Math.abs(s['sub'](thisABS).valueOf()) < eps) {
return s['mul'](this['s']);
}
}
return this;
},
/**
* Check if two rational numbers are divisible
*
* Ex: new Fraction(19.6).divisible(1.5);
*/
"divisible": function(a, b) {
parse(a, b);
return !(!(P["n"] * this["d"]) || ((this["n"] * P["d"]) % (P["n"] * this["d"])));
},
/**
* Returns a decimal representation of the fraction
*
* Ex: new Fraction("100.'91823'").valueOf() => 100.91823918239183
**/
'valueOf': function() {
return this["s"] * this["n"] / this["d"];
},
/**
* Returns a string-fraction representation of a Fraction object
*
* Ex: new Fraction("1.'3'").toFraction(true) => "4 1/3"
**/
'toFraction': function(excludeWhole) {
var whole, str = "";
var n = this["n"];
var d = this["d"];
if (this["s"] < 0) {
str+= '-';
}
if (d === 1) {
str+= n;
} else {
if (excludeWhole && (whole = Math.floor(n / d)) > 0) {
str+= whole;
str+= " ";
n%= d;
}
str+= n;
str+= '/';
str+= d;
}
return str;
},
/**
* Returns a latex representation of a Fraction object
*
* Ex: new Fraction("1.'3'").toLatex() => "\frac{4}{3}"
**/
'toLatex': function(excludeWhole) {
var whole, str = "";
var n = this["n"];
var d = this["d"];
if (this["s"] < 0) {
str+= '-';
}
if (d === 1) {
str+= n;
} else {
if (excludeWhole && (whole = Math.floor(n / d)) > 0) {
str+= whole;
n%= d;
}
str+= "\\frac{";
str+= n;
str+= '}{';
str+= d;
str+= '}';
}
return str;
},
/**
* Returns an array of continued fraction elements
*
* Ex: new Fraction("7/8").toContinued() => [0,1,7]
*/
'toContinued': function() {
var t;
var a = this['n'];
var b = this['d'];
var res = [];
if (isNaN(a) || isNaN(b)) {
return res;
}
do {
res.push(Math.floor(a / b));
t = a % b;
a = b;
b = t;
} while (a !== 1);
return res;
},
/**
* Creates a string representation of a fraction with all digits
*
* Ex: new Fraction("100.'91823'").toString() => "100.(91823)"
**/
'toString': function(dec) {
var N = this["n"];
var D = this["d"];
if (isNaN(N) || isNaN(D)) {
return "NaN";
}
dec = dec || 15; // 15 = decimal places when no repetation
var cycLen = cycleLen(N, D); // Cycle length
var cycOff = cycleStart(N, D, cycLen); // Cycle start
var str = this['s'] < 0 ? "-" : "";
str+= N / D | 0;
N%= D;
N*= 10;
if (N)
str+= ".";
if (cycLen) {
for (var i = cycOff; i--;) {
str+= N / D | 0;
N%= D;
N*= 10;
}
str+= "(";
for (var i = cycLen; i--;) {
str+= N / D | 0;
N%= D;
N*= 10;
}
str+= ")";
} else {
for (var i = dec; N && i--;) {
str+= N / D | 0;
N%= D;
N*= 10;
}
}
return str;
}
};

View File

@ -1,18 +0,0 @@
/*
Fraction.js v4.3.7 31/08/2023
https://www.xarg.org/2014/03/rational-numbers-in-javascript/
Copyright (c) 2023, Robert Eisele (robert@raw.org)
Dual licensed under the MIT or GPL Version 2 licenses.
*/
(function(B){function x(){return Error("Invalid argument")}function z(){return Error("Division by Zero")}function n(a,c){var b=0,d=1,f=1,l=0,k=0,t=0,y=1,u=1,g=0,h=1,v=1,q=1;if(void 0!==a&&null!==a)if(void 0!==c){if(b=a,d=c,f=b*d,0!==b%1||0!==d%1)throw Error("Parameters must be integer");}else switch(typeof a){case "object":if("d"in a&&"n"in a)b=a.n,d=a.d,"s"in a&&(b*=a.s);else if(0 in a)b=a[0],1 in a&&(d=a[1]);else throw x();f=b*d;break;case "number":0>a&&(f=a,a=-a);if(0===a%1)b=a;else if(0<a){1<=
a&&(u=Math.pow(10,Math.floor(1+Math.log(a)/Math.LN10)),a/=u);for(;1E7>=h&&1E7>=q;)if(b=(g+v)/(h+q),a===b){1E7>=h+q?(b=g+v,d=h+q):q>h?(b=v,d=q):(b=g,d=h);break}else a>b?(g+=v,h+=q):(v+=g,q+=h),1E7<h?(b=v,d=q):(b=g,d=h);b*=u}else if(isNaN(a)||isNaN(c))d=b=NaN;break;case "string":h=a.match(/\d+|./g);if(null===h)throw x();"-"===h[g]?(f=-1,g++):"+"===h[g]&&g++;if(h.length===g+1)k=r(h[g++],f);else if("."===h[g+1]||"."===h[g]){"."!==h[g]&&(l=r(h[g++],f));g++;if(g+1===h.length||"("===h[g+1]&&")"===h[g+3]||
"'"===h[g+1]&&"'"===h[g+3])k=r(h[g],f),y=Math.pow(10,h[g].length),g++;if("("===h[g]&&")"===h[g+2]||"'"===h[g]&&"'"===h[g+2])t=r(h[g+1],f),u=Math.pow(10,h[g+1].length)-1,g+=3}else"/"===h[g+1]||":"===h[g+1]?(k=r(h[g],f),y=r(h[g+2],1),g+=3):"/"===h[g+3]&&" "===h[g+1]&&(l=r(h[g],f),k=r(h[g+2],f),y=r(h[g+4],1),g+=5);if(h.length<=g){d=y*u;f=b=t+d*l+u*k;break}default:throw x();}if(0===d)throw z();e.s=0>f?-1:1;e.n=Math.abs(b);e.d=Math.abs(d)}function r(a,c){if(isNaN(a=parseInt(a,10)))throw x();return a*c}
function m(a,c){if(0===c)throw z();var b=Object.create(p.prototype);b.s=0>a?-1:1;a=0>a?-a:a;var d=w(a,c);b.n=a/d;b.d=c/d;return b}function A(a){for(var c={},b=a,d=2,f=4;f<=b;){for(;0===b%d;)b/=d,c[d]=(c[d]||0)+1;f+=1+2*d++}b!==a?1<b&&(c[b]=(c[b]||0)+1):c[a]=(c[a]||0)+1;return c}function w(a,c){if(!a)return c;if(!c)return a;for(;;){a%=c;if(!a)return c;c%=a;if(!c)return a}}function p(a,c){n(a,c);if(this instanceof p)a=w(e.d,e.n),this.s=e.s,this.n=e.n/a,this.d=e.d/a;else return m(e.s*e.n,e.d)}var e=
{s:1,n:0,d:1};p.prototype={s:1,n:0,d:1,abs:function(){return m(this.n,this.d)},neg:function(){return m(-this.s*this.n,this.d)},add:function(a,c){n(a,c);return m(this.s*this.n*e.d+e.s*this.d*e.n,this.d*e.d)},sub:function(a,c){n(a,c);return m(this.s*this.n*e.d-e.s*this.d*e.n,this.d*e.d)},mul:function(a,c){n(a,c);return m(this.s*e.s*this.n*e.n,this.d*e.d)},div:function(a,c){n(a,c);return m(this.s*e.s*this.n*e.d,this.d*e.n)},clone:function(){return m(this.s*this.n,this.d)},mod:function(a,c){if(isNaN(this.n)||
isNaN(this.d))return new p(NaN);if(void 0===a)return m(this.s*this.n%this.d,1);n(a,c);if(0===e.n&&0===this.d)throw z();return m(this.s*e.d*this.n%(e.n*this.d),e.d*this.d)},gcd:function(a,c){n(a,c);return m(w(e.n,this.n)*w(e.d,this.d),e.d*this.d)},lcm:function(a,c){n(a,c);return 0===e.n&&0===this.n?m(0,1):m(e.n*this.n,w(e.n,this.n)*w(e.d,this.d))},ceil:function(a){a=Math.pow(10,a||0);return isNaN(this.n)||isNaN(this.d)?new p(NaN):m(Math.ceil(a*this.s*this.n/this.d),a)},floor:function(a){a=Math.pow(10,
a||0);return isNaN(this.n)||isNaN(this.d)?new p(NaN):m(Math.floor(a*this.s*this.n/this.d),a)},round:function(a){a=Math.pow(10,a||0);return isNaN(this.n)||isNaN(this.d)?new p(NaN):m(Math.round(a*this.s*this.n/this.d),a)},roundTo:function(a,c){n(a,c);return m(this.s*Math.round(this.n*e.d/(this.d*e.n))*e.n,e.d)},inverse:function(){return m(this.s*this.d,this.n)},pow:function(a,c){n(a,c);if(1===e.d)return 0>e.s?m(Math.pow(this.s*this.d,e.n),Math.pow(this.n,e.n)):m(Math.pow(this.s*this.n,e.n),Math.pow(this.d,
e.n));if(0>this.s)return null;var b=A(this.n),d=A(this.d),f=1,l=1,k;for(k in b)if("1"!==k){if("0"===k){f=0;break}b[k]*=e.n;if(0===b[k]%e.d)b[k]/=e.d;else return null;f*=Math.pow(k,b[k])}for(k in d)if("1"!==k){d[k]*=e.n;if(0===d[k]%e.d)d[k]/=e.d;else return null;l*=Math.pow(k,d[k])}return 0>e.s?m(l,f):m(f,l)},equals:function(a,c){n(a,c);return this.s*this.n*e.d===e.s*e.n*this.d},compare:function(a,c){n(a,c);var b=this.s*this.n*e.d-e.s*e.n*this.d;return(0<b)-(0>b)},simplify:function(a){if(isNaN(this.n)||
isNaN(this.d))return this;a=a||.001;for(var c=this.abs(),b=c.toContinued(),d=1;d<b.length;d++){for(var f=m(b[d-1],1),l=d-2;0<=l;l--)f=f.inverse().add(b[l]);if(Math.abs(f.sub(c).valueOf())<a)return f.mul(this.s)}return this},divisible:function(a,c){n(a,c);return!(!(e.n*this.d)||this.n*e.d%(e.n*this.d))},valueOf:function(){return this.s*this.n/this.d},toFraction:function(a){var c,b="",d=this.n,f=this.d;0>this.s&&(b+="-");1===f?b+=d:(a&&0<(c=Math.floor(d/f))&&(b=b+c+" ",d%=f),b=b+d+"/",b+=f);return b},
toLatex:function(a){var c,b="",d=this.n,f=this.d;0>this.s&&(b+="-");1===f?b+=d:(a&&0<(c=Math.floor(d/f))&&(b+=c,d%=f),b=b+"\\frac{"+d+"}{"+f,b+="}");return b},toContinued:function(){var a=this.n,c=this.d,b=[];if(isNaN(a)||isNaN(c))return b;do{b.push(Math.floor(a/c));var d=a%c;a=c;c=d}while(1!==a);return b},toString:function(a){var c=this.n,b=this.d;if(isNaN(c)||isNaN(b))return"NaN";var d;a:{for(d=b;0===d%2;d/=2);for(;0===d%5;d/=5);if(1===d)d=0;else{for(var f=10%d,l=1;1!==f;l++)if(f=10*f%d,2E3<l){d=
0;break a}d=l}}a:{f=1;l=10;for(var k=d,t=1;0<k;l=l*l%b,k>>=1)k&1&&(t=t*l%b);l=t;for(k=0;300>k;k++){if(f===l){l=k;break a}f=10*f%b;l=10*l%b}l=0}f=0>this.s?"-":"";f+=c/b|0;(c=c%b*10)&&(f+=".");if(d){for(a=l;a--;)f+=c/b|0,c%=b,c*=10;f+="(";for(a=d;a--;)f+=c/b|0,c%=b,c*=10;f+=")"}else for(a=a||15;c&&a--;)f+=c/b|0,c%=b,c*=10;return f}};"object"===typeof exports?(Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=p,module.exports=p):B.Fraction=p})(this);

View File

@ -1,55 +1,81 @@
{
"name": "fraction.js",
"title": "fraction.js",
"version": "4.3.7",
"homepage": "https://www.xarg.org/2014/03/rational-numbers-in-javascript/",
"title": "Fraction.js",
"version": "5.3.4",
"description": "The RAW rational numbers library",
"homepage": "https://raw.org/article/rational-numbers-in-javascript/",
"bugs": "https://github.com/rawify/Fraction.js/issues",
"description": "A rational number library",
"keywords": [
"math",
"numbers",
"parser",
"ratio",
"fraction",
"fractions",
"rational",
"rationals",
"number",
"parser",
"rational numbers"
"rational numbers",
"bigint",
"arbitrary precision",
"mixed numbers",
"decimal",
"numerator",
"denominator",
"simplification"
],
"private": false,
"main": "./dist/fraction.js",
"module": "./dist/fraction.mjs",
"browser": "./dist/fraction.min.js",
"unpkg": "./dist/fraction.min.js",
"types": "./fraction.d.mts",
"exports": {
".": {
"types": {
"import": "./fraction.d.mts",
"require": "./fraction.d.ts"
},
"import": "./dist/fraction.mjs",
"require": "./dist/fraction.js",
"browser": "./dist/fraction.min.js"
},
"./package.json": "./package.json"
},
"typesVersions": {
"<4.7": {
"*": [
"fraction.d.ts"
]
}
},
"sideEffects": false,
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/rawify/Fraction.js.git"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/rawify"
},
"author": {
"name": "Robert Eisele",
"email": "robert@raw.org",
"url": "https://raw.org/"
},
"type": "module",
"main": "fraction.cjs",
"exports": {
".": {
"import": "./fraction.js",
"require": "./fraction.cjs",
"types": "./fraction.d.ts"
}
},
"types": "./fraction.d.ts",
"private": false,
"readmeFilename": "README.md",
"directories": {
"example": "examples"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/rawify/Fraction.js.git"
},
"funding": {
"type": "patreon",
"url": "https://github.com/sponsors/rawify"
},
"engines": {
"node": "*"
},
"directories": {
"example": "examples",
"test": "tests"
},
"scripts": {
"build": "crude-build Fraction",
"test": "mocha tests/*.js"
},
"devDependencies": {
"crude-build": "^0.1.2",
"mocha": "*"
}
}
}

1046
frontend/node_modules/fraction.js/src/fraction.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

1806
frontend/node_modules/fraction.js/tests/fraction.test.js generated vendored Normal file

File diff suppressed because it is too large Load Diff