@lakuna/umath 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,2 +1,9 @@
1
- # umath
1
+ [![npm bundle size](https://img.shields.io/bundlephobia/minzip/@lakuna/umath?style=for-the-badge)](https://bundlephobia.com/package/@lakuna/umath)
2
+
3
+ # μMath
4
+
2
5
  A lightweight math library.
6
+
7
+ Documentation is automatically generated and uploaded to [the website](https://umath.lakuna.pw/).
8
+
9
+ The source code can be found on [the GitHub repository](https://github.com/Lakuna/umath).
@@ -0,0 +1,3 @@
1
+ export default function greatestCommonDivisor(a: bigint, b: bigint): bigint;
2
+ export default function greatestCommonDivisor(a: number, b: number): number;
3
+ //# sourceMappingURL=greatestCommonDivisor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"greatestCommonDivisor.d.ts","sourceRoot":"","sources":["../../src/algorithms/greatestCommonDivisor.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;AAS5E,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC"}
@@ -0,0 +1,13 @@
1
+ export default function greatestCommonDivisor(a, b) {
2
+ if (a < 0) {
3
+ a = -a;
4
+ }
5
+ if (b < 0) {
6
+ b = -b;
7
+ }
8
+ while (b) {
9
+ [a, b] = [b, a % b];
10
+ }
11
+ return a;
12
+ }
13
+ //# sourceMappingURL=greatestCommonDivisor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"greatestCommonDivisor.js","sourceRoot":"","sources":["../../src/algorithms/greatestCommonDivisor.ts"],"names":[],"mappings":"AAkBA,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,CAAkB,EAAE,CAAkB;IAEnF,IAAI,CAAC,GAAG,CAAC,EAAE;QAAE,CAAC,GAAG,CAAC,CAAC,CAAC;KAAE;IACtB,IAAI,CAAC,GAAG,CAAC,EAAE;QAAE,CAAC,GAAG,CAAC,CAAC,CAAC;KAAE;IAGtB,OAAO,CAAC,EAAE;QACT,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAG,CAAY,GAAI,CAAY,CAAC,CAAC;KAC5C;IAED,OAAO,CAAC,CAAC;AACV,CAAC"}
@@ -0,0 +1,2 @@
1
+ export default function summation(min: number, max: number, term: (i: number) => number): number;
2
+ //# sourceMappingURL=summation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"summation.d.ts","sourceRoot":"","sources":["../../src/algorithms/summation.ts"],"names":[],"mappings":"AAiBA,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAE/F"}
@@ -0,0 +1,7 @@
1
+ function summationInternal(i, max, term) {
2
+ return term(i) + (i < max ? summationInternal(i + 1, max, term) : 0);
3
+ }
4
+ export default function summation(min, max, term) {
5
+ return summationInternal(min, max, term);
6
+ }
7
+ //# sourceMappingURL=summation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"summation.js","sourceRoot":"","sources":["../../src/algorithms/summation.ts"],"names":[],"mappings":"AAMA,SAAS,iBAAiB,CAAC,CAAS,EAAE,GAAW,EAAE,IAA2B;IAC7E,OAAO,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtE,CAAC;AASD,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,GAAW,EAAE,GAAW,EAAE,IAA2B;IACtF,OAAO,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;AAC1C,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,5 @@
1
- export declare const foo = "bar";
1
+ export { default as greatestCommonDivisor } from "./algorithms/greatestCommonDivisor.js";
2
+ export { default as summation } from "./algorithms/summation.js";
3
+ export type { IntegerRepresentation } from "./types/IntegerRepresentation.js";
4
+ export { default as BigNumber } from "./utility/BigNumber.js";
2
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,GAAG,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AACzF,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACjE,YAAY,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,wBAAwB,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1,4 @@
1
- export const foo = "bar";
1
+ export { default as greatestCommonDivisor } from "./algorithms/greatestCommonDivisor.js";
2
+ export { default as summation } from "./algorithms/summation.js";
3
+ export { default as BigNumber } from "./utility/BigNumber.js";
2
4
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,GAAG,GAAG,KAAK,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AACzF,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAEjE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export type IntegerRepresentation = string | number | bigint | boolean;
2
+ //# sourceMappingURL=IntegerRepresentation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntegerRepresentation.d.ts","sourceRoot":"","sources":["../../src/types/IntegerRepresentation.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IntegerRepresentation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntegerRepresentation.js","sourceRoot":"","sources":["../../src/types/IntegerRepresentation.ts"],"names":[],"mappings":""}
@@ -0,0 +1,15 @@
1
+ import { type IntegerRepresentation } from "../index.js";
2
+ export default class BigNumber {
3
+ constructor(source?: IntegerRepresentation);
4
+ constructor(dividend?: IntegerRepresentation, divisor?: IntegerRepresentation);
5
+ dividend: bigint;
6
+ divisor: bigint;
7
+ private simplify;
8
+ add(n: IntegerRepresentation | BigNumber): this;
9
+ subtract(n: IntegerRepresentation | BigNumber): this;
10
+ multiply(n: IntegerRepresentation | BigNumber): this;
11
+ divide(n: IntegerRepresentation | BigNumber): this;
12
+ toNumber(): number;
13
+ toString(): string;
14
+ }
15
+ //# sourceMappingURL=BigNumber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BigNumber.d.ts","sourceRoot":"","sources":["../../src/utility/BigNumber.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGhF,MAAM,CAAC,OAAO,OAAO,SAAS;gBAKV,MAAM,CAAC,EAAE,qBAAqB;gBAO9B,QAAQ,CAAC,EAAE,qBAAqB,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAS7E,QAAQ,EAAE,MAAM,CAAC;IAGjB,OAAO,EAAE,MAAM,CAAC;IAGvB,OAAO,CAAC,QAAQ;IAoBT,GAAG,CAAC,CAAC,EAAE,qBAAqB,GAAG,SAAS,GAAG,IAAI;IAiB/C,QAAQ,CAAC,CAAC,EAAE,qBAAqB,GAAG,SAAS,GAAG,IAAI;IAiBpD,QAAQ,CAAC,CAAC,EAAE,qBAAqB,GAAG,SAAS,GAAG,IAAI;IAiBpD,MAAM,CAAC,CAAC,EAAE,qBAAqB,GAAG,SAAS,GAAG,IAAI;IAgBlD,QAAQ,IAAI,MAAM;IAQlB,QAAQ,IAAI,MAAM;CAGzB"}
@@ -0,0 +1,72 @@
1
+ import { greatestCommonDivisor } from "../index.js";
2
+ export default class BigNumber {
3
+ constructor(dividend = 0, divisor = 1) {
4
+ this.dividend = BigInt(dividend);
5
+ this.divisor = BigInt(divisor);
6
+ this.simplify();
7
+ }
8
+ dividend;
9
+ divisor;
10
+ simplify() {
11
+ if (this.divisor < 0) {
12
+ this.dividend = -this.dividend;
13
+ this.divisor = -this.divisor;
14
+ }
15
+ const gcd = greatestCommonDivisor(this.dividend, this.divisor);
16
+ if (gcd > 1) {
17
+ this.dividend /= gcd;
18
+ this.divisor /= gcd;
19
+ }
20
+ }
21
+ add(n) {
22
+ if (n instanceof BigNumber) {
23
+ this.dividend = this.dividend * n.divisor + n.dividend * this.divisor;
24
+ this.divisor *= n.divisor;
25
+ }
26
+ else {
27
+ this.dividend += BigInt(n) * this.divisor;
28
+ }
29
+ this.simplify();
30
+ return this;
31
+ }
32
+ subtract(n) {
33
+ if (n instanceof BigNumber) {
34
+ this.dividend = this.dividend * n.divisor - n.dividend * this.divisor;
35
+ this.divisor *= n.divisor;
36
+ }
37
+ else {
38
+ this.dividend -= BigInt(n) * this.divisor;
39
+ }
40
+ this.simplify();
41
+ return this;
42
+ }
43
+ multiply(n) {
44
+ if (n instanceof BigNumber) {
45
+ this.dividend *= n.dividend;
46
+ this.divisor *= n.divisor;
47
+ }
48
+ else {
49
+ this.dividend *= BigInt(n);
50
+ }
51
+ this.simplify();
52
+ return this;
53
+ }
54
+ divide(n) {
55
+ if (n instanceof BigNumber) {
56
+ this.dividend *= n.divisor;
57
+ this.divisor *= n.dividend;
58
+ }
59
+ else {
60
+ this.divisor *= BigInt(n);
61
+ }
62
+ this.simplify();
63
+ return this;
64
+ }
65
+ toNumber() {
66
+ return Number(this.dividend / this.divisor) + (Number(this.dividend % this.divisor) / Number(this.divisor));
67
+ }
68
+ toString() {
69
+ return `${this.dividend}/${this.divisor}`;
70
+ }
71
+ }
72
+ //# sourceMappingURL=BigNumber.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BigNumber.js","sourceRoot":"","sources":["../../src/utility/BigNumber.ts"],"names":[],"mappings":"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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lakuna/umath",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "A lightweight math library.",
5
5
  "keywords": [
6
6
  "math"
@@ -21,8 +21,8 @@
21
21
  "url": "https://github.com/sponsors/Lakuna"
22
22
  },
23
23
  "files": [
24
- "./dist/*",
25
- "./src/*"
24
+ "dist/*",
25
+ "src/*"
26
26
  ],
27
27
  "main": "./dist/index.js",
28
28
  "browser": "./dist/index.js",
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Determines the greatest common divisor of two integers.
3
+ * @param a The first integer.
4
+ * @param b The second integer.
5
+ * @returns The greatest common divisor of the integers.
6
+ * @see [Wikipedia](https://en.wikipedia.org/wiki/Greatest_common_divisor)
7
+ */
8
+ export default function greatestCommonDivisor(a: bigint, b: bigint): bigint;
9
+
10
+ /**
11
+ * Determines the greatest common divisor of two integers.
12
+ * @param a The first integer.
13
+ * @param b The second integer.
14
+ * @returns The greatest common divisor of the integers.
15
+ * @see [Wikipedia](https://en.wikipedia.org/wiki/Greatest_common_divisor)
16
+ */
17
+ export default function greatestCommonDivisor(a: number, b: number): number;
18
+
19
+ export default function greatestCommonDivisor(a: bigint | number, b: bigint | number): bigint | number {
20
+ // Ensure that all of the integers are positive.
21
+ if (a < 0) { a = -a; }
22
+ if (b < 0) { b = -b; }
23
+
24
+ // Apply the Euclidean algorithm.
25
+ while (b) {
26
+ [a, b] = [b, (a as number) % (b as number)];
27
+ }
28
+
29
+ return a;
30
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Recursively sums up the results of the given function.
3
+ * @param i The index of summation.
4
+ * @param max The upper bound of the index of summation.
5
+ * @param term The function used to generate each term.
6
+ */
7
+ function summationInternal(i: number, max: number, term: (i: number) => number): number {
8
+ return term(i) + (i < max ? summationInternal(i + 1, max, term) : 0);
9
+ }
10
+
11
+ /**
12
+ * Performs a summation.
13
+ * @param min The lower bound (inclusive) of the index of summation.
14
+ * @param max The upper bound (inclusive) of the index of summation.
15
+ * @param term The function used to generate each term.
16
+ * @returns The summation.
17
+ */
18
+ export default function summation(min: number, max: number, term: (i: number) => number): number {
19
+ return summationInternal(min, max, term);
20
+ }
package/src/index.ts CHANGED
@@ -1 +1,4 @@
1
- export const foo = "bar";
1
+ export { default as greatestCommonDivisor } from "./algorithms/greatestCommonDivisor.js";
2
+ export { default as summation } from "./algorithms/summation.js";
3
+ export type { IntegerRepresentation } from "./types/IntegerRepresentation.js";
4
+ export { default as BigNumber } from "./utility/BigNumber.js";
@@ -0,0 +1,2 @@
1
+ /** A value that represents an integer. */
2
+ export type IntegerRepresentation = string | number | bigint | boolean;
@@ -0,0 +1,129 @@
1
+ import { greatestCommonDivisor, type IntegerRepresentation } from "../index.js";
2
+
3
+ /** A number with no maximum precise size. */
4
+ export default class BigNumber {
5
+ /**
6
+ * Creates a number.
7
+ * @param source The number.
8
+ */
9
+ public constructor(source?: IntegerRepresentation);
10
+
11
+ /**
12
+ * Creates a number from a fraction.
13
+ * @param dividend The dividend of the fraction.
14
+ * @param divisor The divisor of the fraction.
15
+ */
16
+ public constructor(dividend?: IntegerRepresentation, divisor?: IntegerRepresentation);
17
+
18
+ public constructor(dividend: IntegerRepresentation = 0, divisor: IntegerRepresentation = 1) {
19
+ this.dividend = BigInt(dividend);
20
+ this.divisor = BigInt(divisor);
21
+ this.simplify();
22
+ }
23
+
24
+ /** The dividend of this fraction. */
25
+ public dividend: bigint;
26
+
27
+ /** The divisor of this fraction. */
28
+ public divisor: bigint;
29
+
30
+ /** Simplifies this fraction. */
31
+ private simplify(): void {
32
+ // Switches signs such that only the dividend can be negative.
33
+ if (this.divisor < 0) {
34
+ this.dividend = -this.dividend;
35
+ this.divisor = -this.divisor;
36
+ }
37
+
38
+ // Divide both by their greatest common divisor.
39
+ const gcd: bigint = greatestCommonDivisor(this.dividend, this.divisor);
40
+ if (gcd > 1) {
41
+ this.dividend /= gcd;
42
+ this.divisor /= gcd;
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Adds a number to this number.
48
+ * @param n The other number.
49
+ * @returns This number.
50
+ */
51
+ public add(n: IntegerRepresentation | BigNumber): this {
52
+ if (n instanceof BigNumber) {
53
+ this.dividend = this.dividend * n.divisor + n.dividend * this.divisor;
54
+ this.divisor *= n.divisor;
55
+ } else {
56
+ this.dividend += BigInt(n) * this.divisor;
57
+ }
58
+
59
+ this.simplify();
60
+ return this;
61
+ }
62
+
63
+ /**
64
+ * Subtracts a number from this number.
65
+ * @param n The other number.
66
+ * @returns This number.
67
+ */
68
+ public subtract(n: IntegerRepresentation | BigNumber): this {
69
+ if (n instanceof BigNumber) {
70
+ this.dividend = this.dividend * n.divisor - n.dividend * this.divisor;
71
+ this.divisor *= n.divisor;
72
+ } else {
73
+ this.dividend -= BigInt(n) * this.divisor;
74
+ }
75
+
76
+ this.simplify();
77
+ return this;
78
+ }
79
+
80
+ /**
81
+ * Multiplies this number by a number.
82
+ * @param n The other number.
83
+ * @returns This number.
84
+ */
85
+ public multiply(n: IntegerRepresentation | BigNumber): this {
86
+ if (n instanceof BigNumber) {
87
+ this.dividend *= n.dividend;
88
+ this.divisor *= n.divisor;
89
+ } else {
90
+ this.dividend *= BigInt(n);
91
+ }
92
+
93
+ this.simplify();
94
+ return this;
95
+ }
96
+
97
+ /**
98
+ * Divides this number by a number.
99
+ * @param n The other number.
100
+ * @returns This number.
101
+ */
102
+ public divide(n: IntegerRepresentation | BigNumber): this {
103
+ if (n instanceof BigNumber) {
104
+ this.dividend *= n.divisor;
105
+ this.divisor *= n.dividend;
106
+ } else {
107
+ this.divisor *= BigInt(n);
108
+ }
109
+
110
+ this.simplify();
111
+ return this;
112
+ }
113
+
114
+ /**
115
+ * Converts this number to a regular `number`. Might result in loss of precision.
116
+ * @returns This number as a `number`.
117
+ */
118
+ public toNumber(): number {
119
+ return Number(this.dividend / this.divisor) + (Number(this.dividend % this.divisor) / Number(this.divisor));
120
+ }
121
+
122
+ /**
123
+ * Converts this number to a string.
124
+ * @returns A string representation of this number.
125
+ */
126
+ public toString(): string {
127
+ return `${this.dividend}/${this.divisor}`;
128
+ }
129
+ }