big.esm 1.2.0 → 1.2.1

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 CHANGED
@@ -1,3 +1,15 @@
1
+ ## [1.2.1](https://github.com/dschewchenko/big.esm/compare/v1.2.0...v1.2.1) (2023-05-28)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * types path ([03a2b9a](https://github.com/dschewchenko/big.esm/commit/03a2b9a6ccac8bea3b67163568f402fe8d6309bd))
7
+
8
+
9
+ ### Performance Improvements
10
+
11
+ * optimize pow operation and big instance ([0988711](https://github.com/dschewchenko/big.esm/commit/09887110966eaaba3046d085c85a1167e47f6c2c))
12
+
1
13
  # [1.2.0](https://github.com/dschewchenko/big.esm/compare/v1.1.2...v1.2.0) (2023-05-19)
2
14
 
3
15
 
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
- - Tree-shaking is supported.
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
- #### `addBig(a: Big, b: Big): Big`
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 | undefined} [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.
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 | undefined);
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 M = (e, t, n) => t in e ? O(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var I = (e, t, n) => (M(e, typeof t != "symbol" ? t + "" : t, n), n);
4
- const D = (e) => typeof e == "bigint" || typeof e == "number" || typeof e == "string" && !isNaN(Number(e)), A = /0+$/, R = (e) => e.replace(A, "");
5
- const B = BigInt(0), d = BigInt(1), p = BigInt(10);
6
- function a(e, t) {
7
- return e instanceof v ? e : new v(e, t);
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 _(e, t = !1, n = !0) {
10
- const r = typeof e == "number" ? e.toString() : e;
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 ? a(B) : { value: B, scale: 0 };
15
- let [s, i] = r.split("e");
14
+ return n ? u(m) : { value: m, scale: 0 };
15
+ let [s, a] = r.split("e");
16
16
  const g = s.startsWith("-") ? "-" : "";
17
- g && (s = s.slice(1));
18
- let [u, l = ""] = s.split(".");
19
- t && (l = "");
20
- const o = parseInt(i);
21
- if (o > 0) {
22
- const f = Math.min(o, l.length);
23
- u += l.slice(0, f), l = l.slice(f), f < o && (u += "0".repeat(o - f));
24
- } else if (o < 0) {
25
- const f = Math.min(-o, u.length);
26
- l = u.slice(-f) + l, u = u.slice(0, u.length - f), f < -o && (l = "0".repeat(-o - f) + 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 + u + l), c = l.length;
29
- return n ? a(h, c) : { value: h, scale: c };
28
+ const h = BigInt(g + o + l), c = l.length;
29
+ return n ? u(h, c) : { value: h, scale: c };
30
30
  }
31
- function j(e) {
32
- return e === null || typeof e != "object" ? !1 : "value" in e && "scale" in e && typeof e.value == "bigint" && typeof e.scale == "number";
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 v {
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
- I(this, "value");
46
+ v(this, "value");
47
47
  /**
48
48
  * The scale of the Big instance, representing the number of decimal places.
49
49
  */
50
- I(this, "scale");
51
- if (t instanceof v || j(t))
50
+ v(this, "scale");
51
+ if (R(t))
52
52
  this.value = t.value, this.scale = t.scale;
53
- else if (D(t)) {
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: i } = _(t, r, !1);
59
- this.value = s, this.scale = r ? n : i;
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 > B) {
84
- const i = n.length > this.scale ? n.length - Number(this.scale) : 0;
85
- s = n.slice(i).padStart(Number(this.scale), "0"), t && (s = R(s)), s.length > 0 && (s = `.${s}`), n = n.slice(0, i);
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 = p ** BigInt(Math.abs(r));
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 i = r > 0 ? e : a(e.value * s, t.scale), g = r < 0 ? t : a(t.value * s, e.scale);
106
- return [i, g];
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 y(e, t, n = !1) {
109
- const [r, s] = E(e, t), i = r.value + s.value;
110
- return n ? (e.value = i, e.scale = r.scale, e) : a(i, r.scale);
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) : a(r, s);
118
+ return n ? (e.value = r, e.scale = s, e) : u(r, s);
119
119
  }
120
- const S = (e) => e.value === B;
121
- function m(e, t, n = 20, r = "half-up", s = !1) {
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 i = Math.max(e.scale, t.scale), g = Math.max(0, n), u = e.value * p ** BigInt(i + g - e.scale), l = t.value * p ** BigInt(i - t.scale), o = u / l, h = u % l;
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 = o;
128
+ c = i;
129
129
  break;
130
130
  case "up":
131
- c = h !== B ? o + d : o + B;
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 ? o + d : o;
135
+ c = h * BigInt(2) >= l ? i + d : i;
136
136
  break;
137
137
  }
138
- return s ? (e.value = c, e.scale = g, e) : a(c, g);
138
+ return s ? (e.value = c, e.scale = g, e) : u(c, g);
139
139
  }
140
- function G(e, t, n = !1) {
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 = m(e, t, 0, "down");
143
+ const r = B(e, t, 0, "down");
144
144
  if (n)
145
- return w(r, t, !0), N(e, r, !0);
146
- const s = w(r, t);
147
- return N(e, s);
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
- let r = a(1), s = a(e);
153
- for (t = Math.abs(t); t > 0; )
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 P = (e, t) => {
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 $(e, t = !1) {
162
- const n = e.value < B ? -e.value : e.value;
163
- return t ? (e.value = n, e) : a(n, e.scale);
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 Z(e, t = 2, n = 20, r = !1) {
163
+ function G(e, t = 2, n = 20, r = !1) {
166
164
  if (S(e))
167
- return a(0);
165
+ return u(0);
168
166
  if (e.valueOf() === BigInt(1))
169
- return a(1);
170
- if (e.value < B && t % 2 === 0)
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 = a(n === 0 ? "1" : "0." + "0".repeat(n - 1) + "1"), i = a(t), g = a(t - 1), u = a(2);
177
- let l = m(y(e, m(e, u, n)), u, n), o;
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
- o = l;
180
- const T = y(w(g, l), m(e, b(l, t - 1), n));
181
- l = m(T, i, n);
182
- } while (P($(N(o, l)), s) === 1);
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 a(f);
185
+ return u(f);
188
186
  }
189
- const k = (e) => new v(e.value, e.scale);
187
+ const V = (e) => new p(e.value, e.scale);
190
188
  export {
191
- v as Big,
192
- $ as absBig,
193
- y as addBig,
189
+ p as Big,
190
+ P as absBig,
191
+ T as addBig,
194
192
  E as alignScale,
195
- k as cloneBig,
196
- P as compareBig,
197
- a as createBig,
198
- m as divBig,
199
- _ as fromString,
200
- j as isBigObject,
201
- D as isNumericValue,
202
- G as modBig,
203
- w as mulBig,
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
- Z as sqrtBig,
206
- N as subBig
203
+ G as sqrtBig,
204
+ w as subBig
207
205
  };
@@ -1 +1 @@
1
- (function(s,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(s=typeof globalThis<"u"?globalThis:s||self,c((s.big=s.big||{},s.big.esm={})))})(this,function(s){"use strict";var G=Object.defineProperty;var V=(s,c,d)=>c in s?G(s,c,{enumerable:!0,configurable:!0,writable:!0,value:d}):s[c]=d;var O=(s,c,d)=>(V(s,typeof c!="symbol"?c+"":c,d),d);const c=e=>typeof e=="bigint"||typeof e=="number"||typeof e=="string"&&!isNaN(Number(e)),d=/0+$/,_=e=>e.replace(d,""),v=BigInt(0),b=BigInt(1),p=BigInt(10);function a(e,t){return e instanceof w?e:new w(e,t)}function M(e,t=!1,n=!0){const i=typeof e=="number"?e.toString():e;if(!isFinite(Number(i)))throw new Error("Invalid number");if(Number(i)===0)return n?a(v):{value:v,scale:0};let[r,u]=i.split("e");const B=r.startsWith("-")?"-":"";B&&(r=r.slice(1));let[f,l=""]=r.split(".");t&&(l="");const o=parseInt(u);if(o>0){const h=Math.min(o,l.length);f+=l.slice(0,h),l=l.slice(h),h<o&&(f+="0".repeat(o-h))}else if(o<0){const h=Math.min(-o,f.length);l=f.slice(-h)+l,f=f.slice(0,f.length-h),h<-o&&(l="0".repeat(-o-h)+l)}const m=BigInt(B+f+l),g=l.length;return n?a(m,g):{value:m,scale:g}}function j(e){return e===null||typeof e!="object"?!1:"value"in e&&"scale"in e&&typeof e.value=="bigint"&&typeof e.scale=="number"}class w{constructor(t,n){O(this,"value");O(this,"scale");if(t instanceof w||j(t))this.value=t.value,this.scale=t.scale;else if(c(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:u}=M(t,i,!1);this.value=r,this.scale=i?n:u}}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 u=n.length>this.scale?n.length-Number(this.scale):0;r=n.slice(u).padStart(Number(this.scale),"0"),t&&(r=_(r)),r.length>0&&(r=`.${r}`),n=n.slice(0,u)}return`${i}${n||"0"}${r}`}toJSON(){return this.toString()}}function S(e,t,n=!1){const i=e.scale-t.scale;if(i===0)return[e,t];const r=p**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 u=i>0?e:a(e.value*r,t.scale),B=i<0?t:a(t.value*r,e.scale);return[u,B]}function y(e,t,n=!1){const[i,r]=S(e,t),u=i.value+r.value;return n?(e.value=u,e.scale=i.scale,e):a(u,i.scale)}function E(e,t,n=!1){const[i,r]=S(e,t,n),u=i.value-r.value;return n?(e.value=u,e):a(u,i.scale)}function I(e,t,n=!1){const i=e.value*t.value,r=e.scale+t.scale;return n?(e.value=i,e.scale=r,e):a(i,r)}const T=e=>e.value===v;function N(e,t,n=20,i="half-up",r=!1){if(T(t))throw new Error("Division by zero is not allowed.");const u=Math.max(e.scale,t.scale),B=Math.max(0,n),f=e.value*p**BigInt(u+B-e.scale),l=t.value*p**BigInt(u-t.scale),o=f/l,m=f%l;let g;switch(i){case"down":g=o;break;case"up":g=m!==v?o+b:o+v;break;case"half-up":default:g=m*BigInt(2)>=l?o+b:o;break}return r?(e.value=g,e.scale=B,e):a(g,B)}function P(e,t,n=!1){if(T(t))throw new Error("Division by zero is not allowed.");const i=N(e,t,0,"down");if(n)return I(i,t,!0),E(e,i,!0);const r=I(i,t);return E(e,r)}function D(e,t=2,n=!1){if(!Number.isInteger(t)||t<0)throw new Error("The exponent must be a non-negative integer.");let i=a(1),r=a(e);for(t=Math.abs(t);t>0;)t%2===1&&(i=I(i,r,n)),r=I(r,r,n),t=Math.floor(t/2);return n?(e.value=i.value,e.scale=i.scale,e):i}const A=(e,t)=>{const[n,i]=S(e,t);return n.value>i.value?1:n.value<i.value?-1:0};function R(e,t=!1){const n=e.value<v?-e.value:e.value;return t?(e.value=n,e):a(n,e.scale)}function $(e,t=2,n=20,i=!1){if(T(e))return a(0);if(e.valueOf()===BigInt(1))return a(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=a(n===0?"1":"0."+"0".repeat(n-1)+"1"),u=a(t),B=a(t-1),f=a(2);let l=N(y(e,N(e,f,n)),f,n),o;do{o=l;const F=y(I(B,l),N(e,D(l,t-1),n));l=N(F,u,n)}while(A(R(E(o,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 a(h)}const q=e=>new w(e.value,e.scale);s.Big=w,s.absBig=R,s.addBig=y,s.alignScale=S,s.cloneBig=q,s.compareBig=A,s.createBig=a,s.divBig=N,s.fromString=M,s.isBigObject=j,s.isNumericValue=c,s.modBig=P,s.mulBig=I,s.powBig=D,s.sqrtBig=$,s.subBig=E,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "big.esm",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
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/big.esm.ts",
23
+ "types": "dist/index.d.ts",
24
24
  "files": [
25
25
  "dist/*",
26
26
  "package.json",