big.esm 1.0.2 → 1.1.0

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,10 @@
1
+ # [1.1.0](https://github.com/dschewchenko/big.esm/compare/v1.0.2...v1.1.0) (2023-05-14)
2
+
3
+
4
+ ### Features
5
+
6
+ * to string must return value without zeros by default ([1938f08](https://github.com/dschewchenko/big.esm/commit/1938f0885a478b768f90c797bae53b6320e8b683))
7
+
1
8
  ## [1.0.2](https://github.com/dschewchenko/big.esm/compare/v1.0.1...v1.0.2) (2023-05-13)
2
9
 
3
10
 
package/README.md CHANGED
@@ -14,10 +14,11 @@ Fully written in TypeScript, so it provides type definitions out of the box.
14
14
 
15
15
  Tree-shaking is supported.
16
16
 
17
- Full bundle size(ES) — 5.48 kB minified and 1.98 kB gzipped.
18
- `sqrtBig` and `powBig` are half of this size.
17
+ Full bundle size(ESM) — 3.12 kB minified and 1.42 kB gzipped.
18
+ `powBig` operation is half of this size, 1.5kB/0.7kB(minified/gzip),
19
+ because it's big and reuses most of the operations from `big.esm`.
19
20
 
20
- Full bundle size(UMD) — 3.52 kB minified and 1.58 kB gzipped.
21
+ Full bundle size(UMD) — 3.43 kB minified and 1.57 kB gzipped.
21
22
 
22
23
  ## Installation
23
24
 
@@ -118,32 +119,32 @@ Compares two `Big` instances. Returns `-1` if `a < b`, `0` if `a == b` and `1` i
118
119
 
119
120
  Compare `big.esm` with `big.js`. 100_000 iterations for each operation.
120
121
 
121
- | Operation | big.esm | big.js | Difference |
122
- | --- | --- | --- | --- |
123
- | init - smallInt | 40.538ms | 23.042ms | -75.93% slower |
124
- | add - smallInt | 25.755ms | 15.443ms | -66.77% slower |
125
- | subtract - smallInt | 22.998ms | 15.419ms | -49.15% slower |
126
- | multiply - smallInt | 22.684ms | 19.931ms | -13.81% slower |
127
- | divide - smallInt | 67.082ms | 182.769ms | 63.30% faster |
128
- | power of 4 - smallInt | 115.589ms | 40.343ms | -186.51% slower |
129
- | init - smallNumber | 45.344ms | 37.790ms | -19.99% slower |
130
- | add - smallNumber | 21.636ms | 22.357ms | 3.23% faster |
131
- | subtract - smallNumber | 21.750ms | 24.691ms | 11.91% faster |
132
- | multiply - smallNumber | 23.852ms | 35.742ms | 33.27% faster |
133
- | divide - smallNumber | 61.577ms | 194.170ms | 68.29% faster |
134
- | power of 4 - smallNumber | 137.407ms | 70.480ms | -94.96% slower |
135
- | init - bigInt | 51.163ms | 37.148ms | -37.73% slower |
136
- | add - bigInt | 27.229ms | 25.447ms | -7.00% slower |
137
- | subtract - bigInt | 27.146ms | 24.872ms | -9.14% slower |
138
- | multiply - bigInt | 33.915ms | 124.638ms | 72.79% faster |
139
- | divide - bigInt | 81.944ms | 624.192ms | 86.87% faster |
140
- | power of 4 - bigInt | 251.438ms | 512.083ms | 50.90% faster |
141
- | init - bigNumber | 57.123ms | 77.780ms | 26.56% faster |
142
- | add - bigNumber | 30.457ms | 49.525ms | 38.50% faster |
143
- | subtract - bigNumber | 30.979ms | 49.906ms | 37.93% faster |
144
- | multiply - bigNumber | 41.303ms | 271.533ms | 84.79% faster |
145
- | divide - bigNumber | 81.252ms | 940.948ms | 91.36% faster |
146
- | power of 4 - bigNumber | 375.813ms | 1281.233ms | 70.67% faster |
122
+ | Operation | big.esm | big.js | Difference |
123
+ |--------------------------|-----------|------------|-----------------|
124
+ | init - smallInt | 39.856ms | 22.169ms | -79.78% slower |
125
+ | add - smallInt | 24.227ms | 15.125ms | -60.17% slower |
126
+ | subtract - smallInt | 22.181ms | 15.094ms | -46.95% slower |
127
+ | multiply - smallInt | 22.276ms | 18.538ms | -20.16% slower |
128
+ | divide - smallInt | 66.923ms | 179.699ms | 62.76% faster |
129
+ | power of 4 - smallInt | 113.714ms | 39.359ms | -188.92% slower |
130
+ | init - smallNumber | 44.606ms | 37.136ms | -20.12% slower |
131
+ | add - smallNumber | 21.719ms | 21.857ms | 0.63% faster |
132
+ | subtract - smallNumber | 21.090ms | 24.064ms | 12.36% faster |
133
+ | multiply - smallNumber | 23.246ms | 35.010ms | 33.60% faster |
134
+ | divide - smallNumber | 60.102ms | 189.603ms | 68.30% faster |
135
+ | power of 4 - smallNumber | 136.611ms | 68.859ms | -98.39% slower |
136
+ | init - bigInt | 50.278ms | 36.880ms | -36.33% slower |
137
+ | add - bigInt | 27.485ms | 25.402ms | -8.20% slower |
138
+ | subtract - bigInt | 27.402ms | 24.622ms | -11.29% slower |
139
+ | multiply - bigInt | 33.650ms | 121.126ms | 72.22% faster |
140
+ | divide - bigInt | 79.523ms | 602.879ms | 86.81% faster |
141
+ | power of 4 - bigInt | 248.514ms | 499.246ms | 50.22% faster |
142
+ | init - bigNumber | 55.661ms | 77.789ms | 28.45% faster |
143
+ | add - bigNumber | 29.755ms | 47.843ms | 37.81% faster |
144
+ | subtract - bigNumber | 29.107ms | 47.313ms | 38.48% faster |
145
+ | multiply - bigNumber | 39.976ms | 266.814ms | 85.02% faster |
146
+ | divide - bigNumber | 78.278ms | 931.610ms | 91.60% faster |
147
+ | power of 4 - bigNumber | 376.169ms | 1132.657ms | 66.79% faster |
147
148
 
148
149
  #### Test data:
149
150
 
package/dist/big.d.ts CHANGED
@@ -57,9 +57,10 @@ export declare class Big {
57
57
  /**
58
58
  * Returns a string representation of the Big instance.
59
59
  *
60
+ * @param {boolean} [shouldTrimZeros=true] - Whether to trim trailing zeros from the fractional part. Defaults to true.
60
61
  * @return {string} - A string representation of the Big instance.
61
62
  */
62
- toString(): string;
63
+ toString(shouldTrimZeros?: boolean): string;
63
64
  /**
64
65
  * Returns the JSON representation of the Big instance.
65
66
  *
package/dist/big.esm.js CHANGED
@@ -1,11 +1,9 @@
1
- var y = Object.defineProperty;
2
- var T = (e, t, n) => t in e ? y(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var v = (e, t, n) => (T(e, typeof t != "symbol" ? t + "" : t, n), n);
4
- function D(e) {
5
- return typeof e == "bigint" || typeof e == "number" || typeof e == "string" && !isNaN(Number(e));
6
- }
7
- const p = 20, g = BigInt(0);
8
- class f {
1
+ var N = Object.defineProperty;
2
+ var T = (n, t, e) => t in n ? N(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
+ var m = (n, t, e) => (T(n, typeof t != "symbol" ? t + "" : t, e), e);
4
+ const b = (n) => typeof n == "bigint" || typeof n == "number" || typeof n == "string" && !isNaN(Number(n)), A = /0+$/, M = (n) => n.replace(A, "");
5
+ const g = BigInt(0);
6
+ class B {
9
7
  /**
10
8
  * Implements the overloaded constructors for the Big class.
11
9
  * @param {BigValue} value - The value to create the Big instance from. Can be a number, string, BigInt, or another Big instance.
@@ -13,23 +11,22 @@ class f {
13
11
  * @throws {TypeError} - If the value is not a number, string, BigInt, or Big instance.
14
12
  * @return {Big} - A new Big instance.
15
13
  */
16
- constructor(t, n) {
14
+ constructor(t, e) {
17
15
  /**
18
16
  * The value of the Big instance.
19
17
  */
20
- v(this, "value");
18
+ m(this, "value");
21
19
  /**
22
20
  * The scale of the Big instance, representing the number of decimal places.
23
21
  */
24
- v(this, "scale");
25
- if (t instanceof f)
22
+ m(this, "scale");
23
+ if (t instanceof B)
26
24
  this.value = t.value, this.scale = t.scale;
27
- else if (D(t)) {
25
+ else if (b(t)) {
28
26
  let [r, i = ""] = t.toString().split(".");
29
- n !== void 0 && (typeof n != "number" && (n = Number(n)), n = Math.floor(n), i && (i = ""), r.length < n && (r = r.padEnd(n, "0"))), this.value = BigInt(r + i), this.scale = i ? i.length : n ?? 0;
27
+ e !== void 0 && (typeof e != "number" && (e = Number(e)), e = Math.floor(e), i && (i = ""), r.length < e && (r = r.padEnd(e, "0"))), this.value = BigInt(r + i), this.scale = i ? i.length : e ?? 0;
30
28
  } else
31
29
  throw new TypeError("Invalid type provided to Big constructor.");
32
- return this;
33
30
  }
34
31
  /**
35
32
  * Returns the primitive value of the Big instance.
@@ -42,18 +39,19 @@ class f {
42
39
  /**
43
40
  * Returns a string representation of the Big instance.
44
41
  *
42
+ * @param {boolean} [shouldTrimZeros=true] - Whether to trim trailing zeros from the fractional part. Defaults to true.
45
43
  * @return {string} - A string representation of the Big instance.
46
44
  */
47
- toString() {
48
- let t = this.value.toString();
49
- const n = t.startsWith("-") ? "-" : "";
50
- n && (t = t.substring(1));
51
- let r = "";
45
+ toString(t = !0) {
46
+ let e = this.value.toString();
47
+ const r = e.startsWith("-") ? "-" : "";
48
+ r && (e = e.substring(1));
49
+ let i = "";
52
50
  if (this.scale > g) {
53
- const i = t.length > this.scale ? t.length - Number(this.scale) : 0;
54
- r = t.slice(i).padStart(Number(this.scale), "0"), r.length > 0 && (r = `.${r}`), t = t.slice(0, i);
51
+ const a = e.length > this.scale ? e.length - Number(this.scale) : 0;
52
+ i = e.slice(a).padStart(Number(this.scale), "0"), t && (i = M(i)), i.length > 0 && (i = `.${i}`), e = e.slice(0, a);
55
53
  }
56
- return `${n}${t || "0"}${r}`;
54
+ return `${r}${e || "0"}${i}`;
57
55
  }
58
56
  /**
59
57
  * Returns the JSON representation of the Big instance.
@@ -64,112 +62,106 @@ class f {
64
62
  return this.toString();
65
63
  }
66
64
  }
67
- function o(e, t) {
68
- return e instanceof f ? e : new f(e, t);
69
- }
70
- function m(e, t) {
71
- const n = e.scale - t.scale;
72
- if (n > 0) {
73
- const r = t.value * BigInt(10 ** n);
74
- return [e, o(r, e.scale)];
75
- }
76
- if (n < 0) {
77
- const r = e.value * BigInt(10 ** -n);
78
- return [o(r, t.scale), t];
79
- }
80
- return [e, t];
65
+ function o(n, t) {
66
+ return n instanceof B ? n : new B(n, t);
81
67
  }
82
- function S(e, t) {
83
- const [n, r] = m(e, t), i = n.value + r.value;
84
- return o(i, n.scale);
68
+ const O = BigInt(10);
69
+ function w(n, t) {
70
+ const e = n.scale - t.scale;
71
+ if (e === 0)
72
+ return [n, t];
73
+ const r = O ** BigInt(Math.abs(e)), i = e > 0 ? n : o(n.value * r, t.scale), a = e < 0 ? t : o(t.value * r, n.scale);
74
+ return [i, a];
85
75
  }
86
- function N(e, t) {
87
- const [n, r] = m(e, t), i = n.value - r.value;
88
- return o(i, n.scale);
76
+ function v(n, t) {
77
+ const [e, r] = w(n, t), i = e.value + r.value;
78
+ return o(i, e.scale);
89
79
  }
90
- function w(e, t) {
91
- const n = e.value * t.value, r = e.scale + t.scale;
92
- return o(n, r);
80
+ function E(n, t) {
81
+ const [e, r] = w(n, t), i = e.value - r.value;
82
+ return o(i, e.scale);
93
83
  }
94
- function d(e) {
95
- return e.value === g;
84
+ function d(n, t) {
85
+ const e = n.value * t.value, r = n.scale + t.scale;
86
+ return o(e, r);
96
87
  }
97
- function c(e, t, n = p, r = "half-up") {
98
- if (d(t))
88
+ const I = (n) => n.value === g;
89
+ function h(n, t, e = 20, r = "half-up") {
90
+ if (I(t))
99
91
  throw new Error("Division by zero is not allowed.");
100
- const i = Math.max(e.scale, t.scale), h = Math.max(0, n), B = e.value * BigInt(10) ** BigInt(i + h - e.scale), u = t.value * BigInt(10) ** BigInt(i - t.scale), a = B / u, l = B % u;
101
- let s;
92
+ const i = Math.max(n.scale, t.scale), a = Math.max(0, e), f = n.value * BigInt(10) ** BigInt(i + a - n.scale), s = t.value * BigInt(10) ** BigInt(i - t.scale), u = f / s, c = f % s;
93
+ let l;
102
94
  switch (r) {
103
95
  case "down":
104
- s = a;
96
+ l = u;
105
97
  break;
106
98
  case "up":
107
- s = l !== g ? a + BigInt(1) : a + g;
99
+ l = c !== g ? u + BigInt(1) : u + g;
108
100
  break;
109
101
  case "half-up":
110
102
  default:
111
- s = l * BigInt(2) >= u ? a + BigInt(1) : a;
103
+ l = c * BigInt(2) >= s ? u + BigInt(1) : u;
112
104
  break;
113
105
  }
114
- return o(s.toString(), h);
106
+ return o(l.toString(), a);
115
107
  }
116
- function V(e, t) {
117
- if (d(t))
108
+ function L(n, t) {
109
+ if (I(t))
118
110
  throw new Error("Division by zero is not allowed.");
119
- const n = c(e, t, 0, "down"), r = w(n, t);
120
- return N(e, r);
111
+ const e = h(n, t, 0, "down"), r = d(e, t);
112
+ return E(n, r);
121
113
  }
122
- function M(e, t) {
114
+ function y(n, t) {
123
115
  if (!Number.isInteger(t) || t < 0)
124
116
  throw new Error("The exponent must be a non-negative integer.");
125
- let n = o(1), r = o(e);
117
+ let e = o(1), r = o(n);
126
118
  for (t = Math.abs(t); t > 0; )
127
- t % 2 === 1 && (n = w(n, r)), r = w(r, r), t = Math.floor(t / 2);
128
- return n;
119
+ t % 2 === 1 && (e = d(e, r)), r = d(r, r), t = Math.floor(t / 2);
120
+ return e;
129
121
  }
130
- const O = (e, t) => {
131
- const [n, r] = m(e, t);
132
- return n.value > r.value ? 1 : n.value < r.value ? -1 : 0;
122
+ const D = (n, t) => {
123
+ const [e, r] = w(n, t);
124
+ return e.value > r.value ? 1 : e.value < r.value ? -1 : 0;
133
125
  };
134
- function A(e) {
135
- const t = e.value < BigInt(0) ? -e.value : e.value;
136
- return o(t, e.scale);
126
+ function P(n) {
127
+ const t = n.value < g ? -n.value : n.value;
128
+ return o(t, n.scale);
137
129
  }
138
- function $(e, t = 2, n = p) {
139
- if (d(e))
130
+ function _(n, t = 2, e = 20) {
131
+ if (I(n))
140
132
  return o(0);
141
- if (e.valueOf() === BigInt(1))
133
+ if (n.valueOf() === BigInt(1))
142
134
  return o(1);
143
- if (e.value < g && t % 2 === 0)
135
+ if (n.value < g && t % 2 === 0)
144
136
  throw new Error("The root must be an odd integer when the number is negative.");
145
137
  if (!Number.isInteger(t) || t < 2)
146
138
  throw new Error("The root must be an integer and greater than 1");
147
- if (n < 0)
139
+ if (e < 0)
148
140
  throw new Error("The precision must be a non-negative integer.");
149
- const r = n === 0 ? "1" : "0." + "0".repeat(n - 1) + "1", i = o(r), h = o(t), B = o(t - 1), u = o(2);
150
- let a = c(S(e, c(e, u, n)), u, n), l;
141
+ const r = o(e === 0 ? "1" : "0." + "0".repeat(e - 1) + "1"), i = o(t), a = o(t - 1), f = o(2);
142
+ let s = h(v(n, h(n, f, e)), f, e), u;
151
143
  do {
152
- l = a;
153
- const b = S(w(B, a), c(e, M(a, t - 1), n));
154
- a = c(b, h, n);
155
- } while (O(A(N(l, a)), i) === 1);
156
- const s = a.toString(), I = s.indexOf("."), E = I !== -1 ? s.slice(0, I + n + 1) : s;
157
- return o(E);
144
+ u = s;
145
+ const p = v(d(a, s), h(n, y(s, t - 1), e));
146
+ s = h(p, i, e);
147
+ } while (D(P(E(u, s)), r) === 1);
148
+ const c = s.toString(), l = c.indexOf("."), S = l !== -1 ? c.slice(0, l + e + 1) : c;
149
+ return o(S);
158
150
  }
159
- const k = (e) => new f(e.value, e.scale);
151
+ const $ = (n) => new B(n.value, n.scale);
160
152
  export {
161
- f as Big,
162
- A as absBig,
163
- S as addBig,
164
- m as alignScale,
165
- k as cloneBig,
166
- O as compareBig,
153
+ B as Big,
154
+ P as absBig,
155
+ v as addBig,
156
+ w as alignScale,
157
+ $ as cloneBig,
158
+ D as compareBig,
167
159
  o as createBig,
168
- c as divBig,
169
- D as isNumericValue,
170
- V as modBig,
171
- w as mulBig,
172
- M as powBig,
173
- $ as sqrtBig,
174
- N as subBig
160
+ h as divBig,
161
+ b as isNumericValue,
162
+ L as modBig,
163
+ d as mulBig,
164
+ y as powBig,
165
+ _ as sqrtBig,
166
+ E as subBig
175
167
  };
@@ -1 +1 @@
1
- (function(r,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(r=typeof globalThis<"u"?globalThis:r||self,a((r.big=r.big||{},r.big.esm={})))})(this,function(r){"use strict";var j=Object.defineProperty;var q=(r,a,l)=>a in r?j(r,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):r[a]=l;var y=(r,a,l)=>(q(r,typeof a!="symbol"?a+"":a,l),l);function a(e){return typeof e=="bigint"||typeof e=="number"||typeof e=="string"&&!isNaN(Number(e))}const l=20,B=BigInt(0);class g{constructor(t,n){y(this,"value");y(this,"scale");if(t instanceof g)this.value=t.value,this.scale=t.scale;else if(a(t)){let[i,u=""]=t.toString().split(".");n!==void 0&&(typeof n!="number"&&(n=Number(n)),n=Math.floor(n),u&&(u=""),i.length<n&&(i=i.padEnd(n,"0"))),this.value=BigInt(i+u),this.scale=u?u.length:n??0}else throw new TypeError("Invalid type provided to Big constructor.");return this}valueOf(){return this.value}toString(){let t=this.value.toString();const n=t.startsWith("-")?"-":"";n&&(t=t.substring(1));let i="";if(this.scale>B){const u=t.length>this.scale?t.length-Number(this.scale):0;i=t.slice(u).padStart(Number(this.scale),"0"),i.length>0&&(i=`.${i}`),t=t.slice(0,u)}return`${n}${t||"0"}${i}`}toJSON(){return this.toString()}}function o(e,t){return e instanceof g?e:new g(e,t)}function v(e,t){const n=e.scale-t.scale;if(n>0){const i=t.value*BigInt(10**n);return[e,o(i,e.scale)]}if(n<0){const i=e.value*BigInt(10**-n);return[o(i,t.scale),t]}return[e,t]}function S(e,t){const[n,i]=v(e,t),u=n.value+i.value;return o(u,n.scale)}function b(e,t){const[n,i]=v(e,t),u=n.value-i.value;return o(u,n.scale)}function d(e,t){const n=e.value*t.value,i=e.scale+t.scale;return o(n,i)}function N(e){return e.value===B}function f(e,t,n=l,i="half-up"){if(N(t))throw new Error("Division by zero is not allowed.");const u=Math.max(e.scale,t.scale),w=Math.max(0,n),I=e.value*BigInt(10)**BigInt(u+w-e.scale),h=t.value*BigInt(10)**BigInt(u-t.scale),s=I/h,m=I%h;let c;switch(i){case"down":c=s;break;case"up":c=m!==B?s+BigInt(1):s+B;break;case"half-up":default:c=m*BigInt(2)>=h?s+BigInt(1):s;break}return o(c.toString(),w)}function O(e,t){if(N(t))throw new Error("Division by zero is not allowed.");const n=f(e,t,0,"down"),i=d(n,t);return b(e,i)}function E(e,t){if(!Number.isInteger(t)||t<0)throw new Error("The exponent must be a non-negative integer.");let n=o(1),i=o(e);for(t=Math.abs(t);t>0;)t%2===1&&(n=d(n,i)),i=d(i,i),t=Math.floor(t/2);return n}const T=(e,t)=>{const[n,i]=v(e,t);return n.value>i.value?1:n.value<i.value?-1:0};function p(e){const t=e.value<BigInt(0)?-e.value:e.value;return o(t,e.scale)}function D(e,t=2,n=l){if(N(e))return o(0);if(e.valueOf()===BigInt(1))return o(1);if(e.value<B&&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 i=n===0?"1":"0."+"0".repeat(n-1)+"1",u=o(i),w=o(t),I=o(t-1),h=o(2);let s=f(S(e,f(e,h,n)),h,n),m;do{m=s;const V=S(d(I,s),f(e,E(s,t-1),n));s=f(V,w,n)}while(T(p(b(m,s)),u)===1);const c=s.toString(),M=c.indexOf("."),A=M!==-1?c.slice(0,M+n+1):c;return o(A)}const P=e=>new g(e.value,e.scale);r.Big=g,r.absBig=p,r.addBig=S,r.alignScale=v,r.cloneBig=P,r.compareBig=T,r.createBig=o,r.divBig=f,r.isNumericValue=a,r.modBig=O,r.mulBig=d,r.powBig=E,r.sqrtBig=D,r.subBig=b,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
1
+ (function(r,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(r=typeof globalThis<"u"?globalThis:r||self,s((r.big=r.big||{},r.big.esm={})))})(this,function(r){"use strict";var L=Object.defineProperty;var _=(r,s,g)=>s in r?L(r,s,{enumerable:!0,configurable:!0,writable:!0,value:g}):r[s]=g;var N=(r,s,g)=>(_(r,typeof s!="symbol"?s+"":s,g),g);const s=e=>typeof e=="bigint"||typeof e=="number"||typeof e=="string"&&!isNaN(Number(e)),g=/0+$/,M=e=>e.replace(g,""),h=BigInt(0);class B{constructor(n,t){N(this,"value");N(this,"scale");if(n instanceof B)this.value=n.value,this.scale=n.scale;else if(s(n)){let[i,o=""]=n.toString().split(".");t!==void 0&&(typeof t!="number"&&(t=Number(t)),t=Math.floor(t),o&&(o=""),i.length<t&&(i=i.padEnd(t,"0"))),this.value=BigInt(i+o),this.scale=o?o.length:t??0}else throw new TypeError("Invalid type provided to Big constructor.")}valueOf(){return this.value}toString(n=!0){let t=this.value.toString();const i=t.startsWith("-")?"-":"";i&&(t=t.substring(1));let o="";if(this.scale>h){const l=t.length>this.scale?t.length-Number(this.scale):0;o=t.slice(l).padStart(Number(this.scale),"0"),n&&(o=M(o)),o.length>0&&(o=`.${o}`),t=t.slice(0,l)}return`${i}${t||"0"}${o}`}toJSON(){return this.toString()}}function a(e,n){return e instanceof B?e:new B(e,n)}const O=BigInt(10);function I(e,n){const t=e.scale-n.scale;if(t===0)return[e,n];const i=O**BigInt(Math.abs(t)),o=t>0?e:a(e.value*i,n.scale),l=t<0?n:a(n.value*i,e.scale);return[o,l]}function S(e,n){const[t,i]=I(e,n),o=t.value+i.value;return a(o,t.scale)}function E(e,n){const[t,i]=I(e,n),o=t.value-i.value;return a(o,t.scale)}function w(e,n){const t=e.value*n.value,i=e.scale+n.scale;return a(t,i)}const b=e=>e.value===h;function d(e,n,t=20,i="half-up"){if(b(n))throw new Error("Division by zero is not allowed.");const o=Math.max(e.scale,n.scale),l=Math.max(0,t),v=e.value*BigInt(10)**BigInt(o+l-e.scale),u=n.value*BigInt(10)**BigInt(o-n.scale),c=v/u,m=v%u;let f;switch(i){case"down":f=c;break;case"up":f=m!==h?c+BigInt(1):c+h;break;case"half-up":default:f=m*BigInt(2)>=u?c+BigInt(1):c;break}return a(f.toString(),l)}function A(e,n){if(b(n))throw new Error("Division by zero is not allowed.");const t=d(e,n,0,"down"),i=w(t,n);return E(e,i)}function T(e,n){if(!Number.isInteger(n)||n<0)throw new Error("The exponent must be a non-negative integer.");let t=a(1),i=a(e);for(n=Math.abs(n);n>0;)n%2===1&&(t=w(t,i)),i=w(i,i),n=Math.floor(n/2);return t}const y=(e,n)=>{const[t,i]=I(e,n);return t.value>i.value?1:t.value<i.value?-1:0};function p(e){const n=e.value<h?-e.value:e.value;return a(n,e.scale)}function P(e,n=2,t=20){if(b(e))return a(0);if(e.valueOf()===BigInt(1))return a(1);if(e.value<h&&n%2===0)throw new Error("The root must be an odd integer when the number is negative.");if(!Number.isInteger(n)||n<2)throw new Error("The root must be an integer and greater than 1");if(t<0)throw new Error("The precision must be a non-negative integer.");const i=a(t===0?"1":"0."+"0".repeat(t-1)+"1"),o=a(n),l=a(n-1),v=a(2);let u=d(S(e,d(e,v,t)),v,t),c;do{c=u;const j=S(w(l,u),d(e,T(u,n-1),t));u=d(j,o,t)}while(y(p(E(c,u)),i)===1);const m=u.toString(),f=m.indexOf("."),R=f!==-1?m.slice(0,f+t+1):m;return a(R)}const D=e=>new B(e.value,e.scale);r.Big=B,r.absBig=p,r.addBig=S,r.alignScale=I,r.cloneBig=D,r.compareBig=y,r.createBig=a,r.divBig=d,r.isNumericValue=s,r.modBig=A,r.mulBig=w,r.powBig=T,r.sqrtBig=P,r.subBig=E,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
@@ -11,4 +11,4 @@ import type { Big } from "../big";
11
11
  * isZero(new Big(0)); // true
12
12
  * isZero(new Big(1)); // false
13
13
  */
14
- export declare function isZero(big: Big): boolean;
14
+ export declare const isZero: (big: Big) => boolean;
@@ -11,4 +11,4 @@
11
11
  * isNumericValue(1234567891012345678910n); // true
12
12
  * isNumericValue("123abc"); // false
13
13
  */
14
- export declare function isNumericValue(value: unknown): boolean;
14
+ export declare const isNumericValue: (value: unknown) => boolean;
@@ -0,0 +1 @@
1
+ export declare const trimZeros: (value: string) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "big.esm",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "A small, fast JavaScript library for arbitrary-precision decimal arithmetic.",
5
5
  "type": "module",
6
6
  "scripts": {