big.esm 1.2.1 → 1.3.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,17 @@
1
+ # [1.3.0](https://github.com/dschewchenko/big.esm/compare/v1.2.2...v1.3.0) (2023-06-24)
2
+
3
+
4
+ ### Features
5
+
6
+ * add min max operations ([db274ef](https://github.com/dschewchenko/big.esm/commit/db274ef6c0531b8bd6a2e14839c976d51935db48))
7
+
8
+ ## [1.2.2](https://github.com/dschewchenko/big.esm/compare/v1.2.1...v1.2.2) (2023-05-28)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * import name for types generation ([e41cbf5](https://github.com/dschewchenko/big.esm/commit/e41cbf573d55f46e5baf8ee661483dbcf8dcf289))
14
+
1
15
  ## [1.2.1](https://github.com/dschewchenko/big.esm/compare/v1.2.0...v1.2.1) (2023-05-28)
2
16
 
3
17
 
package/dist/big.esm.js CHANGED
@@ -1,37 +1,37 @@
1
- var O = Object.defineProperty;
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);
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
+ const m = BigInt(0), y = BigInt(1), p = BigInt(10);
6
+ function o(e, t) {
7
+ return e instanceof w ? e : new w(e, t);
8
8
  }
9
- function x(e, t = !1, n = !0) {
9
+ function j(e, t = !1, n = !0) {
10
10
  const r = e.toString();
11
11
  if (!Number.isFinite(Number(r)))
12
12
  throw new Error("Invalid number");
13
13
  if (Number(r) === 0)
14
- return n ? u(m) : { value: m, scale: 0 };
15
- let [s, a] = r.split("e");
14
+ return n ? o(m) : { value: m, scale: 0 };
15
+ let [s, i] = r.split("e");
16
16
  const g = s.startsWith("-") ? "-" : "";
17
17
  s = g ? s.slice(1) : s;
18
- let [o, l = ""] = s.split(".");
18
+ let [u, l = ""] = s.split(".");
19
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);
20
+ const a = Number.parseInt(i);
21
+ if (a > 0) {
22
+ const f = Math.min(a, l.length);
23
+ u += l.slice(0, f), l = l.slice(f), f < a && (u += "0".repeat(a - f));
24
+ } else if (a < 0) {
25
+ const f = Math.min(-a, u.length);
26
+ l = u.slice(-f) + l, u = u.slice(0, u.length - f), f < -a && (l = "0".repeat(-a - f) + l);
27
27
  }
28
- const h = BigInt(g + o + l), c = l.length;
29
- return n ? u(h, c) : { value: h, scale: c };
28
+ const h = BigInt(g + u + l), c = l.length;
29
+ return n ? o(h, c) : { value: h, scale: c };
30
30
  }
31
- function R(e) {
31
+ function P(e) {
32
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 p {
34
+ class w {
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 p {
43
43
  /**
44
44
  * The value of the Big instance.
45
45
  */
46
- v(this, "value");
46
+ I(this, "value");
47
47
  /**
48
48
  * The scale of the Big instance, representing the number of decimal places.
49
49
  */
50
- v(this, "scale");
51
- if (R(t))
50
+ I(this, "scale");
51
+ if (P(t))
52
52
  this.value = t.value, this.scale = t.scale;
53
- else if (A(t)) {
53
+ else if (M(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: a } = x(t, r, !1);
59
- this.value = s, this.scale = r ? n : a;
58
+ const { value: s, scale: i } = j(t, r, !1);
59
+ this.value = s, this.scale = r ? n : i;
60
60
  }
61
61
  } else
62
62
  throw new TypeError("Invalid type provided to Big constructor.");
@@ -81,8 +81,8 @@ class p {
81
81
  r && (n = n.substring(1));
82
82
  let s = "";
83
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);
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);
86
86
  }
87
87
  return `${r}${n || "0"}${s}`;
88
88
  }
@@ -95,111 +95,113 @@ class p {
95
95
  return this.toString();
96
96
  }
97
97
  }
98
- function E(e, t, n = !1) {
98
+ function S(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 = I ** BigInt(Math.abs(r));
102
+ const s = p ** 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 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
- }
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);
105
+ const i = r > 0 ? e : o(e.value * s, t.scale), g = r < 0 ? t : o(t.value * s, e.scale);
106
+ return [i, g];
111
107
  }
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);
108
+ function O(e, t, n = !1) {
109
+ const [r, s] = S(e, t), i = r.value + s.value;
110
+ return n ? (e.value = i, e.scale = r.scale, e) : o(i, r.scale);
115
111
  }
116
112
  function N(e, t, n = !1) {
113
+ const [r, s] = S(e, t, n), i = r.value - s.value;
114
+ return n ? (e.value = i, e) : o(i, r.scale);
115
+ }
116
+ function E(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) : u(r, s);
118
+ return n ? (e.value = r, e.scale = s, e) : o(r, s);
119
119
  }
120
- const S = (e) => e.value === m;
120
+ const d = (e) => e.value === m;
121
121
  function B(e, t, n = 20, r = "half-up", s = !1) {
122
- if (S(t))
122
+ if (d(t))
123
123
  throw new Error("Division by zero is not allowed.");
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;
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), a = u / l, h = u % l;
125
125
  let c;
126
126
  switch (r) {
127
127
  case "down":
128
- c = i;
128
+ c = a;
129
129
  break;
130
130
  case "up":
131
- c = h !== m ? i + d : i + m;
131
+ c = h !== m ? a + y : a + m;
132
132
  break;
133
133
  case "half-up":
134
134
  default:
135
- c = h * BigInt(2) >= l ? i + d : i;
135
+ c = h * BigInt(2) >= l ? a + y : a;
136
136
  break;
137
137
  }
138
- return s ? (e.value = c, e.scale = g, e) : u(c, g);
138
+ return s ? (e.value = c, e.scale = g, e) : o(c, g);
139
139
  }
140
- function F(e, t, n = !1) {
141
- if (S(t))
140
+ function V(e, t, n = !1) {
141
+ if (d(t))
142
142
  throw new Error("Division by zero is not allowed.");
143
143
  const r = B(e, t, 0, "down");
144
144
  if (n)
145
- return N(r, t, !0), w(e, r, !0);
146
- const s = N(r, t);
147
- return w(e, s);
145
+ return E(r, t, !0), N(e, r, !0);
146
+ const s = E(r, t);
147
+ return N(e, s);
148
148
  }
149
- function b(e, t = 2, n = !1) {
149
+ function $(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
152
  const r = e.value ** BigInt(t), s = e.scale * t;
153
- return n ? (e.value = r, e.scale = s, e) : u(r, s);
153
+ return n ? (e.value = r, e.scale = s, e) : o(r, s);
154
154
  }
155
- const j = (e, t) => {
156
- const [n, r] = E(e, t);
155
+ const T = (e, t) => {
156
+ const [n, r] = S(e, t);
157
157
  return n.value > r.value ? 1 : n.value < r.value ? -1 : 0;
158
158
  };
159
- function P(e, t = !1) {
159
+ function F(e, t = !1) {
160
160
  const n = e.value < m ? -e.value : e.value;
161
- return t ? (e.value = n, e) : u(n, e.scale);
161
+ return t ? (e.value = n, e) : o(n, e.scale);
162
162
  }
163
- function G(e, t = 2, n = 20, r = !1) {
164
- if (S(e))
165
- return u(0);
163
+ function Z(e, t = 2, n = 20, r = !1) {
164
+ if (d(e))
165
+ return o(0);
166
166
  if (e.valueOf() === BigInt(1))
167
- return u(1);
167
+ return o(1);
168
168
  if (e.value < m && t % 2 === 0)
169
169
  throw new Error("The root must be an odd integer when the number is negative.");
170
170
  if (!Number.isInteger(t) || t < 2)
171
171
  throw new Error("The root must be an integer and greater than 1");
172
172
  if (n < 0)
173
173
  throw new Error("The precision must be a non-negative integer.");
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;
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;
176
176
  do {
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);
177
+ a = l;
178
+ const D = O(E(g, l), B(e, $(l, t - 1), n));
179
+ l = B(D, i, n);
180
+ } while (T(F(N(a, l)), s) === 1);
181
181
  const h = l.toString();
182
182
  if (r)
183
183
  return e.value = l.value, e.scale = n, e;
184
184
  const c = h.indexOf("."), f = c !== -1 ? h.slice(0, c + n + 1) : h;
185
- return u(f);
185
+ return o(f);
186
186
  }
187
- const V = (e) => new p(e.value, e.scale);
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
188
  export {
189
- p as Big,
190
- P as absBig,
191
- T as addBig,
192
- E as alignScale,
193
- V as cloneBig,
194
- j as compareBig,
195
- u as createBig,
189
+ w as Big,
190
+ F as absBig,
191
+ O as addBig,
192
+ S as alignScale,
193
+ v as cloneBig,
194
+ T as compareBig,
195
+ o as createBig,
196
196
  B as divBig,
197
- x as fromString,
198
- R as isBigObject,
199
- A as isNumericValue,
200
- F as modBig,
201
- N as mulBig,
202
- b as powBig,
203
- G as sqrtBig,
204
- w as subBig
197
+ j as fromString,
198
+ P as isBigObject,
199
+ M as isNumericValue,
200
+ q as maxBig,
201
+ k as minBig,
202
+ V as modBig,
203
+ E as mulBig,
204
+ $ as powBig,
205
+ Z as sqrtBig,
206
+ N as subBig
205
207
  };
@@ -1 +1 @@
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"})});
1
+ (function(r,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(r=typeof globalThis<"u"?globalThis:r||self,o((r.big=r.big||{},r.big.esm={})))})(this,function(r){"use strict";var Z=Object.defineProperty;var k=(r,o,d)=>o in r?Z(r,o,{enumerable:!0,configurable:!0,writable:!0,value:d}):r[o]=d;var D=(r,o,d)=>(k(r,typeof o!="symbol"?o+"":o,d),d);const o=e=>typeof e=="bigint"||typeof e=="number"||typeof e=="string"&&!isNaN(Number(e)),d=/0+$/,P=e=>e.replace(d,""),v=BigInt(0),M=BigInt(1),T=BigInt(10);function u(e,t){return e instanceof N?e:new N(e,t)}function A(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[s,a]=i.split("e");const h=s.startsWith("-")?"-":"";s=h?s.slice(1):s;let[f,l=""]=s.split(".");l=t?"":l;const c=Number.parseInt(a);if(c>0){const B=Math.min(c,l.length);f+=l.slice(0,B),l=l.slice(B),B<c&&(f+="0".repeat(c-B))}else if(c<0){const B=Math.min(-c,f.length);l=f.slice(-B)+l,f=f.slice(0,f.length-B),B<-c&&(l="0".repeat(-c-B)+l)}const m=BigInt(h+f+l),g=l.length;return n?u(m,g):{value:m,scale:g}}function _(e){return typeof e!="object"||e===null?!1:"value"in e&&"scale"in e&&typeof e.value=="bigint"&&typeof e.scale=="number"}class N{constructor(t,n){D(this,"value");D(this,"scale");if(_(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:s,scale:a}=A(t,i,!1);this.value=s,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 s="";if(this.scale>v){const a=n.length>this.scale?n.length-Number(this.scale):0;s=n.slice(a).padStart(Number(this.scale),"0"),t&&(s=P(s)),s.length>0&&(s=`.${s}`),n=n.slice(0,a)}return`${i}${n||"0"}${s}`}toJSON(){return this.toString()}}function S(e,t,n=!1){const i=e.scale-t.scale;if(i===0)return[e,t];const s=T**BigInt(Math.abs(i));if(n)return i>0?(t.value*=s,t.scale=e.scale):(e.value*=s,e.scale=t.scale),[e,t];const a=i>0?e:u(e.value*s,t.scale),h=i<0?t:u(t.value*s,e.scale);return[a,h]}function O(e,t,n=!1){const[i,s]=S(e,t),a=i.value+s.value;return n?(e.value=a,e.scale=i.scale,e):u(a,i.scale)}function E(e,t,n=!1){const[i,s]=S(e,t,n),a=i.value-s.value;return n?(e.value=a,e):u(a,i.scale)}function p(e,t,n=!1){const i=e.value*t.value,s=e.scale+t.scale;return n?(e.value=i,e.scale=s,e):u(i,s)}const j=e=>e.value===v;function I(e,t,n=20,i="half-up",s=!1){if(j(t))throw new Error("Division by zero is not allowed.");const a=Math.max(e.scale,t.scale),h=Math.max(0,n),f=e.value*T**BigInt(a+h-e.scale),l=t.value*T**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+M:c+v;break;case"half-up":default:g=m*BigInt(2)>=l?c+M:c;break}return s?(e.value=g,e.scale=h,e):u(g,h)}function V(e,t,n=!1){if(j(t))throw new Error("Division by zero is not allowed.");const i=I(e,t,0,"down");if(n)return p(i,t,!0),E(e,i,!0);const s=p(i,t);return E(e,s)}function b(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),s=e.scale*t;return n?(e.value=i,e.scale=s,e):u(i,s)}const y=(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):u(n,e.scale)}function $(e,t=2,n=20,i=!1){if(j(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 s=u(n===0?"1":"0."+"0".repeat(n-1)+"1"),a=u(t),h=u(t-1),f=u(2);let l=I(O(e,I(e,f,n)),f,n),c;do{c=l;const G=O(p(h,l),I(e,b(l,t-1),n));l=I(G,a,n)}while(y(R(E(c,l)),s)===1);const m=l.toString();if(i)return e.value=l.value,e.scale=n,e;const g=m.indexOf("."),B=g!==-1?m.slice(0,g+n+1):m;return u(B)}const w=e=>new N(e.value,e.scale),q=(e,t,n=!1)=>y(e,t)>0?n?t:w(t):n?e:w(e),F=(e,t,n=!1)=>y(e,t)>=0?n?e:w(e):n?t:w(t);r.Big=N,r.absBig=R,r.addBig=O,r.alignScale=S,r.cloneBig=w,r.compareBig=y,r.createBig=u,r.divBig=I,r.fromString=A,r.isBigObject=_,r.isNumericValue=o,r.maxBig=F,r.minBig=q,r.modBig=V,r.mulBig=p,r.powBig=b,r.sqrtBig=$,r.subBig=E,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
package/dist/index.d.ts CHANGED
@@ -9,9 +9,11 @@ export { powBig } from "./operations/pow";
9
9
  export { sqrtBig } from "./operations/sqrt";
10
10
  export { absBig } from "./operations/abs";
11
11
  export { compareBig } from "./operations/compare";
12
+ export { minBig } from "./operations/min";
13
+ export { maxBig } from "./operations/max";
12
14
  export { isBigObject } from "./utils/is-big-object";
13
15
  export { isNumericValue } from "./utils/numeric";
14
16
  export { alignScale } from "./utils/align-scale";
15
- export { createBig } from "./utils/create.ts";
16
- export { cloneBig } from "./utils/clone.ts";
17
- export { fromString } from "./utils/from-string.ts";
17
+ export { createBig } from "./utils/create";
18
+ export { cloneBig } from "./utils/clone";
19
+ export { fromString } from "./utils/from-string";
@@ -1,5 +1,5 @@
1
1
  import type { Big } from "../big";
2
- import type { CompareResult } from "../types.ts";
2
+ import type { CompareResult } from "../types";
3
3
  /**
4
4
  * Compares two Big numbers and returns a CompareResult indicating the relation between them.
5
5
  *
@@ -0,0 +1,19 @@
1
+ import type { Big } from "../big";
2
+ /**
3
+ * Returns the maximum of two Big numbers.
4
+ *
5
+ * @param {Big} a - The first Big number.
6
+ * @param {Big} b - The second Big number.
7
+ * @param {boolean} [mutable=false] - Whether to return same Big instance. Defaults to false.
8
+ *
9
+ * @returns {Big} - The maximum of the two Big numbers. If the two Big numbers are equal, the first Big number is returned.
10
+ *
11
+ * @category Operations
12
+ *
13
+ * @example
14
+ * maxBig(new Big(1), new Big(2)); // new Big instance with value 2 (second Big number)
15
+ * maxBig(new Big(2), new Big(1)); // new Big instance with value 2 (first Big number)
16
+ * maxBig(new Big(1), new Big(1)); // new Big instance with value 1 (first Big number)
17
+ * maxBig(new Big(1), new Big(1), true); // first Big number with value 1 and same instance
18
+ */
19
+ export declare const maxBig: (a: Big, b: Big, mutable?: boolean) => Big;
@@ -0,0 +1,19 @@
1
+ import type { Big } from "../big";
2
+ /**
3
+ * Returns the minimum of two Big numbers.
4
+ *
5
+ * @param {Big} a - The first Big number.
6
+ * @param {Big} b - The second Big number.
7
+ * @param {boolean} [mutable=false] - Whether to return same Big instance. Defaults to false.
8
+ *
9
+ * @returns {Big} - The minimum of the two Big numbers. If the two Big numbers are equal, the first Big number is returned.
10
+ *
11
+ * @category Operations
12
+ *
13
+ * @example
14
+ * minBig(new Big(1), new Big(2)); // new Big instance with value 1 (first Big number)
15
+ * minBig(new Big(2), new Big(1)); // new Big instance with value 1 (second Big number)
16
+ * minBig(new Big(1), new Big(1)); // new Big instance with value 1 (first Big number)
17
+ * minBig(new Big(1), new Big(1), true); // first Big number with value 1 and same instance
18
+ */
19
+ export declare const minBig: (a: Big, b: Big, mutable?: boolean) => Big;
@@ -1,4 +1,4 @@
1
- import { Big } from "../big.ts";
1
+ import { Big } from "../big";
2
2
  /**
3
3
  * Clone a Big instance
4
4
  * @param {Big} big - The Big instance to clone.
@@ -1,5 +1,5 @@
1
- import { Big } from "../big.ts";
2
- import type { BigObject, PossibleNumber } from "../types.ts";
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 { Big } from "../big.ts";
2
- import { BigObject } from "../types.ts";
1
+ import { Big } from "../big";
2
+ import { BigObject } from "../types";
3
3
  /**
4
4
  * Convert a number or string to normal string number. Supports scientific notation.
5
5
  *
@@ -1,5 +1,5 @@
1
- import type { BigObject } from "../types.ts";
2
- import type { Big } from "../big.ts";
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.1",
3
+ "version": "1.3.0",
4
4
  "description": "A small, fast JavaScript library for arbitrary-precision decimal arithmetic.",
5
5
  "type": "module",
6
6
  "scripts": {