big.esm 1.2.0 → 1.2.2
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/CHANGELOG.md +19 -0
- package/README.md +14 -17
- package/dist/big.d.ts +2 -2
- package/dist/big.esm.js +90 -92
- package/dist/big.esm.umd.cjs +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/operations/compare.d.ts +1 -1
- package/dist/utils/clone.d.ts +1 -1
- package/dist/utils/create.d.ts +2 -2
- package/dist/utils/from-string.d.ts +2 -2
- package/dist/utils/is-big-object.d.ts +2 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
## [1.2.2](https://github.com/dschewchenko/big.esm/compare/v1.2.1...v1.2.2) (2023-05-28)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* import name for types generation ([e41cbf5](https://github.com/dschewchenko/big.esm/commit/e41cbf573d55f46e5baf8ee661483dbcf8dcf289))
|
|
7
|
+
|
|
8
|
+
## [1.2.1](https://github.com/dschewchenko/big.esm/compare/v1.2.0...v1.2.1) (2023-05-28)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* types path ([03a2b9a](https://github.com/dschewchenko/big.esm/commit/03a2b9a6ccac8bea3b67163568f402fe8d6309bd))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Performance Improvements
|
|
17
|
+
|
|
18
|
+
* optimize pow operation and big instance ([0988711](https://github.com/dschewchenko/big.esm/commit/09887110966eaaba3046d085c85a1167e47f6c2c))
|
|
19
|
+
|
|
1
20
|
# [1.2.0](https://github.com/dschewchenko/big.esm/compare/v1.1.2...v1.2.0) (2023-05-19)
|
|
2
21
|
|
|
3
22
|
|
package/README.md
CHANGED
|
@@ -8,18 +8,13 @@ It provides advanced functionality for performing arithmetic operations with pre
|
|
|
8
8
|
[Documentation](https://dschewchenko.github.io/big.esm/).
|
|
9
9
|
|
|
10
10
|
- 100% test coverage.
|
|
11
|
-
|
|
12
11
|
- No dependencies.
|
|
13
|
-
|
|
14
|
-
- No limitations on the size of the numbers, except for the limitations of `BigInt`, so limited by system memory =).
|
|
15
|
-
|
|
12
|
+
- No limitations on the size of the numbers, except for the limitations of `BigInt`, so limited by system memory =)
|
|
16
13
|
- Fully written in TypeScript, so it provides type definitions out of the box.
|
|
14
|
+
- Tree-shaking is supported.
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Full bundle size(ESM) — 3.12 kB minified and 1.42 kB gzipped.
|
|
21
|
-
`powBig` operation is half of this size, 1.5kB/0.7kB(minified/gzip),
|
|
22
|
-
because it's big and reuses most of the operations from `big.esm`.
|
|
16
|
+
Full bundle size(ESM) — 4.16 kB minified and 1.75 kB gzipped.
|
|
17
|
+
`sqrtBig` operation is heavy(more than half of bundle), because it reuses most of the operations from `big.esm`.
|
|
23
18
|
|
|
24
19
|
## Installation
|
|
25
20
|
|
|
@@ -79,35 +74,37 @@ Checks if the value is a valid numeric value for creating a `Big` instance.
|
|
|
79
74
|
|
|
80
75
|
### Mathematical operations
|
|
81
76
|
|
|
82
|
-
|
|
77
|
+
In math operations `mutable` option is used to specify whether to mutate the first argument or create a new instance. By default, a new instance is created.
|
|
78
|
+
|
|
79
|
+
#### `addBig(a: Big, b: Big, mutable = false): Big`
|
|
83
80
|
|
|
84
81
|
Adds two `Big` instances.
|
|
85
82
|
|
|
86
|
-
#### `subBig(a: Big, b: Big): Big`
|
|
83
|
+
#### `subBig(a: Big, b: Big, mutable = false): Big`
|
|
87
84
|
|
|
88
85
|
Subtracts two `Big` instances.
|
|
89
86
|
|
|
90
|
-
#### `mulBig(a: Big, b: Big): Big`
|
|
87
|
+
#### `mulBig(a: Big, b: Big, mutable = false): Big`
|
|
91
88
|
|
|
92
89
|
Multiplies two `Big` instances.
|
|
93
90
|
|
|
94
|
-
#### `divBig(a: Big, b: Big, precision = 20, roundingMode = "half-up"): Big`
|
|
91
|
+
#### `divBig(a: Big, b: Big, precision = 20, roundingMode = "half-up", mutable = false): Big`
|
|
95
92
|
|
|
96
93
|
Divides two `Big` instances. The default precision is 20. The default rounding mode is "half-up".
|
|
97
94
|
|
|
98
|
-
#### `modBig(a: Big, b: Big): Big`
|
|
95
|
+
#### `modBig(a: Big, b: Big, mutable = false): Big`
|
|
99
96
|
|
|
100
97
|
Calculates the remainder of dividing two `Big` instances.
|
|
101
98
|
|
|
102
|
-
#### `powBig(a: Big, exp: number): Big`
|
|
99
|
+
#### `powBig(a: Big, exp: number, mutable = false): Big`
|
|
103
100
|
|
|
104
101
|
Raises `a` to the power of `b`.
|
|
105
102
|
|
|
106
|
-
#### `sqrtBig(a: Big, root = 2, precision = 20): Big`
|
|
103
|
+
#### `sqrtBig(a: Big, root = 2, precision = 20, mutable = false): Big`
|
|
107
104
|
|
|
108
105
|
Calculates the root of `a`. The default root is 2, which means the square root. The default precision is 20.
|
|
109
106
|
|
|
110
|
-
#### `absBig(a: Big): Big`
|
|
107
|
+
#### `absBig(a: Big, mutable = false): Big`
|
|
111
108
|
|
|
112
109
|
Returns the absolute value of `a`.
|
|
113
110
|
|
package/dist/big.d.ts
CHANGED
|
@@ -43,11 +43,11 @@ export declare class Big {
|
|
|
43
43
|
* Creates a new Big instance.
|
|
44
44
|
*
|
|
45
45
|
* @param {PossibleNumber} value - The value to create the Big instance from. Can be a number, string, or BigInt.
|
|
46
|
-
* @param {number | string
|
|
46
|
+
* @param {number | string} [scale] - The scale for the value (optional), representing the number of decimal places. If scale provided and value has a fractional part, the fractional part will be removed.
|
|
47
47
|
* @throws {TypeError} - If the value is not a number, string, BigInt, or Big instance.
|
|
48
48
|
* @return {Big} - A new Big instance.
|
|
49
49
|
*/
|
|
50
|
-
constructor(value: PossibleNumber, scale: number | string
|
|
50
|
+
constructor(value: PossibleNumber, scale: number | string);
|
|
51
51
|
/**
|
|
52
52
|
* Returns the primitive value of the Big instance.
|
|
53
53
|
*
|
package/dist/big.esm.js
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
var O = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
function
|
|
7
|
-
return e instanceof
|
|
2
|
+
var D = (e, t, n) => t in e ? O(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var v = (e, t, n) => (D(e, typeof t != "symbol" ? t + "" : t, n), n);
|
|
4
|
+
const A = (e) => typeof e == "bigint" || typeof e == "number" || typeof e == "string" && !isNaN(Number(e)), M = /0+$/, _ = (e) => e.replace(M, "");
|
|
5
|
+
const m = BigInt(0), d = BigInt(1), I = BigInt(10);
|
|
6
|
+
function u(e, t) {
|
|
7
|
+
return e instanceof p ? e : new p(e, t);
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
const r =
|
|
11
|
-
if (!isFinite(Number(r)))
|
|
9
|
+
function x(e, t = !1, n = !0) {
|
|
10
|
+
const r = e.toString();
|
|
11
|
+
if (!Number.isFinite(Number(r)))
|
|
12
12
|
throw new Error("Invalid number");
|
|
13
13
|
if (Number(r) === 0)
|
|
14
|
-
return n ?
|
|
15
|
-
let [s,
|
|
14
|
+
return n ? u(m) : { value: m, scale: 0 };
|
|
15
|
+
let [s, a] = r.split("e");
|
|
16
16
|
const g = s.startsWith("-") ? "-" : "";
|
|
17
|
-
|
|
18
|
-
let [
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
22
|
-
const f = Math.min(
|
|
23
|
-
|
|
24
|
-
} else if (
|
|
25
|
-
const f = Math.min(-
|
|
26
|
-
l =
|
|
17
|
+
s = g ? s.slice(1) : s;
|
|
18
|
+
let [o, l = ""] = s.split(".");
|
|
19
|
+
l = t ? "" : l;
|
|
20
|
+
const i = Number.parseInt(a);
|
|
21
|
+
if (i > 0) {
|
|
22
|
+
const f = Math.min(i, l.length);
|
|
23
|
+
o += l.slice(0, f), l = l.slice(f), f < i && (o += "0".repeat(i - f));
|
|
24
|
+
} else if (i < 0) {
|
|
25
|
+
const f = Math.min(-i, o.length);
|
|
26
|
+
l = o.slice(-f) + l, o = o.slice(0, o.length - f), f < -i && (l = "0".repeat(-i - f) + l);
|
|
27
27
|
}
|
|
28
|
-
const h = BigInt(g +
|
|
29
|
-
return n ?
|
|
28
|
+
const h = BigInt(g + o + l), c = l.length;
|
|
29
|
+
return n ? u(h, c) : { value: h, scale: c };
|
|
30
30
|
}
|
|
31
|
-
function
|
|
32
|
-
return
|
|
31
|
+
function R(e) {
|
|
32
|
+
return typeof e != "object" || e === null ? !1 : "value" in e && "scale" in e && typeof e.value == "bigint" && typeof e.scale == "number";
|
|
33
33
|
}
|
|
34
|
-
class
|
|
34
|
+
class p {
|
|
35
35
|
/**
|
|
36
36
|
* Implements the overloaded constructors for the Big class.
|
|
37
37
|
* @param {BigValue} value - The value to create the Big instance from. Can be a number, string, BigInt, or another Big instance.
|
|
@@ -43,20 +43,20 @@ class v {
|
|
|
43
43
|
/**
|
|
44
44
|
* The value of the Big instance.
|
|
45
45
|
*/
|
|
46
|
-
|
|
46
|
+
v(this, "value");
|
|
47
47
|
/**
|
|
48
48
|
* The scale of the Big instance, representing the number of decimal places.
|
|
49
49
|
*/
|
|
50
|
-
|
|
51
|
-
if (
|
|
50
|
+
v(this, "scale");
|
|
51
|
+
if (R(t))
|
|
52
52
|
this.value = t.value, this.scale = t.scale;
|
|
53
|
-
else if (
|
|
53
|
+
else if (A(t)) {
|
|
54
54
|
let r = n !== void 0;
|
|
55
55
|
if (r && (typeof n != "number" && (n = Number(n)), r = !isNaN(n), n = r ? Math.floor(n) : 0), typeof t == "bigint")
|
|
56
56
|
this.value = t, this.scale = r ? n : 0;
|
|
57
57
|
else {
|
|
58
|
-
const { value: s, scale:
|
|
59
|
-
this.value = s, this.scale = r ? n :
|
|
58
|
+
const { value: s, scale: a } = x(t, r, !1);
|
|
59
|
+
this.value = s, this.scale = r ? n : a;
|
|
60
60
|
}
|
|
61
61
|
} else
|
|
62
62
|
throw new TypeError("Invalid type provided to Big constructor.");
|
|
@@ -80,9 +80,9 @@ class v {
|
|
|
80
80
|
const r = n.startsWith("-") ? "-" : "";
|
|
81
81
|
r && (n = n.substring(1));
|
|
82
82
|
let s = "";
|
|
83
|
-
if (this.scale >
|
|
84
|
-
const
|
|
85
|
-
s = n.slice(
|
|
83
|
+
if (this.scale > m) {
|
|
84
|
+
const a = n.length > this.scale ? n.length - Number(this.scale) : 0;
|
|
85
|
+
s = n.slice(a).padStart(Number(this.scale), "0"), t && (s = _(s)), s.length > 0 && (s = `.${s}`), n = n.slice(0, a);
|
|
86
86
|
}
|
|
87
87
|
return `${r}${n || "0"}${s}`;
|
|
88
88
|
}
|
|
@@ -99,109 +99,107 @@ function E(e, t, n = !1) {
|
|
|
99
99
|
const r = e.scale - t.scale;
|
|
100
100
|
if (r === 0)
|
|
101
101
|
return [e, t];
|
|
102
|
-
const s =
|
|
102
|
+
const s = I ** BigInt(Math.abs(r));
|
|
103
103
|
if (n)
|
|
104
104
|
return r > 0 ? (t.value *= s, t.scale = e.scale) : (e.value *= s, e.scale = t.scale), [e, t];
|
|
105
|
-
const
|
|
106
|
-
return [
|
|
105
|
+
const a = r > 0 ? e : u(e.value * s, t.scale), g = r < 0 ? t : u(t.value * s, e.scale);
|
|
106
|
+
return [a, g];
|
|
107
107
|
}
|
|
108
|
-
function
|
|
109
|
-
const [r, s] = E(e, t),
|
|
110
|
-
return n ? (e.value =
|
|
111
|
-
}
|
|
112
|
-
function N(e, t, n = !1) {
|
|
113
|
-
const [r, s] = E(e, t, n), i = r.value - s.value;
|
|
114
|
-
return n ? (e.value = i, e) : a(i, r.scale);
|
|
108
|
+
function T(e, t, n = !1) {
|
|
109
|
+
const [r, s] = E(e, t), a = r.value + s.value;
|
|
110
|
+
return n ? (e.value = a, e.scale = r.scale, e) : u(a, r.scale);
|
|
115
111
|
}
|
|
116
112
|
function w(e, t, n = !1) {
|
|
113
|
+
const [r, s] = E(e, t, n), a = r.value - s.value;
|
|
114
|
+
return n ? (e.value = a, e) : u(a, r.scale);
|
|
115
|
+
}
|
|
116
|
+
function N(e, t, n = !1) {
|
|
117
117
|
const r = e.value * t.value, s = e.scale + t.scale;
|
|
118
|
-
return n ? (e.value = r, e.scale = s, e) :
|
|
118
|
+
return n ? (e.value = r, e.scale = s, e) : u(r, s);
|
|
119
119
|
}
|
|
120
|
-
const S = (e) => e.value ===
|
|
121
|
-
function
|
|
120
|
+
const S = (e) => e.value === m;
|
|
121
|
+
function B(e, t, n = 20, r = "half-up", s = !1) {
|
|
122
122
|
if (S(t))
|
|
123
123
|
throw new Error("Division by zero is not allowed.");
|
|
124
|
-
const
|
|
124
|
+
const a = Math.max(e.scale, t.scale), g = Math.max(0, n), o = e.value * I ** BigInt(a + g - e.scale), l = t.value * I ** BigInt(a - t.scale), i = o / l, h = o % l;
|
|
125
125
|
let c;
|
|
126
126
|
switch (r) {
|
|
127
127
|
case "down":
|
|
128
|
-
c =
|
|
128
|
+
c = i;
|
|
129
129
|
break;
|
|
130
130
|
case "up":
|
|
131
|
-
c = h !==
|
|
131
|
+
c = h !== m ? i + d : i + m;
|
|
132
132
|
break;
|
|
133
133
|
case "half-up":
|
|
134
134
|
default:
|
|
135
|
-
c = h * BigInt(2) >= l ?
|
|
135
|
+
c = h * BigInt(2) >= l ? i + d : i;
|
|
136
136
|
break;
|
|
137
137
|
}
|
|
138
|
-
return s ? (e.value = c, e.scale = g, e) :
|
|
138
|
+
return s ? (e.value = c, e.scale = g, e) : u(c, g);
|
|
139
139
|
}
|
|
140
|
-
function
|
|
140
|
+
function F(e, t, n = !1) {
|
|
141
141
|
if (S(t))
|
|
142
142
|
throw new Error("Division by zero is not allowed.");
|
|
143
|
-
const r =
|
|
143
|
+
const r = B(e, t, 0, "down");
|
|
144
144
|
if (n)
|
|
145
|
-
return
|
|
146
|
-
const s =
|
|
147
|
-
return
|
|
145
|
+
return N(r, t, !0), w(e, r, !0);
|
|
146
|
+
const s = N(r, t);
|
|
147
|
+
return w(e, s);
|
|
148
148
|
}
|
|
149
149
|
function b(e, t = 2, n = !1) {
|
|
150
150
|
if (!Number.isInteger(t) || t < 0)
|
|
151
151
|
throw new Error("The exponent must be a non-negative integer.");
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
t % 2 === 1 && (r = w(r, s, n)), s = w(s, s, n), t = Math.floor(t / 2);
|
|
155
|
-
return n ? (e.value = r.value, e.scale = r.scale, e) : r;
|
|
152
|
+
const r = e.value ** BigInt(t), s = e.scale * t;
|
|
153
|
+
return n ? (e.value = r, e.scale = s, e) : u(r, s);
|
|
156
154
|
}
|
|
157
|
-
const
|
|
155
|
+
const j = (e, t) => {
|
|
158
156
|
const [n, r] = E(e, t);
|
|
159
157
|
return n.value > r.value ? 1 : n.value < r.value ? -1 : 0;
|
|
160
158
|
};
|
|
161
|
-
function
|
|
162
|
-
const n = e.value <
|
|
163
|
-
return t ? (e.value = n, e) :
|
|
159
|
+
function P(e, t = !1) {
|
|
160
|
+
const n = e.value < m ? -e.value : e.value;
|
|
161
|
+
return t ? (e.value = n, e) : u(n, e.scale);
|
|
164
162
|
}
|
|
165
|
-
function
|
|
163
|
+
function G(e, t = 2, n = 20, r = !1) {
|
|
166
164
|
if (S(e))
|
|
167
|
-
return
|
|
165
|
+
return u(0);
|
|
168
166
|
if (e.valueOf() === BigInt(1))
|
|
169
|
-
return
|
|
170
|
-
if (e.value <
|
|
167
|
+
return u(1);
|
|
168
|
+
if (e.value < m && t % 2 === 0)
|
|
171
169
|
throw new Error("The root must be an odd integer when the number is negative.");
|
|
172
170
|
if (!Number.isInteger(t) || t < 2)
|
|
173
171
|
throw new Error("The root must be an integer and greater than 1");
|
|
174
172
|
if (n < 0)
|
|
175
173
|
throw new Error("The precision must be a non-negative integer.");
|
|
176
|
-
const s =
|
|
177
|
-
let l =
|
|
174
|
+
const s = u(n === 0 ? "1" : "0." + "0".repeat(n - 1) + "1"), a = u(t), g = u(t - 1), o = u(2);
|
|
175
|
+
let l = B(T(e, B(e, o, n)), o, n), i;
|
|
178
176
|
do {
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
l =
|
|
182
|
-
} while (P(
|
|
177
|
+
i = l;
|
|
178
|
+
const y = T(N(g, l), B(e, b(l, t - 1), n));
|
|
179
|
+
l = B(y, a, n);
|
|
180
|
+
} while (j(P(w(i, l)), s) === 1);
|
|
183
181
|
const h = l.toString();
|
|
184
182
|
if (r)
|
|
185
183
|
return e.value = l.value, e.scale = n, e;
|
|
186
184
|
const c = h.indexOf("."), f = c !== -1 ? h.slice(0, c + n + 1) : h;
|
|
187
|
-
return
|
|
185
|
+
return u(f);
|
|
188
186
|
}
|
|
189
|
-
const
|
|
187
|
+
const V = (e) => new p(e.value, e.scale);
|
|
190
188
|
export {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
189
|
+
p as Big,
|
|
190
|
+
P as absBig,
|
|
191
|
+
T as addBig,
|
|
194
192
|
E as alignScale,
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
193
|
+
V as cloneBig,
|
|
194
|
+
j as compareBig,
|
|
195
|
+
u as createBig,
|
|
196
|
+
B as divBig,
|
|
197
|
+
x as fromString,
|
|
198
|
+
R as isBigObject,
|
|
199
|
+
A as isNumericValue,
|
|
200
|
+
F as modBig,
|
|
201
|
+
N as mulBig,
|
|
204
202
|
b as powBig,
|
|
205
|
-
|
|
206
|
-
|
|
203
|
+
G as sqrtBig,
|
|
204
|
+
w as subBig
|
|
207
205
|
};
|
package/dist/big.esm.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(s,
|
|
1
|
+
(function(s,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(s=typeof globalThis<"u"?globalThis:s||self,o((s.big=s.big||{},s.big.esm={})))})(this,function(s){"use strict";var F=Object.defineProperty;var G=(s,o,d)=>o in s?F(s,o,{enumerable:!0,configurable:!0,writable:!0,value:d}):s[o]=d;var b=(s,o,d)=>(G(s,typeof o!="symbol"?o+"":o,d),d);const o=e=>typeof e=="bigint"||typeof e=="number"||typeof e=="string"&&!isNaN(Number(e)),d=/0+$/,R=e=>e.replace(d,""),v=BigInt(0),O=BigInt(1),E=BigInt(10);function u(e,t){return e instanceof w?e:new w(e,t)}function j(e,t=!1,n=!0){const i=e.toString();if(!Number.isFinite(Number(i)))throw new Error("Invalid number");if(Number(i)===0)return n?u(v):{value:v,scale:0};let[r,a]=i.split("e");const B=r.startsWith("-")?"-":"";r=B?r.slice(1):r;let[f,l=""]=r.split(".");l=t?"":l;const c=Number.parseInt(a);if(c>0){const h=Math.min(c,l.length);f+=l.slice(0,h),l=l.slice(h),h<c&&(f+="0".repeat(c-h))}else if(c<0){const h=Math.min(-c,f.length);l=f.slice(-h)+l,f=f.slice(0,f.length-h),h<-c&&(l="0".repeat(-c-h)+l)}const m=BigInt(B+f+l),g=l.length;return n?u(m,g):{value:m,scale:g}}function D(e){return typeof e!="object"||e===null?!1:"value"in e&&"scale"in e&&typeof e.value=="bigint"&&typeof e.scale=="number"}class w{constructor(t,n){b(this,"value");b(this,"scale");if(D(t))this.value=t.value,this.scale=t.scale;else if(o(t)){let i=n!==void 0;if(i&&(typeof n!="number"&&(n=Number(n)),i=!isNaN(n),n=i?Math.floor(n):0),typeof t=="bigint")this.value=t,this.scale=i?n:0;else{const{value:r,scale:a}=j(t,i,!1);this.value=r,this.scale=i?n:a}}else throw new TypeError("Invalid type provided to Big constructor.")}valueOf(){return this.value}toString(t=!0){let n=this.value.toString();const i=n.startsWith("-")?"-":"";i&&(n=n.substring(1));let r="";if(this.scale>v){const a=n.length>this.scale?n.length-Number(this.scale):0;r=n.slice(a).padStart(Number(this.scale),"0"),t&&(r=R(r)),r.length>0&&(r=`.${r}`),n=n.slice(0,a)}return`${i}${n||"0"}${r}`}toJSON(){return this.toString()}}function N(e,t,n=!1){const i=e.scale-t.scale;if(i===0)return[e,t];const r=E**BigInt(Math.abs(i));if(n)return i>0?(t.value*=r,t.scale=e.scale):(e.value*=r,e.scale=t.scale),[e,t];const a=i>0?e:u(e.value*r,t.scale),B=i<0?t:u(t.value*r,e.scale);return[a,B]}function y(e,t,n=!1){const[i,r]=N(e,t),a=i.value+r.value;return n?(e.value=a,e.scale=i.scale,e):u(a,i.scale)}function S(e,t,n=!1){const[i,r]=N(e,t,n),a=i.value-r.value;return n?(e.value=a,e):u(a,i.scale)}function p(e,t,n=!1){const i=e.value*t.value,r=e.scale+t.scale;return n?(e.value=i,e.scale=r,e):u(i,r)}const T=e=>e.value===v;function I(e,t,n=20,i="half-up",r=!1){if(T(t))throw new Error("Division by zero is not allowed.");const a=Math.max(e.scale,t.scale),B=Math.max(0,n),f=e.value*E**BigInt(a+B-e.scale),l=t.value*E**BigInt(a-t.scale),c=f/l,m=f%l;let g;switch(i){case"down":g=c;break;case"up":g=m!==v?c+O:c+v;break;case"half-up":default:g=m*BigInt(2)>=l?c+O:c;break}return r?(e.value=g,e.scale=B,e):u(g,B)}function P(e,t,n=!1){if(T(t))throw new Error("Division by zero is not allowed.");const i=I(e,t,0,"down");if(n)return p(i,t,!0),S(e,i,!0);const r=p(i,t);return S(e,r)}function M(e,t=2,n=!1){if(!Number.isInteger(t)||t<0)throw new Error("The exponent must be a non-negative integer.");const i=e.value**BigInt(t),r=e.scale*t;return n?(e.value=i,e.scale=r,e):u(i,r)}const A=(e,t)=>{const[n,i]=N(e,t);return n.value>i.value?1:n.value<i.value?-1:0};function _(e,t=!1){const n=e.value<v?-e.value:e.value;return t?(e.value=n,e):u(n,e.scale)}function V(e,t=2,n=20,i=!1){if(T(e))return u(0);if(e.valueOf()===BigInt(1))return u(1);if(e.value<v&&t%2===0)throw new Error("The root must be an odd integer when the number is negative.");if(!Number.isInteger(t)||t<2)throw new Error("The root must be an integer and greater than 1");if(n<0)throw new Error("The precision must be a non-negative integer.");const r=u(n===0?"1":"0."+"0".repeat(n-1)+"1"),a=u(t),B=u(t-1),f=u(2);let l=I(y(e,I(e,f,n)),f,n),c;do{c=l;const q=y(p(B,l),I(e,M(l,t-1),n));l=I(q,a,n)}while(A(_(S(c,l)),r)===1);const m=l.toString();if(i)return e.value=l.value,e.scale=n,e;const g=m.indexOf("."),h=g!==-1?m.slice(0,g+n+1):m;return u(h)}const $=e=>new w(e.value,e.scale);s.Big=w,s.absBig=_,s.addBig=y,s.alignScale=N,s.cloneBig=$,s.compareBig=A,s.createBig=u,s.divBig=I,s.fromString=j,s.isBigObject=D,s.isNumericValue=o,s.modBig=P,s.mulBig=p,s.powBig=M,s.sqrtBig=V,s.subBig=S,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,6 @@ export { compareBig } from "./operations/compare";
|
|
|
12
12
|
export { isBigObject } from "./utils/is-big-object";
|
|
13
13
|
export { isNumericValue } from "./utils/numeric";
|
|
14
14
|
export { alignScale } from "./utils/align-scale";
|
|
15
|
-
export { createBig } from "./utils/create
|
|
16
|
-
export { cloneBig } from "./utils/clone
|
|
17
|
-
export { fromString } from "./utils/from-string
|
|
15
|
+
export { createBig } from "./utils/create";
|
|
16
|
+
export { cloneBig } from "./utils/clone";
|
|
17
|
+
export { fromString } from "./utils/from-string";
|
package/dist/utils/clone.d.ts
CHANGED
package/dist/utils/create.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Big } from "../big
|
|
2
|
-
import type { BigObject, PossibleNumber } from "../types
|
|
1
|
+
import { Big } from "../big";
|
|
2
|
+
import type { BigObject, PossibleNumber } from "../types";
|
|
3
3
|
/**
|
|
4
4
|
* Creates a new Big instance from the given value.
|
|
5
5
|
* If the value is already a Big instance, it returns the value itself.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { BigObject } from "../types
|
|
2
|
-
import type { Big } from "../big
|
|
1
|
+
import type { BigObject } from "../types";
|
|
2
|
+
import type { Big } from "../big";
|
|
3
3
|
/**
|
|
4
4
|
* Determines if the value is a BigObject. A BigObject is an object with a value property of type bigint and a scale property of type number. It usually represents a Big instance.
|
|
5
5
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "big.esm",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "A small, fast JavaScript library for arbitrary-precision decimal arithmetic.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"main": "dist/big.esm.umd.cjs",
|
|
22
22
|
"module": "dist/big.esm.js",
|
|
23
|
-
"types": "dist/
|
|
23
|
+
"types": "dist/index.d.ts",
|
|
24
24
|
"files": [
|
|
25
25
|
"dist/*",
|
|
26
26
|
"package.json",
|