big.esm 1.3.1 → 1.3.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 +7 -0
- package/README.md +9 -3
- package/dist/big.d.ts +1 -1
- package/dist/big.esm.js +97 -106
- package/dist/big.esm.umd.cjs +1 -1
- package/dist/index.d.ts +19 -19
- package/dist/operations/abs.d.ts +1 -1
- package/dist/operations/add.d.ts +1 -1
- package/dist/operations/compare.d.ts +2 -2
- package/dist/operations/div.d.ts +2 -2
- package/dist/operations/max.d.ts +1 -1
- package/dist/operations/min.d.ts +1 -1
- package/dist/operations/mod.d.ts +1 -1
- package/dist/operations/mul.d.ts +1 -1
- package/dist/operations/pow.d.ts +1 -1
- package/dist/operations/sqrt.d.ts +1 -1
- package/dist/operations/sub.d.ts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/utils/align-scale.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/dist/utils/is-zero.d.ts +1 -1
- package/package.json +34 -39
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.3.2](https://github.com/dschewchenko/big.esm/compare/v1.3.1...v1.3.2) (2025-10-26)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* migrate to bun and fix dependencies ([302f12b](https://github.com/dschewchenko/big.esm/commit/302f12bcf300a0f14f2af970c34b0251e1bbda81))
|
|
7
|
+
|
|
1
8
|
## [1.3.1](https://github.com/dschewchenko/big.esm/compare/v1.3.0...v1.3.1) (2023-06-25)
|
|
2
9
|
|
|
3
10
|
|
package/README.md
CHANGED
|
@@ -18,8 +18,14 @@ Full bundle size (ESM) — 4.2 kB minified and 1.8 kB gzipped.
|
|
|
18
18
|
|
|
19
19
|
## Installation
|
|
20
20
|
|
|
21
|
-
Install `big.esm` using
|
|
22
|
-
|
|
21
|
+
Install `big.esm` using Bun:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
bun add big.esm
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
or npm:
|
|
28
|
+
|
|
23
29
|
```bash
|
|
24
30
|
npm install big.esm
|
|
25
31
|
```
|
|
@@ -43,7 +49,7 @@ console.log(result.toString()); // 22222222121.1111111101
|
|
|
43
49
|
|
|
44
50
|
## Compatibility
|
|
45
51
|
|
|
46
|
-
`big.esm` is compatible with all modern browsers and Node.js
|
|
52
|
+
`big.esm` is compatible with all modern browsers, Bun 1.0+, and Node.js 16+. It uses `BigInt` internally, so it is not compatible with older runtimes. On info from [caniuse.com](https://caniuse.com/#feat=bigint) `BigInt` is supported by 96.47% of all browsers(as of 2023-06-25).
|
|
47
53
|
|
|
48
54
|
## Notes
|
|
49
55
|
|
package/dist/big.d.ts
CHANGED
package/dist/big.esm.js
CHANGED
|
@@ -1,37 +1,40 @@
|
|
|
1
|
-
var x = Object.defineProperty;
|
|
2
|
-
var A = (e, t, n) => t in e ? x(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
-
var I = (e, t, n) => (A(e, typeof t != "symbol" ? t + "" : t, n), n);
|
|
4
|
-
const M = (e) => typeof e == "bigint" || typeof e == "number" || typeof e == "string" && !isNaN(Number(e)), _ = /0+$/, R = (e) => e.replace(_, "");
|
|
5
1
|
const m = BigInt(0), y = BigInt(1), p = BigInt(10);
|
|
6
2
|
function o(e, t) {
|
|
7
3
|
return e instanceof w ? e : new w(e, t);
|
|
8
4
|
}
|
|
9
|
-
function
|
|
5
|
+
function x(e, t = !1, n = !0) {
|
|
10
6
|
const r = e.toString();
|
|
11
|
-
if (!Number.isFinite(Number(r)))
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
s = g ? s.slice(1) : s;
|
|
18
|
-
let [u, l = ""] = s.split(".");
|
|
7
|
+
if (!Number.isFinite(Number(r))) throw new Error("Invalid number");
|
|
8
|
+
if (Number(r) === 0) return n ? o(m) : { value: m, scale: 0 };
|
|
9
|
+
let [s, a] = r.split("e");
|
|
10
|
+
const g = a ?? "0", h = s.startsWith("-") ? "-" : "";
|
|
11
|
+
s = h ? s.slice(1) : s;
|
|
12
|
+
let [i, l = ""] = s.split(".");
|
|
19
13
|
l = t ? "" : l;
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
} else if (
|
|
25
|
-
const
|
|
26
|
-
l =
|
|
14
|
+
const u = Number.parseInt(g, 10);
|
|
15
|
+
if (u > 0) {
|
|
16
|
+
const c = Math.min(u, l.length);
|
|
17
|
+
i += l.slice(0, c), l = l.slice(c), c < u && (i += "0".repeat(u - c));
|
|
18
|
+
} else if (u < 0) {
|
|
19
|
+
const c = Math.min(-u, i.length);
|
|
20
|
+
l = i.slice(-c) + l, i = i.slice(0, i.length - c), c < -u && (l = "0".repeat(-u - c) + l);
|
|
27
21
|
}
|
|
28
|
-
const
|
|
29
|
-
return n ? o(
|
|
22
|
+
const f = BigInt(h + i + l), v = l.length;
|
|
23
|
+
return n ? o(f, v) : { value: f, scale: v };
|
|
30
24
|
}
|
|
31
|
-
function
|
|
25
|
+
function D(e) {
|
|
32
26
|
return typeof e != "object" || e === null ? !1 : "value" in e && "scale" in e && typeof e.value == "bigint" && typeof e.scale == "number";
|
|
33
27
|
}
|
|
28
|
+
const A = (e) => typeof e == "bigint" || typeof e == "number" || typeof e == "string" && !Number.isNaN(Number(e)), M = /0+$/, _ = (e) => e.replace(M, "");
|
|
34
29
|
class w {
|
|
30
|
+
/**
|
|
31
|
+
* The value of the Big instance.
|
|
32
|
+
*/
|
|
33
|
+
value;
|
|
34
|
+
/**
|
|
35
|
+
* The scale of the Big instance, representing the number of decimal places.
|
|
36
|
+
*/
|
|
37
|
+
scale;
|
|
35
38
|
/**
|
|
36
39
|
* Implements the overloaded constructors for the Big class.
|
|
37
40
|
* @param {BigValue} value - The value to create the Big instance from. Can be a number, string, BigInt, or another Big instance.
|
|
@@ -40,23 +43,15 @@ class w {
|
|
|
40
43
|
* @return {Big} - A new Big instance.
|
|
41
44
|
*/
|
|
42
45
|
constructor(t, n) {
|
|
43
|
-
|
|
44
|
-
* The value of the Big instance.
|
|
45
|
-
*/
|
|
46
|
-
I(this, "value");
|
|
47
|
-
/**
|
|
48
|
-
* The scale of the Big instance, representing the number of decimal places.
|
|
49
|
-
*/
|
|
50
|
-
I(this, "scale");
|
|
51
|
-
if (P(t))
|
|
46
|
+
if (D(t))
|
|
52
47
|
this.value = t.value, this.scale = t.scale;
|
|
53
|
-
else if (
|
|
48
|
+
else if (A(t)) {
|
|
54
49
|
let r = n !== void 0;
|
|
55
|
-
if (r && (typeof n != "number" && (n = Number(n)), r = !isNaN(n), n = r ? Math.floor(n) : 0), typeof t == "bigint")
|
|
50
|
+
if (r && (typeof n != "number" && (n = Number(n)), r = !Number.isNaN(n), n = r ? Math.floor(n) : 0), typeof t == "bigint")
|
|
56
51
|
this.value = t, this.scale = r ? n : 0;
|
|
57
52
|
else {
|
|
58
|
-
const { value: s, scale:
|
|
59
|
-
this.value = s, this.scale = r ? n :
|
|
53
|
+
const { value: s, scale: a } = x(t, r, !1);
|
|
54
|
+
this.value = s, this.scale = r ? n : a;
|
|
60
55
|
}
|
|
61
56
|
} else
|
|
62
57
|
throw new TypeError("Invalid type provided to Big constructor.");
|
|
@@ -81,8 +76,8 @@ class w {
|
|
|
81
76
|
r && (n = n.substring(1));
|
|
82
77
|
let s = "";
|
|
83
78
|
if (this.scale > m) {
|
|
84
|
-
const
|
|
85
|
-
s = n.slice(
|
|
79
|
+
const a = n.length > this.scale ? n.length - Number(this.scale) : 0;
|
|
80
|
+
s = n.slice(a).padStart(Number(this.scale), "0"), t && (s = _(s)), s.length > 0 && (s = `.${s}`), n = n.slice(0, a);
|
|
86
81
|
}
|
|
87
82
|
return `${r}${n || "0"}${s}`;
|
|
88
83
|
}
|
|
@@ -95,6 +90,10 @@ class w {
|
|
|
95
90
|
return this.toString();
|
|
96
91
|
}
|
|
97
92
|
}
|
|
93
|
+
function R(e, t = !1) {
|
|
94
|
+
const n = e.value < m ? -e.value : e.value;
|
|
95
|
+
return t ? (e.value = n, e) : o(n, e.scale);
|
|
96
|
+
}
|
|
98
97
|
function S(e, t, n = !1) {
|
|
99
98
|
const r = e.scale - t.scale;
|
|
100
99
|
if (r === 0)
|
|
@@ -102,106 +101,98 @@ function S(e, t, n = !1) {
|
|
|
102
101
|
const s = p ** BigInt(Math.abs(r));
|
|
103
102
|
if (n)
|
|
104
103
|
return r > 0 ? (t.value *= s, t.scale = e.scale) : (e.value *= s, e.scale = t.scale), [e, t];
|
|
105
|
-
const
|
|
106
|
-
return [
|
|
104
|
+
const a = r > 0 ? e : o(e.value * s, t.scale), g = r < 0 ? t : o(t.value * s, e.scale);
|
|
105
|
+
return [a, g];
|
|
107
106
|
}
|
|
108
107
|
function O(e, t, n = !1) {
|
|
109
|
-
const [r, s] = S(e, t),
|
|
110
|
-
return n ? (e.value =
|
|
108
|
+
const [r, s] = S(e, t), a = r.value + s.value;
|
|
109
|
+
return n ? (e.value = a, e.scale = r.scale, e) : o(a, r.scale);
|
|
111
110
|
}
|
|
112
|
-
|
|
113
|
-
const [
|
|
114
|
-
return n
|
|
115
|
-
}
|
|
116
|
-
function E(e, t, n = !1) {
|
|
117
|
-
const r = e.value * t.value, s = e.scale + t.scale;
|
|
118
|
-
return n ? (e.value = r, e.scale = s, e) : o(r, s);
|
|
119
|
-
}
|
|
120
|
-
const d = (e) => e.value === m;
|
|
111
|
+
const d = (e, t) => {
|
|
112
|
+
const [n, r] = S(e, t);
|
|
113
|
+
return n.value > r.value ? 1 : n.value < r.value ? -1 : 0;
|
|
114
|
+
}, T = (e) => e.value === m;
|
|
121
115
|
function B(e, t, n = 20, r = "half-up", s = !1) {
|
|
122
|
-
if (
|
|
116
|
+
if (T(t))
|
|
123
117
|
throw new Error("Division by zero is not allowed.");
|
|
124
|
-
const
|
|
125
|
-
let
|
|
118
|
+
const a = Math.max(e.scale, t.scale), g = Math.max(0, n), h = e.value * p ** BigInt(a + g - e.scale), i = t.value * p ** BigInt(a - t.scale), l = h / i, u = h % i;
|
|
119
|
+
let f = l;
|
|
126
120
|
switch (r) {
|
|
127
121
|
case "down":
|
|
128
|
-
c = a;
|
|
129
122
|
break;
|
|
130
123
|
case "up":
|
|
131
|
-
|
|
124
|
+
f = u !== m ? l + y : l + m;
|
|
132
125
|
break;
|
|
133
|
-
case "half-up":
|
|
134
126
|
default:
|
|
135
|
-
|
|
127
|
+
f = u * BigInt(2) >= i ? l + y : l;
|
|
136
128
|
break;
|
|
137
129
|
}
|
|
138
|
-
return s ? (e.value =
|
|
130
|
+
return s ? (e.value = f, e.scale = g, e) : o(f, g);
|
|
131
|
+
}
|
|
132
|
+
const I = (e) => new w(e.value, e.scale), P = (e, t, n = !1) => d(e, t) >= 0 ? n ? e : I(e) : n ? t : I(t), $ = (e, t, n = !1) => d(e, t) > 0 ? n ? t : I(t) : n ? e : I(e);
|
|
133
|
+
function N(e, t, n = !1) {
|
|
134
|
+
const r = e.value * t.value, s = e.scale + t.scale;
|
|
135
|
+
return n ? (e.value = r, e.scale = s, e) : o(r, s);
|
|
136
|
+
}
|
|
137
|
+
function E(e, t, n = !1) {
|
|
138
|
+
const [r, s] = S(e, t, n), a = r.value - s.value;
|
|
139
|
+
return n ? (e.value = a, e) : o(a, r.scale);
|
|
139
140
|
}
|
|
140
|
-
function
|
|
141
|
-
if (
|
|
141
|
+
function F(e, t, n = !1) {
|
|
142
|
+
if (T(t))
|
|
142
143
|
throw new Error("Division by zero is not allowed.");
|
|
143
144
|
const r = B(e, t, 0, "down");
|
|
144
145
|
if (n)
|
|
145
|
-
return
|
|
146
|
-
const s =
|
|
147
|
-
return
|
|
146
|
+
return N(r, t, !0), E(e, r, !0);
|
|
147
|
+
const s = N(r, t);
|
|
148
|
+
return E(e, s);
|
|
148
149
|
}
|
|
149
|
-
function
|
|
150
|
+
function j(e, t = 2, n = !1) {
|
|
150
151
|
if (!Number.isInteger(t) || t < 0)
|
|
151
152
|
throw new Error("The exponent must be a non-negative integer.");
|
|
152
153
|
const r = e.value ** BigInt(t), s = e.scale * t;
|
|
153
154
|
return n ? (e.value = r, e.scale = s, e) : o(r, s);
|
|
154
155
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
};
|
|
159
|
-
function F(e, t = !1) {
|
|
160
|
-
const n = e.value < m ? -e.value : e.value;
|
|
161
|
-
return t ? (e.value = n, e) : o(n, e.scale);
|
|
162
|
-
}
|
|
163
|
-
function Z(e, t = 2, n = 20, r = !1) {
|
|
164
|
-
if (d(e))
|
|
165
|
-
return o(0);
|
|
166
|
-
if (e.valueOf() === BigInt(1))
|
|
167
|
-
return o(1);
|
|
156
|
+
function G(e, t = 2, n = 20, r = !1) {
|
|
157
|
+
if (T(e)) return o(0);
|
|
158
|
+
if (e.valueOf() === BigInt(1)) return o(1);
|
|
168
159
|
if (e.value < m && t % 2 === 0)
|
|
169
160
|
throw new Error("The root must be an odd integer when the number is negative.");
|
|
170
|
-
if (!Number.isInteger(t) || t < 2)
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const s = o(n === 0 ? "1" : "0." + "0".repeat(n - 1) + "1"), i = o(t), g = o(t - 1), u = o(2);
|
|
175
|
-
let l = B(O(e, B(e, u, n)), u, n), a;
|
|
161
|
+
if (!Number.isInteger(t) || t < 2) throw new Error("The root must be an integer and greater than 1");
|
|
162
|
+
if (n < 0) throw new Error("The precision must be a non-negative integer.");
|
|
163
|
+
const s = o(n === 0 ? "1" : `0.${"0".repeat(n - 1)}1`), a = o(t), g = o(t - 1), h = o(2);
|
|
164
|
+
let i = B(O(e, B(e, h, n)), h, n), l;
|
|
176
165
|
do {
|
|
177
|
-
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
166
|
+
l = i;
|
|
167
|
+
const c = O(
|
|
168
|
+
N(g, i),
|
|
169
|
+
B(e, j(i, t - 1), n)
|
|
170
|
+
);
|
|
171
|
+
i = B(c, a, n);
|
|
172
|
+
} while (d(R(E(l, i)), s) === 1);
|
|
173
|
+
const u = i.toString();
|
|
182
174
|
if (r)
|
|
183
|
-
return e.value =
|
|
184
|
-
const
|
|
185
|
-
return o(
|
|
175
|
+
return e.value = i.value, e.scale = n, e;
|
|
176
|
+
const f = u.indexOf("."), v = f !== -1 ? u.slice(0, f + n + 1) : u;
|
|
177
|
+
return o(v);
|
|
186
178
|
}
|
|
187
|
-
const v = (e) => new w(e.value, e.scale), k = (e, t, n = !1) => T(e, t) > 0 ? n ? t : v(t) : n ? e : v(e), q = (e, t, n = !1) => T(e, t) >= 0 ? n ? e : v(e) : n ? t : v(t);
|
|
188
179
|
export {
|
|
189
180
|
w as Big,
|
|
190
|
-
|
|
181
|
+
R as absBig,
|
|
191
182
|
O as addBig,
|
|
192
183
|
S as alignScale,
|
|
193
|
-
|
|
194
|
-
|
|
184
|
+
I as cloneBig,
|
|
185
|
+
d as compareBig,
|
|
195
186
|
o as createBig,
|
|
196
187
|
B as divBig,
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
188
|
+
x as fromString,
|
|
189
|
+
D as isBigObject,
|
|
190
|
+
A as isNumericValue,
|
|
191
|
+
P as maxBig,
|
|
192
|
+
$ as minBig,
|
|
193
|
+
F as modBig,
|
|
194
|
+
N as mulBig,
|
|
195
|
+
j as powBig,
|
|
196
|
+
G as sqrtBig,
|
|
197
|
+
E as subBig
|
|
207
198
|
};
|
package/dist/big.esm.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(s,I){typeof exports=="object"&&typeof module<"u"?I(exports):typeof define=="function"&&define.amd?define(["exports"],I):(s=typeof globalThis<"u"?globalThis:s||self,I((s.big=s.big||{},s.big.esm={})))})(this,(function(s){"use strict";const m=BigInt(0),j=BigInt(1),T=BigInt(10);function c(e,t){return e instanceof w?e:new w(e,t)}function D(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?c(m):{value:m,scale:0};let[r,a]=i.split("e");const B=a??"0",h=r.startsWith("-")?"-":"";r=h?r.slice(1):r;let[u,l=""]=r.split(".");l=t?"":l;const o=Number.parseInt(B,10);if(o>0){const f=Math.min(o,l.length);u+=l.slice(0,f),l=l.slice(f),f<o&&(u+="0".repeat(o-f))}else if(o<0){const f=Math.min(-o,u.length);l=u.slice(-f)+l,u=u.slice(0,u.length-f),f<-o&&(l="0".repeat(-o-f)+l)}const g=BigInt(h+u+l),y=l.length;return n?c(g,y):{value:g,scale:y}}function M(e){return typeof e!="object"||e===null?!1:"value"in e&&"scale"in e&&typeof e.value=="bigint"&&typeof e.scale=="number"}const A=e=>typeof e=="bigint"||typeof e=="number"||typeof e=="string"&&!Number.isNaN(Number(e)),R=/0+$/,$=e=>e.replace(R,"");class w{value;scale;constructor(t,n){if(M(t))this.value=t.value,this.scale=t.scale;else if(A(t)){let i=n!==void 0;if(i&&(typeof n!="number"&&(n=Number(n)),i=!Number.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}=D(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>m){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.length>0&&(r=`.${r}`),n=n.slice(0,a)}return`${i}${n||"0"}${r}`}toJSON(){return this.toString()}}function _(e,t=!1){const n=e.value<m?-e.value:e.value;return t?(e.value=n,e):c(n,e.scale)}function N(e,t,n=!1){const i=e.scale-t.scale;if(i===0)return[e,t];const r=T**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:c(e.value*r,t.scale),B=i<0?t:c(t.value*r,e.scale);return[a,B]}function O(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):c(a,i.scale)}const S=(e,t)=>{const[n,i]=N(e,t);return n.value>i.value?1:n.value<i.value?-1:0},b=e=>e.value===m;function v(e,t,n=20,i="half-up",r=!1){if(b(t))throw new Error("Division by zero is not allowed.");const a=Math.max(e.scale,t.scale),B=Math.max(0,n),h=e.value*T**BigInt(a+B-e.scale),u=t.value*T**BigInt(a-t.scale),l=h/u,o=h%u;let g=l;switch(i){case"down":break;case"up":g=o!==m?l+j:l+m;break;default:g=o*BigInt(2)>=u?l+j:l;break}return r?(e.value=g,e.scale=B,e):c(g,B)}const d=e=>new w(e.value,e.scale),V=(e,t,n=!1)=>S(e,t)>=0?n?e:d(e):n?t:d(t),q=(e,t,n=!1)=>S(e,t)>0?n?t:d(t):n?e:d(e);function E(e,t,n=!1){const i=e.value*t.value,r=e.scale+t.scale;return n?(e.value=i,e.scale=r,e):c(i,r)}function p(e,t,n=!1){const[i,r]=N(e,t,n),a=i.value-r.value;return n?(e.value=a,e):c(a,i.scale)}function F(e,t,n=!1){if(b(t))throw new Error("Division by zero is not allowed.");const i=v(e,t,0,"down");if(n)return E(i,t,!0),p(e,i,!0);const r=E(i,t);return p(e,r)}function P(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):c(i,r)}function G(e,t=2,n=20,i=!1){if(b(e))return c(0);if(e.valueOf()===BigInt(1))return c(1);if(e.value<m&&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=c(n===0?"1":`0.${"0".repeat(n-1)}1`),a=c(t),B=c(t-1),h=c(2);let u=v(O(e,v(e,h,n)),h,n),l;do{l=u;const f=O(E(B,u),v(e,P(u,t-1),n));u=v(f,a,n)}while(S(_(p(l,u)),r)===1);const o=u.toString();if(i)return e.value=u.value,e.scale=n,e;const g=o.indexOf("."),y=g!==-1?o.slice(0,g+n+1):o;return c(y)}s.Big=w,s.absBig=_,s.addBig=O,s.alignScale=N,s.cloneBig=d,s.compareBig=S,s.createBig=c,s.divBig=v,s.fromString=D,s.isBigObject=M,s.isNumericValue=A,s.maxBig=V,s.minBig=q,s.modBig=F,s.mulBig=E,s.powBig=P,s.sqrtBig=G,s.subBig=p,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
export { Big } from
|
|
2
|
-
export
|
|
3
|
-
export { addBig } from
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
15
|
-
export {
|
|
16
|
-
export {
|
|
17
|
-
export {
|
|
18
|
-
export {
|
|
19
|
-
export {
|
|
1
|
+
export { Big } from './big';
|
|
2
|
+
export { absBig } from './operations/abs';
|
|
3
|
+
export { addBig } from './operations/add';
|
|
4
|
+
export { compareBig } from './operations/compare';
|
|
5
|
+
export { divBig } from './operations/div';
|
|
6
|
+
export { maxBig } from './operations/max';
|
|
7
|
+
export { minBig } from './operations/min';
|
|
8
|
+
export { modBig } from './operations/mod';
|
|
9
|
+
export { mulBig } from './operations/mul';
|
|
10
|
+
export { powBig } from './operations/pow';
|
|
11
|
+
export { sqrtBig } from './operations/sqrt';
|
|
12
|
+
export { subBig } from './operations/sub';
|
|
13
|
+
export type { BigValue, CompareResult, PossibleNumber, RoundingMode } from './types';
|
|
14
|
+
export { alignScale } from './utils/align-scale';
|
|
15
|
+
export { cloneBig } from './utils/clone';
|
|
16
|
+
export { createBig } from './utils/create';
|
|
17
|
+
export { fromString } from './utils/from-string';
|
|
18
|
+
export { isBigObject } from './utils/is-big-object';
|
|
19
|
+
export { isNumericValue } from './utils/numeric';
|
package/dist/operations/abs.d.ts
CHANGED
package/dist/operations/add.d.ts
CHANGED
package/dist/operations/div.d.ts
CHANGED
package/dist/operations/max.d.ts
CHANGED
package/dist/operations/min.d.ts
CHANGED
package/dist/operations/mod.d.ts
CHANGED
package/dist/operations/mul.d.ts
CHANGED
package/dist/operations/pow.d.ts
CHANGED
package/dist/operations/sub.d.ts
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Big } from '../big';
|
|
2
2
|
/**
|
|
3
3
|
* Aligns the scale(decimal places) of two Big instances before performing arithmetic operations.
|
|
4
4
|
* It takes two Big instances as input and returns a tuple (array) of two new Big instances with the same scale.
|
package/dist/utils/clone.d.ts
CHANGED
package/dist/utils/create.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Big } from
|
|
2
|
-
import
|
|
1
|
+
import { Big } from '../big';
|
|
2
|
+
import { 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
|
|
2
|
-
import
|
|
1
|
+
import { Big } from '../big';
|
|
2
|
+
import { BigObject } from '../types';
|
|
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/dist/utils/is-zero.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "big.esm",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "A small, fast JavaScript library for arbitrary-precision decimal arithmetic.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"dev": "vite",
|
|
8
|
-
"build": "tsc && vite build",
|
|
9
|
-
"preview": "vite preview",
|
|
10
|
-
"test": "vitest",
|
|
11
|
-
"test:ui": "vitest --ui",
|
|
12
|
-
"test:run": "vitest run",
|
|
13
|
-
"coverage": "vitest run --coverage",
|
|
14
|
-
"docs": "typedoc --out docs",
|
|
15
|
-
"lint": "
|
|
16
|
-
"lint:fix": "
|
|
17
|
-
"benchmark": "
|
|
18
|
-
"semantic-release": "semantic-release",
|
|
19
|
-
"prepare": "is-ci || husky
|
|
7
|
+
"dev": "bunx vite",
|
|
8
|
+
"build": "bunx tsc && bunx vite build",
|
|
9
|
+
"preview": "bunx vite preview",
|
|
10
|
+
"test": "bunx vitest",
|
|
11
|
+
"test:ui": "bunx vitest --ui",
|
|
12
|
+
"test:run": "bunx vitest run",
|
|
13
|
+
"coverage": "bunx vitest run --coverage",
|
|
14
|
+
"docs": "bunx typedoc --out docs",
|
|
15
|
+
"lint": "bunx biome check",
|
|
16
|
+
"lint:fix": "bun run lint -- --write",
|
|
17
|
+
"benchmark": "bun benchmark.js",
|
|
18
|
+
"semantic-release": "bunx semantic-release",
|
|
19
|
+
"prepare": "bunx is-ci || bunx husky"
|
|
20
20
|
},
|
|
21
21
|
"main": "dist/big.esm.umd.cjs",
|
|
22
22
|
"module": "dist/big.esm.js",
|
|
@@ -46,37 +46,32 @@
|
|
|
46
46
|
"url": "https://github.com/dschewchenko/big.esm/issues"
|
|
47
47
|
},
|
|
48
48
|
"homepage": "https://github.com/dschewchenko/big.esm#readme",
|
|
49
|
+
"packageManager": "bun@1.3.1",
|
|
49
50
|
"engines": {
|
|
51
|
+
"bun": ">=1.0.0",
|
|
50
52
|
"node": ">=16"
|
|
51
53
|
},
|
|
52
54
|
"devDependencies": {
|
|
53
|
-
"@
|
|
54
|
-
"@commitlint/
|
|
55
|
+
"@biomejs/biome": "2.3.0",
|
|
56
|
+
"@commitlint/cli": "^20.1.0",
|
|
57
|
+
"@commitlint/config-conventional": "^20.0.0",
|
|
55
58
|
"@semantic-release/changelog": "^6.0.3",
|
|
56
59
|
"@semantic-release/git": "^10.0.1",
|
|
57
|
-
"@types/
|
|
58
|
-
"@
|
|
59
|
-
"@
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"is-ci": "^3.0.1",
|
|
69
|
-
"prettier": "^2.8.8",
|
|
70
|
-
"rollup-plugin-visualizer": "^5.9.0",
|
|
71
|
-
"semantic-release": "^21.0.5",
|
|
72
|
-
"ts-jest": "^29.1.0",
|
|
73
|
-
"typedoc": "^0.24.8",
|
|
74
|
-
"typedoc-plugin-mdn-links": "^3.0.3",
|
|
75
|
-
"typedoc-plugin-merge-modules": "^5.0.1",
|
|
60
|
+
"@types/node": "^24.9.1",
|
|
61
|
+
"@vitest/ui": "^4.0.3",
|
|
62
|
+
"@vitest/coverage-v8": "^4.0.3",
|
|
63
|
+
"big.js": "^7.0.1",
|
|
64
|
+
"husky": "^9.1.7",
|
|
65
|
+
"is-ci": "^4.1.0",
|
|
66
|
+
"rollup-plugin-visualizer": "^6.0.5",
|
|
67
|
+
"semantic-release": "^25.0.1",
|
|
68
|
+
"typedoc": "^0.28.14",
|
|
69
|
+
"typedoc-plugin-mdn-links": "^5.0.10",
|
|
70
|
+
"typedoc-plugin-merge-modules": "^7.0.0",
|
|
76
71
|
"typedoc-plugin-pages": "^1.1.0",
|
|
77
|
-
"typescript": "^5.
|
|
78
|
-
"vite": "^
|
|
79
|
-
"vite-plugin-dts": "^
|
|
80
|
-
"vitest": "^0.
|
|
72
|
+
"typescript": "^5.9.3",
|
|
73
|
+
"vite": "^7.1.12",
|
|
74
|
+
"vite-plugin-dts": "^4.5.4",
|
|
75
|
+
"vitest": "^4.0.3"
|
|
81
76
|
}
|
|
82
77
|
}
|