@agrozyme/numeric 1.0.31 → 1.0.32
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/lib/config.d.ts +3 -0
- package/lib/constants.d.ts +9 -0
- package/lib/format.d.ts +18 -0
- package/lib/helper.d.ts +11 -0
- package/lib/index.d.ts +14 -0
- package/lib/index.js +592 -0
- package/lib/index.mjs +474 -0
- package/lib/numeric.d.ts +136 -0
- package/package.json +8 -8
package/lib/config.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Numeric } from './numeric';
|
|
2
|
+
export declare const NegativeOne: Numeric;
|
|
3
|
+
export declare const Zero: Numeric;
|
|
4
|
+
export declare const One: Numeric;
|
|
5
|
+
export declare const Two: Numeric;
|
|
6
|
+
export declare const WeiPerEther: Numeric;
|
|
7
|
+
export declare const MaxUint256: Numeric;
|
|
8
|
+
export declare const MaxInt256: Numeric;
|
|
9
|
+
export declare const MinInt256: Numeric;
|
package/lib/format.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { NumericValue } from './numeric';
|
|
2
|
+
export interface IFormatNumberOptions {
|
|
3
|
+
negativeType?: 'right' | 'left' | 'brackets' | 'none';
|
|
4
|
+
negativeLeftSymbol?: string;
|
|
5
|
+
negativeRightSymbol?: string;
|
|
6
|
+
negativeLeftOut?: boolean;
|
|
7
|
+
negativeRightOut?: boolean;
|
|
8
|
+
prefix?: string;
|
|
9
|
+
suffix?: string;
|
|
10
|
+
integerSeparator?: string;
|
|
11
|
+
decimalsSeparator?: string;
|
|
12
|
+
decimal?: string;
|
|
13
|
+
padLeft?: number;
|
|
14
|
+
padRight?: number;
|
|
15
|
+
round?: number;
|
|
16
|
+
truncate?: number;
|
|
17
|
+
}
|
|
18
|
+
export declare const formatValue: (value: NumericValue, options?: IFormatNumberOptions) => string;
|
package/lib/helper.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Numeric, NumericValue } from './numeric';
|
|
2
|
+
export interface RangeOptions {
|
|
3
|
+
includeMinimum?: boolean;
|
|
4
|
+
includeMaximum?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare const isRange: (value: NumericValue, minimum: NumericValue, maximum: NumericValue, options?: RangeOptions) => boolean;
|
|
7
|
+
export declare const tryParse: (value: NumericValue) => false | Numeric;
|
|
8
|
+
export declare const isInteger: (value: NumericValue) => boolean;
|
|
9
|
+
export declare const isUnsignedIntegerBits: (bits: bigint, value: NumericValue) => boolean;
|
|
10
|
+
export declare const isSignedIntegerBits: (bits: bigint, value: NumericValue) => boolean;
|
|
11
|
+
export declare const createArrayCompareFunction: (ascending?: boolean) => (left: NumericValue, right: NumericValue) => number;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { Numeric, toBigInt, toBigInteger, toBigNumber, toBN, toIntegerString, toNumeric, toNumerics } from './numeric';
|
|
2
|
+
export type { NumericValue } from './numeric';
|
|
3
|
+
export { formatValue } from './format';
|
|
4
|
+
export type { IFormatNumberOptions } from './format';
|
|
5
|
+
export { getNumericConfig, setupNumericConfig } from './config';
|
|
6
|
+
export { MaxInt256, MaxUint256, MinInt256, NegativeOne, One, Two, WeiPerEther, Zero } from './constants';
|
|
7
|
+
export { createArrayCompareFunction, isInteger, isRange, isSignedIntegerBits, isUnsignedIntegerBits, tryParse, } from './helper';
|
|
8
|
+
export type { RangeOptions } from './helper';
|
|
9
|
+
/**
|
|
10
|
+
* - must use `@types/node@16` for Symbol typing
|
|
11
|
+
* - must put `@types/bn.js` in dependencies section of package.json
|
|
12
|
+
* - must set `rootDir` to `src` that in compilerOptions section of tscnfig.json (for bundler tools)
|
|
13
|
+
* - must import namespaces: `big-integer`, `bn.js`, `decimal.js`
|
|
14
|
+
* */
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,592 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
isRange: ()=>isRange,
|
|
37
|
+
isUnsignedIntegerBits: ()=>isUnsignedIntegerBits,
|
|
38
|
+
WeiPerEther: ()=>WeiPerEther,
|
|
39
|
+
MinInt256: ()=>MinInt256,
|
|
40
|
+
isSignedIntegerBits: ()=>isSignedIntegerBits,
|
|
41
|
+
toBN: ()=>toBN,
|
|
42
|
+
toIntegerString: ()=>toIntegerString,
|
|
43
|
+
formatValue: ()=>formatValue,
|
|
44
|
+
Zero: ()=>Zero,
|
|
45
|
+
createArrayCompareFunction: ()=>createArrayCompareFunction,
|
|
46
|
+
toBigInteger: ()=>toBigInteger,
|
|
47
|
+
MaxInt256: ()=>MaxInt256,
|
|
48
|
+
MaxUint256: ()=>MaxUint256,
|
|
49
|
+
toNumerics: ()=>toNumerics,
|
|
50
|
+
toBigNumber: ()=>toBigNumber,
|
|
51
|
+
setupNumericConfig: ()=>setupNumericConfig,
|
|
52
|
+
toBigInt: ()=>toBigInt,
|
|
53
|
+
Numeric: ()=>Numeric,
|
|
54
|
+
Two: ()=>Two,
|
|
55
|
+
isInteger: ()=>isInteger,
|
|
56
|
+
toNumeric: ()=>toNumeric,
|
|
57
|
+
One: ()=>One,
|
|
58
|
+
NegativeOne: ()=>NegativeOne,
|
|
59
|
+
getNumericConfig: ()=>getNumericConfig,
|
|
60
|
+
tryParse: ()=>tryParse
|
|
61
|
+
});
|
|
62
|
+
const bignumber_namespaceObject = require("@ethersproject/bignumber");
|
|
63
|
+
const bytes_namespaceObject = require("@ethersproject/bytes");
|
|
64
|
+
const external_big_integer_namespaceObject = require("big-integer");
|
|
65
|
+
var external_big_integer_default = /*#__PURE__*/ __webpack_require__.n(external_big_integer_namespaceObject);
|
|
66
|
+
const external_bn_js_namespaceObject = require("bn.js");
|
|
67
|
+
var external_bn_js_default = /*#__PURE__*/ __webpack_require__.n(external_bn_js_namespaceObject);
|
|
68
|
+
const external_browser_or_node_namespaceObject = require("browser-or-node");
|
|
69
|
+
const external_decimal_js_namespaceObject = require("decimal.js");
|
|
70
|
+
const toNumeric = (value)=>new Numeric(value);
|
|
71
|
+
const toNumerics = (values)=>values.map(toNumeric);
|
|
72
|
+
const toIntegerString = (value)=>toNumeric(value).toFixed(0);
|
|
73
|
+
const toBigInt = (value)=>BigInt(toIntegerString(value));
|
|
74
|
+
const toBN = (value)=>new (external_bn_js_default())(toIntegerString(value));
|
|
75
|
+
const toBigInteger = (value)=>external_big_integer_default()(toIntegerString(value));
|
|
76
|
+
const toBigNumber = (value)=>bignumber_namespaceObject.BigNumber.from(toIntegerString(value));
|
|
77
|
+
class Numeric extends external_decimal_js_namespaceObject.Decimal {
|
|
78
|
+
constructor(value){
|
|
79
|
+
if (value instanceof external_decimal_js_namespaceObject.Decimal) super(value);
|
|
80
|
+
else switch(typeof value){
|
|
81
|
+
case 'string':
|
|
82
|
+
case 'number':
|
|
83
|
+
super(value);
|
|
84
|
+
break;
|
|
85
|
+
case 'bigint':
|
|
86
|
+
super(value.toString());
|
|
87
|
+
break;
|
|
88
|
+
default:
|
|
89
|
+
if (external_big_integer_default().isInstance(value) || bignumber_namespaceObject.BigNumber.isBigNumber(value) || external_bn_js_default().isBN(value)) super(value.toString());
|
|
90
|
+
else if ((0, bytes_namespaceObject.isBytesLike)(value)) super((0, bytes_namespaceObject.hexlify)(value));
|
|
91
|
+
else super(value);
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
static abs(value) {
|
|
96
|
+
return new Numeric(value).abs();
|
|
97
|
+
}
|
|
98
|
+
static acos(value) {
|
|
99
|
+
return new Numeric(value).acos();
|
|
100
|
+
}
|
|
101
|
+
static acosh(value) {
|
|
102
|
+
return new Numeric(value).acosh();
|
|
103
|
+
}
|
|
104
|
+
static add(x, y) {
|
|
105
|
+
return new Numeric(x).add(y);
|
|
106
|
+
}
|
|
107
|
+
static asin(value) {
|
|
108
|
+
return new Numeric(value).asin();
|
|
109
|
+
}
|
|
110
|
+
static asinh(value) {
|
|
111
|
+
return new Numeric(value).asinh();
|
|
112
|
+
}
|
|
113
|
+
static atan(value) {
|
|
114
|
+
return new Numeric(value).atan();
|
|
115
|
+
}
|
|
116
|
+
static atanh(value) {
|
|
117
|
+
return new Numeric(value).atanh();
|
|
118
|
+
}
|
|
119
|
+
static atan2(x, y) {
|
|
120
|
+
return new Numeric(external_decimal_js_namespaceObject.Decimal.atan2(new Numeric(x), new Numeric(y)));
|
|
121
|
+
}
|
|
122
|
+
static cbrt(value) {
|
|
123
|
+
return new Numeric(value).cbrt();
|
|
124
|
+
}
|
|
125
|
+
static ceil(value) {
|
|
126
|
+
return new Numeric(value).ceil();
|
|
127
|
+
}
|
|
128
|
+
static clamp(value, min, max) {
|
|
129
|
+
return new Numeric(external_decimal_js_namespaceObject.Decimal.clamp(new Numeric(value), new Numeric(min), new Numeric(max)));
|
|
130
|
+
}
|
|
131
|
+
static cos(value) {
|
|
132
|
+
return new Numeric(value).cos();
|
|
133
|
+
}
|
|
134
|
+
static cosh(value) {
|
|
135
|
+
return new Numeric(value).cosh();
|
|
136
|
+
}
|
|
137
|
+
static div(x, y) {
|
|
138
|
+
return new Numeric(x).div(y);
|
|
139
|
+
}
|
|
140
|
+
static exp(value) {
|
|
141
|
+
return new Numeric(value).exp();
|
|
142
|
+
}
|
|
143
|
+
static floor(value) {
|
|
144
|
+
return new Numeric(value).floor();
|
|
145
|
+
}
|
|
146
|
+
static hypot(...values) {
|
|
147
|
+
return new Numeric(external_decimal_js_namespaceObject.Decimal.hypot(...toNumerics(values)));
|
|
148
|
+
}
|
|
149
|
+
static ln(value) {
|
|
150
|
+
return new Numeric(value).ln();
|
|
151
|
+
}
|
|
152
|
+
static log(value, base) {
|
|
153
|
+
return new Numeric(value).log(base);
|
|
154
|
+
}
|
|
155
|
+
static log2(value) {
|
|
156
|
+
return new Numeric(value).log(2);
|
|
157
|
+
}
|
|
158
|
+
static log10(value) {
|
|
159
|
+
return new Numeric(value).log(10);
|
|
160
|
+
}
|
|
161
|
+
static max(...values) {
|
|
162
|
+
return new Numeric(external_decimal_js_namespaceObject.Decimal.max(...toNumerics(values)));
|
|
163
|
+
}
|
|
164
|
+
static min(...values) {
|
|
165
|
+
return new Numeric(external_decimal_js_namespaceObject.Decimal.min(...toNumerics(values)));
|
|
166
|
+
}
|
|
167
|
+
static mod(x, y) {
|
|
168
|
+
return new Numeric(x).mod(y);
|
|
169
|
+
}
|
|
170
|
+
static mul(x, y) {
|
|
171
|
+
return new Numeric(x).mul(y);
|
|
172
|
+
}
|
|
173
|
+
static pow(base, exponent) {
|
|
174
|
+
return new Numeric(base).pow(exponent);
|
|
175
|
+
}
|
|
176
|
+
static random(significantDigits) {
|
|
177
|
+
return new Numeric(external_decimal_js_namespaceObject.Decimal.random(significantDigits));
|
|
178
|
+
}
|
|
179
|
+
static round(value) {
|
|
180
|
+
return new Numeric(value).round();
|
|
181
|
+
}
|
|
182
|
+
static set(object) {
|
|
183
|
+
return external_decimal_js_namespaceObject.Decimal.set(object);
|
|
184
|
+
}
|
|
185
|
+
static sign(value) {
|
|
186
|
+
return external_decimal_js_namespaceObject.Decimal.sign(new Numeric(value));
|
|
187
|
+
}
|
|
188
|
+
static sin(value) {
|
|
189
|
+
return new Numeric(value).sin();
|
|
190
|
+
}
|
|
191
|
+
static sinh(value) {
|
|
192
|
+
return new Numeric(value).sinh();
|
|
193
|
+
}
|
|
194
|
+
static sqrt(value) {
|
|
195
|
+
return new Numeric(value).sqrt();
|
|
196
|
+
}
|
|
197
|
+
static sub(x, y) {
|
|
198
|
+
return new Numeric(x).sub(y);
|
|
199
|
+
}
|
|
200
|
+
static sum(...values) {
|
|
201
|
+
return new Numeric(external_decimal_js_namespaceObject.Decimal.sum(...toNumerics(values)));
|
|
202
|
+
}
|
|
203
|
+
static tan(value) {
|
|
204
|
+
return new Numeric(value).tan();
|
|
205
|
+
}
|
|
206
|
+
static tanh(value) {
|
|
207
|
+
return new Numeric(value).tanh();
|
|
208
|
+
}
|
|
209
|
+
static trunc(value) {
|
|
210
|
+
return new Numeric(value).trunc();
|
|
211
|
+
}
|
|
212
|
+
absoluteValue() {
|
|
213
|
+
return new Numeric(super.absoluteValue());
|
|
214
|
+
}
|
|
215
|
+
abs() {
|
|
216
|
+
return new Numeric(super.abs());
|
|
217
|
+
}
|
|
218
|
+
ceil() {
|
|
219
|
+
return new Numeric(super.ceil());
|
|
220
|
+
}
|
|
221
|
+
clampedTo(min, max) {
|
|
222
|
+
return new Numeric(super.clampedTo(new Numeric(min), new Numeric(max)));
|
|
223
|
+
}
|
|
224
|
+
clamp(min, max) {
|
|
225
|
+
return new Numeric(super.clamp(new Numeric(min), new Numeric(max)));
|
|
226
|
+
}
|
|
227
|
+
comparedTo(value) {
|
|
228
|
+
return super.comparedTo(new Numeric(value));
|
|
229
|
+
}
|
|
230
|
+
cmp(value) {
|
|
231
|
+
return super.cmp(new Numeric(value));
|
|
232
|
+
}
|
|
233
|
+
cosine() {
|
|
234
|
+
return new Numeric(super.cosine());
|
|
235
|
+
}
|
|
236
|
+
cos() {
|
|
237
|
+
return new Numeric(super.cos());
|
|
238
|
+
}
|
|
239
|
+
cubeRoot() {
|
|
240
|
+
return new Numeric(super.cubeRoot());
|
|
241
|
+
}
|
|
242
|
+
cbrt() {
|
|
243
|
+
return new Numeric(super.cbrt());
|
|
244
|
+
}
|
|
245
|
+
dividedBy(value) {
|
|
246
|
+
return new Numeric(super.dividedBy(new Numeric(value)));
|
|
247
|
+
}
|
|
248
|
+
div(value) {
|
|
249
|
+
return new Numeric(super.div(new Numeric(value)));
|
|
250
|
+
}
|
|
251
|
+
dividedToIntegerBy(value) {
|
|
252
|
+
return new Numeric(super.dividedToIntegerBy(new Numeric(value)));
|
|
253
|
+
}
|
|
254
|
+
divToInt(value) {
|
|
255
|
+
return new Numeric(super.divToInt(new Numeric(value)));
|
|
256
|
+
}
|
|
257
|
+
equals(value) {
|
|
258
|
+
return super.equals(new Numeric(value));
|
|
259
|
+
}
|
|
260
|
+
eq(value) {
|
|
261
|
+
return super.eq(new Numeric(value));
|
|
262
|
+
}
|
|
263
|
+
floor() {
|
|
264
|
+
return new Numeric(super.floor());
|
|
265
|
+
}
|
|
266
|
+
greaterThan(value) {
|
|
267
|
+
return super.greaterThan(new Numeric(value));
|
|
268
|
+
}
|
|
269
|
+
gt(value) {
|
|
270
|
+
return super.gt(new Numeric(value));
|
|
271
|
+
}
|
|
272
|
+
greaterThanOrEqualTo(value) {
|
|
273
|
+
return super.greaterThanOrEqualTo(new Numeric(value));
|
|
274
|
+
}
|
|
275
|
+
gte(value) {
|
|
276
|
+
return super.gte(new Numeric(value));
|
|
277
|
+
}
|
|
278
|
+
hyperbolicCosine() {
|
|
279
|
+
return new Numeric(super.hyperbolicCosine());
|
|
280
|
+
}
|
|
281
|
+
cosh() {
|
|
282
|
+
return new Numeric(super.cosh());
|
|
283
|
+
}
|
|
284
|
+
hyperbolicSine() {
|
|
285
|
+
return new Numeric(super.hyperbolicSine());
|
|
286
|
+
}
|
|
287
|
+
sinh() {
|
|
288
|
+
return new Numeric(super.sinh());
|
|
289
|
+
}
|
|
290
|
+
hyperbolicTangent() {
|
|
291
|
+
return new Numeric(super.hyperbolicTangent());
|
|
292
|
+
}
|
|
293
|
+
tanh() {
|
|
294
|
+
return new Numeric(super.tanh());
|
|
295
|
+
}
|
|
296
|
+
inverseCosine() {
|
|
297
|
+
return new Numeric(super.inverseCosine());
|
|
298
|
+
}
|
|
299
|
+
acos() {
|
|
300
|
+
return new Numeric(super.acos());
|
|
301
|
+
}
|
|
302
|
+
inverseHyperbolicCosine() {
|
|
303
|
+
return new Numeric(super.inverseHyperbolicCosine());
|
|
304
|
+
}
|
|
305
|
+
acosh() {
|
|
306
|
+
return new Numeric(super.acosh());
|
|
307
|
+
}
|
|
308
|
+
inverseHyperbolicSine() {
|
|
309
|
+
return new Numeric(super.inverseHyperbolicSine());
|
|
310
|
+
}
|
|
311
|
+
asinh() {
|
|
312
|
+
return new Numeric(super.asinh());
|
|
313
|
+
}
|
|
314
|
+
inverseHyperbolicTangent() {
|
|
315
|
+
return new Numeric(super.inverseHyperbolicTangent());
|
|
316
|
+
}
|
|
317
|
+
atanh() {
|
|
318
|
+
return new Numeric(super.atanh());
|
|
319
|
+
}
|
|
320
|
+
inverseSine() {
|
|
321
|
+
return new Numeric(super.inverseSine());
|
|
322
|
+
}
|
|
323
|
+
asin() {
|
|
324
|
+
return new Numeric(super.asin());
|
|
325
|
+
}
|
|
326
|
+
inverseTangent() {
|
|
327
|
+
return new Numeric(super.inverseTangent());
|
|
328
|
+
}
|
|
329
|
+
atan() {
|
|
330
|
+
return new Numeric(super.atan());
|
|
331
|
+
}
|
|
332
|
+
lessThan(value) {
|
|
333
|
+
return super.lessThan(new Numeric(value));
|
|
334
|
+
}
|
|
335
|
+
lt(value) {
|
|
336
|
+
return super.lt(new Numeric(value));
|
|
337
|
+
}
|
|
338
|
+
lessThanOrEqualTo(value) {
|
|
339
|
+
return super.lessThanOrEqualTo(new Numeric(value));
|
|
340
|
+
}
|
|
341
|
+
lte(value) {
|
|
342
|
+
return super.lte(new Numeric(value));
|
|
343
|
+
}
|
|
344
|
+
logarithm(value) {
|
|
345
|
+
return new Numeric(super.logarithm(void 0 === value ? void 0 : new Numeric(value)));
|
|
346
|
+
}
|
|
347
|
+
log(value) {
|
|
348
|
+
return new Numeric(super.log(void 0 === value ? void 0 : new Numeric(value)));
|
|
349
|
+
}
|
|
350
|
+
minus(value) {
|
|
351
|
+
return new Numeric(super.minus(new Numeric(value)));
|
|
352
|
+
}
|
|
353
|
+
sub(value) {
|
|
354
|
+
return new Numeric(super.sub(new Numeric(value)));
|
|
355
|
+
}
|
|
356
|
+
modulo(value) {
|
|
357
|
+
return new Numeric(super.modulo(new Numeric(value)));
|
|
358
|
+
}
|
|
359
|
+
mod(value) {
|
|
360
|
+
return new Numeric(super.mod(new Numeric(value)));
|
|
361
|
+
}
|
|
362
|
+
naturalExponential() {
|
|
363
|
+
return new Numeric(super.naturalExponential());
|
|
364
|
+
}
|
|
365
|
+
exp() {
|
|
366
|
+
return new Numeric(super.exp());
|
|
367
|
+
}
|
|
368
|
+
naturalLogarithm() {
|
|
369
|
+
return new Numeric(super.naturalLogarithm());
|
|
370
|
+
}
|
|
371
|
+
ln() {
|
|
372
|
+
return new Numeric(super.ln());
|
|
373
|
+
}
|
|
374
|
+
negated() {
|
|
375
|
+
return new Numeric(super.negated());
|
|
376
|
+
}
|
|
377
|
+
neg() {
|
|
378
|
+
return new Numeric(super.neg());
|
|
379
|
+
}
|
|
380
|
+
plus(value) {
|
|
381
|
+
return new Numeric(super.plus(new Numeric(value)));
|
|
382
|
+
}
|
|
383
|
+
add(value) {
|
|
384
|
+
return new Numeric(super.add(new Numeric(value)));
|
|
385
|
+
}
|
|
386
|
+
round() {
|
|
387
|
+
return new Numeric(super.round());
|
|
388
|
+
}
|
|
389
|
+
sine() {
|
|
390
|
+
return new Numeric(super.sine());
|
|
391
|
+
}
|
|
392
|
+
sin() {
|
|
393
|
+
return new Numeric(super.sin());
|
|
394
|
+
}
|
|
395
|
+
squareRoot() {
|
|
396
|
+
return new Numeric(super.squareRoot());
|
|
397
|
+
}
|
|
398
|
+
sqrt() {
|
|
399
|
+
return new Numeric(super.sqrt());
|
|
400
|
+
}
|
|
401
|
+
tangent() {
|
|
402
|
+
return new Numeric(super.tangent());
|
|
403
|
+
}
|
|
404
|
+
tan() {
|
|
405
|
+
return new Numeric(super.tan());
|
|
406
|
+
}
|
|
407
|
+
times(value) {
|
|
408
|
+
return new Numeric(super.times(new Numeric(value)));
|
|
409
|
+
}
|
|
410
|
+
mul(value) {
|
|
411
|
+
return new Numeric(super.mul(new Numeric(value)));
|
|
412
|
+
}
|
|
413
|
+
toDecimalPlaces(decimalPlaces, rounding) {
|
|
414
|
+
return new Numeric(void 0 !== rounding && void 0 !== decimalPlaces ? super.toDecimalPlaces(decimalPlaces, rounding) : super.toDecimalPlaces(decimalPlaces));
|
|
415
|
+
}
|
|
416
|
+
toDP(decimalPlaces, rounding) {
|
|
417
|
+
return new Numeric(void 0 !== rounding && void 0 !== decimalPlaces ? super.toDP(decimalPlaces, rounding) : super.toDP(decimalPlaces));
|
|
418
|
+
}
|
|
419
|
+
toFraction(maxDenominator) {
|
|
420
|
+
return toNumerics(super.toFraction(void 0 === maxDenominator ? void 0 : new Numeric(maxDenominator)));
|
|
421
|
+
}
|
|
422
|
+
toNearest(value, rounding) {
|
|
423
|
+
return new Numeric(super.toNearest(new Numeric(value), rounding));
|
|
424
|
+
}
|
|
425
|
+
toPower(value) {
|
|
426
|
+
return new Numeric(super.toPower(new Numeric(value)));
|
|
427
|
+
}
|
|
428
|
+
pow(value) {
|
|
429
|
+
return new Numeric(super.pow(new Numeric(value)));
|
|
430
|
+
}
|
|
431
|
+
toSignificantDigits(decimalPlaces, rounding) {
|
|
432
|
+
return new Numeric(void 0 !== rounding && void 0 !== decimalPlaces ? super.toSignificantDigits(decimalPlaces, rounding) : super.toSignificantDigits(decimalPlaces));
|
|
433
|
+
}
|
|
434
|
+
toSD(decimalPlaces, rounding) {
|
|
435
|
+
return new Numeric(void 0 !== rounding && void 0 !== decimalPlaces ? super.toSD(decimalPlaces, rounding) : super.toSD(decimalPlaces));
|
|
436
|
+
}
|
|
437
|
+
truncated() {
|
|
438
|
+
return new Numeric(super.truncated());
|
|
439
|
+
}
|
|
440
|
+
trunc() {
|
|
441
|
+
return new Numeric(super.trunc());
|
|
442
|
+
}
|
|
443
|
+
inspect(depth, options) {
|
|
444
|
+
const value = this.toFixed();
|
|
445
|
+
return external_browser_or_node_namespaceObject.isNode ? options.stylize(value, 'bigint') : value;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
const external_format_number_namespaceObject = require("format-number");
|
|
449
|
+
var external_format_number_default = /*#__PURE__*/ __webpack_require__.n(external_format_number_namespaceObject);
|
|
450
|
+
const formatValue = (value, options)=>{
|
|
451
|
+
const format = external_format_number_default()(options);
|
|
452
|
+
const text = new Numeric(value).toFixed();
|
|
453
|
+
return format(text);
|
|
454
|
+
};
|
|
455
|
+
const getNumericConfig = ()=>{
|
|
456
|
+
const { precision, rounding, minE, maxE, toExpNeg, toExpPos, crypto, modulo } = Numeric;
|
|
457
|
+
const data = {
|
|
458
|
+
precision,
|
|
459
|
+
rounding,
|
|
460
|
+
minE,
|
|
461
|
+
maxE,
|
|
462
|
+
toExpNeg,
|
|
463
|
+
toExpPos,
|
|
464
|
+
crypto,
|
|
465
|
+
modulo,
|
|
466
|
+
defaults: false
|
|
467
|
+
};
|
|
468
|
+
return data;
|
|
469
|
+
};
|
|
470
|
+
const setupNumericConfig = ()=>{
|
|
471
|
+
const config = {
|
|
472
|
+
precision: 256,
|
|
473
|
+
toExpNeg: Numeric.minE,
|
|
474
|
+
toExpPos: Numeric.maxE,
|
|
475
|
+
crypto: false
|
|
476
|
+
};
|
|
477
|
+
Numeric.set({
|
|
478
|
+
defaults: true
|
|
479
|
+
});
|
|
480
|
+
Numeric.set(config);
|
|
481
|
+
};
|
|
482
|
+
const constants_namespaceObject = require("@ethersproject/constants");
|
|
483
|
+
const NegativeOne = new Numeric(-1);
|
|
484
|
+
const Zero = new Numeric(0);
|
|
485
|
+
const One = new Numeric(1);
|
|
486
|
+
const Two = new Numeric(2);
|
|
487
|
+
const WeiPerEther = new Numeric(constants_namespaceObject.WeiPerEther);
|
|
488
|
+
const MaxUint256 = new Numeric(constants_namespaceObject.MaxUint256);
|
|
489
|
+
const MaxInt256 = new Numeric(constants_namespaceObject.MaxInt256);
|
|
490
|
+
const MinInt256 = new Numeric(constants_namespaceObject.MinInt256);
|
|
491
|
+
const isRange = (value, minimum, maximum, options)=>{
|
|
492
|
+
try {
|
|
493
|
+
const data = toNumeric(value);
|
|
494
|
+
const defaultOptions = {
|
|
495
|
+
includeMaximum: true,
|
|
496
|
+
includeMinimum: true
|
|
497
|
+
};
|
|
498
|
+
const { includeMaximum, includeMinimum } = options ? Object.assign({}, defaultOptions, options) : defaultOptions;
|
|
499
|
+
const isOverLower = includeMinimum ? data.lessThan(minimum) : data.lessThanOrEqualTo(minimum);
|
|
500
|
+
const isOverUpper = includeMaximum ? data.greaterThan(maximum) : data.greaterThanOrEqualTo(maximum);
|
|
501
|
+
return !(isOverLower || isOverUpper);
|
|
502
|
+
} catch (error) {
|
|
503
|
+
return false;
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
const tryParse = (value)=>{
|
|
507
|
+
try {
|
|
508
|
+
return toNumeric(value);
|
|
509
|
+
} catch (error) {
|
|
510
|
+
return false;
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
const isInteger = (value)=>{
|
|
514
|
+
const data = tryParse(value);
|
|
515
|
+
return false !== data && data.isInteger();
|
|
516
|
+
};
|
|
517
|
+
const isUnsignedIntegerBits = (bits, value)=>{
|
|
518
|
+
if (0n > bits || false === isInteger(value)) return false;
|
|
519
|
+
const maximum = Two.toPower(bits);
|
|
520
|
+
const minimum = Zero;
|
|
521
|
+
const options = {
|
|
522
|
+
includeMinimum: true,
|
|
523
|
+
includeMaximum: false
|
|
524
|
+
};
|
|
525
|
+
return isRange(value, minimum, maximum, options);
|
|
526
|
+
};
|
|
527
|
+
const isSignedIntegerBits = (bits, value)=>{
|
|
528
|
+
if (0n > bits || false === isInteger(value)) return false;
|
|
529
|
+
const maximum = Two.toPower(bits - 1n);
|
|
530
|
+
const minimum = NegativeOne.times(maximum);
|
|
531
|
+
const options = {
|
|
532
|
+
includeMinimum: true,
|
|
533
|
+
includeMaximum: false
|
|
534
|
+
};
|
|
535
|
+
return isRange(value, minimum, maximum, options);
|
|
536
|
+
};
|
|
537
|
+
const createArrayCompareFunction = (ascending = true)=>ascending ? (left, right)=>Numeric.sub(left, right).toNumber() : (left, right)=>Numeric.sub(right, left).toNumber();
|
|
538
|
+
exports.MaxInt256 = __webpack_exports__.MaxInt256;
|
|
539
|
+
exports.MaxUint256 = __webpack_exports__.MaxUint256;
|
|
540
|
+
exports.MinInt256 = __webpack_exports__.MinInt256;
|
|
541
|
+
exports.NegativeOne = __webpack_exports__.NegativeOne;
|
|
542
|
+
exports.Numeric = __webpack_exports__.Numeric;
|
|
543
|
+
exports.One = __webpack_exports__.One;
|
|
544
|
+
exports.Two = __webpack_exports__.Two;
|
|
545
|
+
exports.WeiPerEther = __webpack_exports__.WeiPerEther;
|
|
546
|
+
exports.Zero = __webpack_exports__.Zero;
|
|
547
|
+
exports.createArrayCompareFunction = __webpack_exports__.createArrayCompareFunction;
|
|
548
|
+
exports.formatValue = __webpack_exports__.formatValue;
|
|
549
|
+
exports.getNumericConfig = __webpack_exports__.getNumericConfig;
|
|
550
|
+
exports.isInteger = __webpack_exports__.isInteger;
|
|
551
|
+
exports.isRange = __webpack_exports__.isRange;
|
|
552
|
+
exports.isSignedIntegerBits = __webpack_exports__.isSignedIntegerBits;
|
|
553
|
+
exports.isUnsignedIntegerBits = __webpack_exports__.isUnsignedIntegerBits;
|
|
554
|
+
exports.setupNumericConfig = __webpack_exports__.setupNumericConfig;
|
|
555
|
+
exports.toBN = __webpack_exports__.toBN;
|
|
556
|
+
exports.toBigInt = __webpack_exports__.toBigInt;
|
|
557
|
+
exports.toBigInteger = __webpack_exports__.toBigInteger;
|
|
558
|
+
exports.toBigNumber = __webpack_exports__.toBigNumber;
|
|
559
|
+
exports.toIntegerString = __webpack_exports__.toIntegerString;
|
|
560
|
+
exports.toNumeric = __webpack_exports__.toNumeric;
|
|
561
|
+
exports.toNumerics = __webpack_exports__.toNumerics;
|
|
562
|
+
exports.tryParse = __webpack_exports__.tryParse;
|
|
563
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
564
|
+
"MaxInt256",
|
|
565
|
+
"MaxUint256",
|
|
566
|
+
"MinInt256",
|
|
567
|
+
"NegativeOne",
|
|
568
|
+
"Numeric",
|
|
569
|
+
"One",
|
|
570
|
+
"Two",
|
|
571
|
+
"WeiPerEther",
|
|
572
|
+
"Zero",
|
|
573
|
+
"createArrayCompareFunction",
|
|
574
|
+
"formatValue",
|
|
575
|
+
"getNumericConfig",
|
|
576
|
+
"isInteger",
|
|
577
|
+
"isRange",
|
|
578
|
+
"isSignedIntegerBits",
|
|
579
|
+
"isUnsignedIntegerBits",
|
|
580
|
+
"setupNumericConfig",
|
|
581
|
+
"toBN",
|
|
582
|
+
"toBigInt",
|
|
583
|
+
"toBigInteger",
|
|
584
|
+
"toBigNumber",
|
|
585
|
+
"toIntegerString",
|
|
586
|
+
"toNumeric",
|
|
587
|
+
"toNumerics",
|
|
588
|
+
"tryParse"
|
|
589
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
590
|
+
Object.defineProperty(exports, '__esModule', {
|
|
591
|
+
value: true
|
|
592
|
+
});
|
package/lib/index.mjs
ADDED
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
import { BigNumber } from "@ethersproject/bignumber";
|
|
2
|
+
import { hexlify, isBytesLike } from "@ethersproject/bytes";
|
|
3
|
+
import big_integer from "big-integer";
|
|
4
|
+
import bn from "bn.js";
|
|
5
|
+
import { isNode } from "browser-or-node";
|
|
6
|
+
import { Decimal } from "decimal.js";
|
|
7
|
+
import format_number from "format-number";
|
|
8
|
+
import { MaxInt256, MaxUint256, MinInt256, WeiPerEther } from "@ethersproject/constants";
|
|
9
|
+
const toNumeric = (value)=>new Numeric(value);
|
|
10
|
+
const toNumerics = (values)=>values.map(toNumeric);
|
|
11
|
+
const toIntegerString = (value)=>toNumeric(value).toFixed(0);
|
|
12
|
+
const toBigInt = (value)=>BigInt(toIntegerString(value));
|
|
13
|
+
const toBN = (value)=>new bn(toIntegerString(value));
|
|
14
|
+
const toBigInteger = (value)=>big_integer(toIntegerString(value));
|
|
15
|
+
const toBigNumber = (value)=>BigNumber.from(toIntegerString(value));
|
|
16
|
+
class Numeric extends Decimal {
|
|
17
|
+
constructor(value){
|
|
18
|
+
if (value instanceof Decimal) super(value);
|
|
19
|
+
else switch(typeof value){
|
|
20
|
+
case 'string':
|
|
21
|
+
case 'number':
|
|
22
|
+
super(value);
|
|
23
|
+
break;
|
|
24
|
+
case 'bigint':
|
|
25
|
+
super(value.toString());
|
|
26
|
+
break;
|
|
27
|
+
default:
|
|
28
|
+
if (big_integer.isInstance(value) || BigNumber.isBigNumber(value) || bn.isBN(value)) super(value.toString());
|
|
29
|
+
else if (isBytesLike(value)) super(hexlify(value));
|
|
30
|
+
else super(value);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
static abs(value) {
|
|
35
|
+
return new Numeric(value).abs();
|
|
36
|
+
}
|
|
37
|
+
static acos(value) {
|
|
38
|
+
return new Numeric(value).acos();
|
|
39
|
+
}
|
|
40
|
+
static acosh(value) {
|
|
41
|
+
return new Numeric(value).acosh();
|
|
42
|
+
}
|
|
43
|
+
static add(x, y) {
|
|
44
|
+
return new Numeric(x).add(y);
|
|
45
|
+
}
|
|
46
|
+
static asin(value) {
|
|
47
|
+
return new Numeric(value).asin();
|
|
48
|
+
}
|
|
49
|
+
static asinh(value) {
|
|
50
|
+
return new Numeric(value).asinh();
|
|
51
|
+
}
|
|
52
|
+
static atan(value) {
|
|
53
|
+
return new Numeric(value).atan();
|
|
54
|
+
}
|
|
55
|
+
static atanh(value) {
|
|
56
|
+
return new Numeric(value).atanh();
|
|
57
|
+
}
|
|
58
|
+
static atan2(x, y) {
|
|
59
|
+
return new Numeric(Decimal.atan2(new Numeric(x), new Numeric(y)));
|
|
60
|
+
}
|
|
61
|
+
static cbrt(value) {
|
|
62
|
+
return new Numeric(value).cbrt();
|
|
63
|
+
}
|
|
64
|
+
static ceil(value) {
|
|
65
|
+
return new Numeric(value).ceil();
|
|
66
|
+
}
|
|
67
|
+
static clamp(value, min, max) {
|
|
68
|
+
return new Numeric(Decimal.clamp(new Numeric(value), new Numeric(min), new Numeric(max)));
|
|
69
|
+
}
|
|
70
|
+
static cos(value) {
|
|
71
|
+
return new Numeric(value).cos();
|
|
72
|
+
}
|
|
73
|
+
static cosh(value) {
|
|
74
|
+
return new Numeric(value).cosh();
|
|
75
|
+
}
|
|
76
|
+
static div(x, y) {
|
|
77
|
+
return new Numeric(x).div(y);
|
|
78
|
+
}
|
|
79
|
+
static exp(value) {
|
|
80
|
+
return new Numeric(value).exp();
|
|
81
|
+
}
|
|
82
|
+
static floor(value) {
|
|
83
|
+
return new Numeric(value).floor();
|
|
84
|
+
}
|
|
85
|
+
static hypot(...values) {
|
|
86
|
+
return new Numeric(Decimal.hypot(...toNumerics(values)));
|
|
87
|
+
}
|
|
88
|
+
static ln(value) {
|
|
89
|
+
return new Numeric(value).ln();
|
|
90
|
+
}
|
|
91
|
+
static log(value, base) {
|
|
92
|
+
return new Numeric(value).log(base);
|
|
93
|
+
}
|
|
94
|
+
static log2(value) {
|
|
95
|
+
return new Numeric(value).log(2);
|
|
96
|
+
}
|
|
97
|
+
static log10(value) {
|
|
98
|
+
return new Numeric(value).log(10);
|
|
99
|
+
}
|
|
100
|
+
static max(...values) {
|
|
101
|
+
return new Numeric(Decimal.max(...toNumerics(values)));
|
|
102
|
+
}
|
|
103
|
+
static min(...values) {
|
|
104
|
+
return new Numeric(Decimal.min(...toNumerics(values)));
|
|
105
|
+
}
|
|
106
|
+
static mod(x, y) {
|
|
107
|
+
return new Numeric(x).mod(y);
|
|
108
|
+
}
|
|
109
|
+
static mul(x, y) {
|
|
110
|
+
return new Numeric(x).mul(y);
|
|
111
|
+
}
|
|
112
|
+
static pow(base, exponent) {
|
|
113
|
+
return new Numeric(base).pow(exponent);
|
|
114
|
+
}
|
|
115
|
+
static random(significantDigits) {
|
|
116
|
+
return new Numeric(Decimal.random(significantDigits));
|
|
117
|
+
}
|
|
118
|
+
static round(value) {
|
|
119
|
+
return new Numeric(value).round();
|
|
120
|
+
}
|
|
121
|
+
static set(object) {
|
|
122
|
+
return Decimal.set(object);
|
|
123
|
+
}
|
|
124
|
+
static sign(value) {
|
|
125
|
+
return Decimal.sign(new Numeric(value));
|
|
126
|
+
}
|
|
127
|
+
static sin(value) {
|
|
128
|
+
return new Numeric(value).sin();
|
|
129
|
+
}
|
|
130
|
+
static sinh(value) {
|
|
131
|
+
return new Numeric(value).sinh();
|
|
132
|
+
}
|
|
133
|
+
static sqrt(value) {
|
|
134
|
+
return new Numeric(value).sqrt();
|
|
135
|
+
}
|
|
136
|
+
static sub(x, y) {
|
|
137
|
+
return new Numeric(x).sub(y);
|
|
138
|
+
}
|
|
139
|
+
static sum(...values) {
|
|
140
|
+
return new Numeric(Decimal.sum(...toNumerics(values)));
|
|
141
|
+
}
|
|
142
|
+
static tan(value) {
|
|
143
|
+
return new Numeric(value).tan();
|
|
144
|
+
}
|
|
145
|
+
static tanh(value) {
|
|
146
|
+
return new Numeric(value).tanh();
|
|
147
|
+
}
|
|
148
|
+
static trunc(value) {
|
|
149
|
+
return new Numeric(value).trunc();
|
|
150
|
+
}
|
|
151
|
+
absoluteValue() {
|
|
152
|
+
return new Numeric(super.absoluteValue());
|
|
153
|
+
}
|
|
154
|
+
abs() {
|
|
155
|
+
return new Numeric(super.abs());
|
|
156
|
+
}
|
|
157
|
+
ceil() {
|
|
158
|
+
return new Numeric(super.ceil());
|
|
159
|
+
}
|
|
160
|
+
clampedTo(min, max) {
|
|
161
|
+
return new Numeric(super.clampedTo(new Numeric(min), new Numeric(max)));
|
|
162
|
+
}
|
|
163
|
+
clamp(min, max) {
|
|
164
|
+
return new Numeric(super.clamp(new Numeric(min), new Numeric(max)));
|
|
165
|
+
}
|
|
166
|
+
comparedTo(value) {
|
|
167
|
+
return super.comparedTo(new Numeric(value));
|
|
168
|
+
}
|
|
169
|
+
cmp(value) {
|
|
170
|
+
return super.cmp(new Numeric(value));
|
|
171
|
+
}
|
|
172
|
+
cosine() {
|
|
173
|
+
return new Numeric(super.cosine());
|
|
174
|
+
}
|
|
175
|
+
cos() {
|
|
176
|
+
return new Numeric(super.cos());
|
|
177
|
+
}
|
|
178
|
+
cubeRoot() {
|
|
179
|
+
return new Numeric(super.cubeRoot());
|
|
180
|
+
}
|
|
181
|
+
cbrt() {
|
|
182
|
+
return new Numeric(super.cbrt());
|
|
183
|
+
}
|
|
184
|
+
dividedBy(value) {
|
|
185
|
+
return new Numeric(super.dividedBy(new Numeric(value)));
|
|
186
|
+
}
|
|
187
|
+
div(value) {
|
|
188
|
+
return new Numeric(super.div(new Numeric(value)));
|
|
189
|
+
}
|
|
190
|
+
dividedToIntegerBy(value) {
|
|
191
|
+
return new Numeric(super.dividedToIntegerBy(new Numeric(value)));
|
|
192
|
+
}
|
|
193
|
+
divToInt(value) {
|
|
194
|
+
return new Numeric(super.divToInt(new Numeric(value)));
|
|
195
|
+
}
|
|
196
|
+
equals(value) {
|
|
197
|
+
return super.equals(new Numeric(value));
|
|
198
|
+
}
|
|
199
|
+
eq(value) {
|
|
200
|
+
return super.eq(new Numeric(value));
|
|
201
|
+
}
|
|
202
|
+
floor() {
|
|
203
|
+
return new Numeric(super.floor());
|
|
204
|
+
}
|
|
205
|
+
greaterThan(value) {
|
|
206
|
+
return super.greaterThan(new Numeric(value));
|
|
207
|
+
}
|
|
208
|
+
gt(value) {
|
|
209
|
+
return super.gt(new Numeric(value));
|
|
210
|
+
}
|
|
211
|
+
greaterThanOrEqualTo(value) {
|
|
212
|
+
return super.greaterThanOrEqualTo(new Numeric(value));
|
|
213
|
+
}
|
|
214
|
+
gte(value) {
|
|
215
|
+
return super.gte(new Numeric(value));
|
|
216
|
+
}
|
|
217
|
+
hyperbolicCosine() {
|
|
218
|
+
return new Numeric(super.hyperbolicCosine());
|
|
219
|
+
}
|
|
220
|
+
cosh() {
|
|
221
|
+
return new Numeric(super.cosh());
|
|
222
|
+
}
|
|
223
|
+
hyperbolicSine() {
|
|
224
|
+
return new Numeric(super.hyperbolicSine());
|
|
225
|
+
}
|
|
226
|
+
sinh() {
|
|
227
|
+
return new Numeric(super.sinh());
|
|
228
|
+
}
|
|
229
|
+
hyperbolicTangent() {
|
|
230
|
+
return new Numeric(super.hyperbolicTangent());
|
|
231
|
+
}
|
|
232
|
+
tanh() {
|
|
233
|
+
return new Numeric(super.tanh());
|
|
234
|
+
}
|
|
235
|
+
inverseCosine() {
|
|
236
|
+
return new Numeric(super.inverseCosine());
|
|
237
|
+
}
|
|
238
|
+
acos() {
|
|
239
|
+
return new Numeric(super.acos());
|
|
240
|
+
}
|
|
241
|
+
inverseHyperbolicCosine() {
|
|
242
|
+
return new Numeric(super.inverseHyperbolicCosine());
|
|
243
|
+
}
|
|
244
|
+
acosh() {
|
|
245
|
+
return new Numeric(super.acosh());
|
|
246
|
+
}
|
|
247
|
+
inverseHyperbolicSine() {
|
|
248
|
+
return new Numeric(super.inverseHyperbolicSine());
|
|
249
|
+
}
|
|
250
|
+
asinh() {
|
|
251
|
+
return new Numeric(super.asinh());
|
|
252
|
+
}
|
|
253
|
+
inverseHyperbolicTangent() {
|
|
254
|
+
return new Numeric(super.inverseHyperbolicTangent());
|
|
255
|
+
}
|
|
256
|
+
atanh() {
|
|
257
|
+
return new Numeric(super.atanh());
|
|
258
|
+
}
|
|
259
|
+
inverseSine() {
|
|
260
|
+
return new Numeric(super.inverseSine());
|
|
261
|
+
}
|
|
262
|
+
asin() {
|
|
263
|
+
return new Numeric(super.asin());
|
|
264
|
+
}
|
|
265
|
+
inverseTangent() {
|
|
266
|
+
return new Numeric(super.inverseTangent());
|
|
267
|
+
}
|
|
268
|
+
atan() {
|
|
269
|
+
return new Numeric(super.atan());
|
|
270
|
+
}
|
|
271
|
+
lessThan(value) {
|
|
272
|
+
return super.lessThan(new Numeric(value));
|
|
273
|
+
}
|
|
274
|
+
lt(value) {
|
|
275
|
+
return super.lt(new Numeric(value));
|
|
276
|
+
}
|
|
277
|
+
lessThanOrEqualTo(value) {
|
|
278
|
+
return super.lessThanOrEqualTo(new Numeric(value));
|
|
279
|
+
}
|
|
280
|
+
lte(value) {
|
|
281
|
+
return super.lte(new Numeric(value));
|
|
282
|
+
}
|
|
283
|
+
logarithm(value) {
|
|
284
|
+
return new Numeric(super.logarithm(void 0 === value ? void 0 : new Numeric(value)));
|
|
285
|
+
}
|
|
286
|
+
log(value) {
|
|
287
|
+
return new Numeric(super.log(void 0 === value ? void 0 : new Numeric(value)));
|
|
288
|
+
}
|
|
289
|
+
minus(value) {
|
|
290
|
+
return new Numeric(super.minus(new Numeric(value)));
|
|
291
|
+
}
|
|
292
|
+
sub(value) {
|
|
293
|
+
return new Numeric(super.sub(new Numeric(value)));
|
|
294
|
+
}
|
|
295
|
+
modulo(value) {
|
|
296
|
+
return new Numeric(super.modulo(new Numeric(value)));
|
|
297
|
+
}
|
|
298
|
+
mod(value) {
|
|
299
|
+
return new Numeric(super.mod(new Numeric(value)));
|
|
300
|
+
}
|
|
301
|
+
naturalExponential() {
|
|
302
|
+
return new Numeric(super.naturalExponential());
|
|
303
|
+
}
|
|
304
|
+
exp() {
|
|
305
|
+
return new Numeric(super.exp());
|
|
306
|
+
}
|
|
307
|
+
naturalLogarithm() {
|
|
308
|
+
return new Numeric(super.naturalLogarithm());
|
|
309
|
+
}
|
|
310
|
+
ln() {
|
|
311
|
+
return new Numeric(super.ln());
|
|
312
|
+
}
|
|
313
|
+
negated() {
|
|
314
|
+
return new Numeric(super.negated());
|
|
315
|
+
}
|
|
316
|
+
neg() {
|
|
317
|
+
return new Numeric(super.neg());
|
|
318
|
+
}
|
|
319
|
+
plus(value) {
|
|
320
|
+
return new Numeric(super.plus(new Numeric(value)));
|
|
321
|
+
}
|
|
322
|
+
add(value) {
|
|
323
|
+
return new Numeric(super.add(new Numeric(value)));
|
|
324
|
+
}
|
|
325
|
+
round() {
|
|
326
|
+
return new Numeric(super.round());
|
|
327
|
+
}
|
|
328
|
+
sine() {
|
|
329
|
+
return new Numeric(super.sine());
|
|
330
|
+
}
|
|
331
|
+
sin() {
|
|
332
|
+
return new Numeric(super.sin());
|
|
333
|
+
}
|
|
334
|
+
squareRoot() {
|
|
335
|
+
return new Numeric(super.squareRoot());
|
|
336
|
+
}
|
|
337
|
+
sqrt() {
|
|
338
|
+
return new Numeric(super.sqrt());
|
|
339
|
+
}
|
|
340
|
+
tangent() {
|
|
341
|
+
return new Numeric(super.tangent());
|
|
342
|
+
}
|
|
343
|
+
tan() {
|
|
344
|
+
return new Numeric(super.tan());
|
|
345
|
+
}
|
|
346
|
+
times(value) {
|
|
347
|
+
return new Numeric(super.times(new Numeric(value)));
|
|
348
|
+
}
|
|
349
|
+
mul(value) {
|
|
350
|
+
return new Numeric(super.mul(new Numeric(value)));
|
|
351
|
+
}
|
|
352
|
+
toDecimalPlaces(decimalPlaces, rounding) {
|
|
353
|
+
return new Numeric(void 0 !== rounding && void 0 !== decimalPlaces ? super.toDecimalPlaces(decimalPlaces, rounding) : super.toDecimalPlaces(decimalPlaces));
|
|
354
|
+
}
|
|
355
|
+
toDP(decimalPlaces, rounding) {
|
|
356
|
+
return new Numeric(void 0 !== rounding && void 0 !== decimalPlaces ? super.toDP(decimalPlaces, rounding) : super.toDP(decimalPlaces));
|
|
357
|
+
}
|
|
358
|
+
toFraction(maxDenominator) {
|
|
359
|
+
return toNumerics(super.toFraction(void 0 === maxDenominator ? void 0 : new Numeric(maxDenominator)));
|
|
360
|
+
}
|
|
361
|
+
toNearest(value, rounding) {
|
|
362
|
+
return new Numeric(super.toNearest(new Numeric(value), rounding));
|
|
363
|
+
}
|
|
364
|
+
toPower(value) {
|
|
365
|
+
return new Numeric(super.toPower(new Numeric(value)));
|
|
366
|
+
}
|
|
367
|
+
pow(value) {
|
|
368
|
+
return new Numeric(super.pow(new Numeric(value)));
|
|
369
|
+
}
|
|
370
|
+
toSignificantDigits(decimalPlaces, rounding) {
|
|
371
|
+
return new Numeric(void 0 !== rounding && void 0 !== decimalPlaces ? super.toSignificantDigits(decimalPlaces, rounding) : super.toSignificantDigits(decimalPlaces));
|
|
372
|
+
}
|
|
373
|
+
toSD(decimalPlaces, rounding) {
|
|
374
|
+
return new Numeric(void 0 !== rounding && void 0 !== decimalPlaces ? super.toSD(decimalPlaces, rounding) : super.toSD(decimalPlaces));
|
|
375
|
+
}
|
|
376
|
+
truncated() {
|
|
377
|
+
return new Numeric(super.truncated());
|
|
378
|
+
}
|
|
379
|
+
trunc() {
|
|
380
|
+
return new Numeric(super.trunc());
|
|
381
|
+
}
|
|
382
|
+
inspect(depth, options) {
|
|
383
|
+
const value = this.toFixed();
|
|
384
|
+
return isNode ? options.stylize(value, 'bigint') : value;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
const formatValue = (value, options)=>{
|
|
388
|
+
const format = format_number(options);
|
|
389
|
+
const text = new Numeric(value).toFixed();
|
|
390
|
+
return format(text);
|
|
391
|
+
};
|
|
392
|
+
const getNumericConfig = ()=>{
|
|
393
|
+
const { precision, rounding, minE, maxE, toExpNeg, toExpPos, crypto, modulo } = Numeric;
|
|
394
|
+
const data = {
|
|
395
|
+
precision,
|
|
396
|
+
rounding,
|
|
397
|
+
minE,
|
|
398
|
+
maxE,
|
|
399
|
+
toExpNeg,
|
|
400
|
+
toExpPos,
|
|
401
|
+
crypto,
|
|
402
|
+
modulo,
|
|
403
|
+
defaults: false
|
|
404
|
+
};
|
|
405
|
+
return data;
|
|
406
|
+
};
|
|
407
|
+
const setupNumericConfig = ()=>{
|
|
408
|
+
const config = {
|
|
409
|
+
precision: 256,
|
|
410
|
+
toExpNeg: Numeric.minE,
|
|
411
|
+
toExpPos: Numeric.maxE,
|
|
412
|
+
crypto: false
|
|
413
|
+
};
|
|
414
|
+
Numeric.set({
|
|
415
|
+
defaults: true
|
|
416
|
+
});
|
|
417
|
+
Numeric.set(config);
|
|
418
|
+
};
|
|
419
|
+
const NegativeOne = new Numeric(-1);
|
|
420
|
+
const Zero = new Numeric(0);
|
|
421
|
+
const One = new Numeric(1);
|
|
422
|
+
const Two = new Numeric(2);
|
|
423
|
+
const constants_WeiPerEther = new Numeric(WeiPerEther);
|
|
424
|
+
const constants_MaxUint256 = new Numeric(MaxUint256);
|
|
425
|
+
const constants_MaxInt256 = new Numeric(MaxInt256);
|
|
426
|
+
const constants_MinInt256 = new Numeric(MinInt256);
|
|
427
|
+
const isRange = (value, minimum, maximum, options)=>{
|
|
428
|
+
try {
|
|
429
|
+
const data = toNumeric(value);
|
|
430
|
+
const defaultOptions = {
|
|
431
|
+
includeMaximum: true,
|
|
432
|
+
includeMinimum: true
|
|
433
|
+
};
|
|
434
|
+
const { includeMaximum, includeMinimum } = options ? Object.assign({}, defaultOptions, options) : defaultOptions;
|
|
435
|
+
const isOverLower = includeMinimum ? data.lessThan(minimum) : data.lessThanOrEqualTo(minimum);
|
|
436
|
+
const isOverUpper = includeMaximum ? data.greaterThan(maximum) : data.greaterThanOrEqualTo(maximum);
|
|
437
|
+
return !(isOverLower || isOverUpper);
|
|
438
|
+
} catch (error) {
|
|
439
|
+
return false;
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
const tryParse = (value)=>{
|
|
443
|
+
try {
|
|
444
|
+
return toNumeric(value);
|
|
445
|
+
} catch (error) {
|
|
446
|
+
return false;
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
const isInteger = (value)=>{
|
|
450
|
+
const data = tryParse(value);
|
|
451
|
+
return false !== data && data.isInteger();
|
|
452
|
+
};
|
|
453
|
+
const isUnsignedIntegerBits = (bits, value)=>{
|
|
454
|
+
if (0n > bits || false === isInteger(value)) return false;
|
|
455
|
+
const maximum = Two.toPower(bits);
|
|
456
|
+
const minimum = Zero;
|
|
457
|
+
const options = {
|
|
458
|
+
includeMinimum: true,
|
|
459
|
+
includeMaximum: false
|
|
460
|
+
};
|
|
461
|
+
return isRange(value, minimum, maximum, options);
|
|
462
|
+
};
|
|
463
|
+
const isSignedIntegerBits = (bits, value)=>{
|
|
464
|
+
if (0n > bits || false === isInteger(value)) return false;
|
|
465
|
+
const maximum = Two.toPower(bits - 1n);
|
|
466
|
+
const minimum = NegativeOne.times(maximum);
|
|
467
|
+
const options = {
|
|
468
|
+
includeMinimum: true,
|
|
469
|
+
includeMaximum: false
|
|
470
|
+
};
|
|
471
|
+
return isRange(value, minimum, maximum, options);
|
|
472
|
+
};
|
|
473
|
+
const createArrayCompareFunction = (ascending = true)=>ascending ? (left, right)=>Numeric.sub(left, right).toNumber() : (left, right)=>Numeric.sub(right, left).toNumber();
|
|
474
|
+
export { NegativeOne, Numeric, One, Two, Zero, constants_MaxInt256 as MaxInt256, constants_MaxUint256 as MaxUint256, constants_MinInt256 as MinInt256, constants_WeiPerEther as WeiPerEther, createArrayCompareFunction, formatValue, getNumericConfig, isInteger, isRange, isSignedIntegerBits, isUnsignedIntegerBits, setupNumericConfig, toBN, toBigInt, toBigInteger, toBigNumber, toIntegerString, toNumeric, toNumerics, tryParse };
|
package/lib/numeric.d.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { BigNumber, BigNumberish } from '@ethersproject/bignumber';
|
|
2
|
+
import 'big-integer';
|
|
3
|
+
import bigInt from 'big-integer';
|
|
4
|
+
import 'bn.js';
|
|
5
|
+
import BN from 'bn.js';
|
|
6
|
+
import 'decimal.js';
|
|
7
|
+
import { Decimal } from 'decimal.js';
|
|
8
|
+
import { InspectOptionsStylized } from 'util';
|
|
9
|
+
export type NumericValue = Numeric | Decimal.Value | bigInt.BigNumber | BigNumberish;
|
|
10
|
+
export declare const toNumeric: (value: NumericValue) => Numeric;
|
|
11
|
+
export declare const toNumerics: (values: NumericValue[]) => Numeric[];
|
|
12
|
+
export declare const toIntegerString: (value: NumericValue) => string;
|
|
13
|
+
export declare const toBigInt: (value: NumericValue) => bigint;
|
|
14
|
+
export declare const toBN: (value: NumericValue) => BN;
|
|
15
|
+
export declare const toBigInteger: (value: NumericValue) => bigInt.BigInteger;
|
|
16
|
+
export declare const toBigNumber: (value: NumericValue) => BigNumber;
|
|
17
|
+
export declare class Numeric extends Decimal {
|
|
18
|
+
constructor(value: NumericValue);
|
|
19
|
+
static abs(value: NumericValue): Numeric;
|
|
20
|
+
static acos(value: NumericValue): Numeric;
|
|
21
|
+
static acosh(value: NumericValue): Numeric;
|
|
22
|
+
static add(x: NumericValue, y: NumericValue): Numeric;
|
|
23
|
+
static asin(value: NumericValue): Numeric;
|
|
24
|
+
static asinh(value: NumericValue): Numeric;
|
|
25
|
+
static atan(value: NumericValue): Numeric;
|
|
26
|
+
static atanh(value: NumericValue): Numeric;
|
|
27
|
+
static atan2(x: NumericValue, y: NumericValue): Numeric;
|
|
28
|
+
static cbrt(value: NumericValue): Numeric;
|
|
29
|
+
static ceil(value: NumericValue): Numeric;
|
|
30
|
+
static clamp(value: NumericValue, min: NumericValue, max: NumericValue): Numeric;
|
|
31
|
+
static cos(value: NumericValue): Numeric;
|
|
32
|
+
static cosh(value: NumericValue): Numeric;
|
|
33
|
+
static div(x: NumericValue, y: NumericValue): Numeric;
|
|
34
|
+
static exp(value: NumericValue): Numeric;
|
|
35
|
+
static floor(value: NumericValue): Numeric;
|
|
36
|
+
static hypot(...values: NumericValue[]): Numeric;
|
|
37
|
+
static ln(value: NumericValue): Numeric;
|
|
38
|
+
static log(value: NumericValue, base?: NumericValue): Numeric;
|
|
39
|
+
static log2(value: NumericValue): Numeric;
|
|
40
|
+
static log10(value: NumericValue): Numeric;
|
|
41
|
+
static max(...values: NumericValue[]): Numeric;
|
|
42
|
+
static min(...values: NumericValue[]): Numeric;
|
|
43
|
+
static mod(x: NumericValue, y: NumericValue): Numeric;
|
|
44
|
+
static mul(x: NumericValue, y: NumericValue): Numeric;
|
|
45
|
+
static pow(base: NumericValue, exponent: NumericValue): Numeric;
|
|
46
|
+
static random(significantDigits?: number): Numeric;
|
|
47
|
+
static round(value: NumericValue): Numeric;
|
|
48
|
+
static set(object: Decimal.Config): typeof Decimal;
|
|
49
|
+
static sign(value: NumericValue): number;
|
|
50
|
+
static sin(value: NumericValue): Numeric;
|
|
51
|
+
static sinh(value: NumericValue): Numeric;
|
|
52
|
+
static sqrt(value: NumericValue): Numeric;
|
|
53
|
+
static sub(x: NumericValue, y: NumericValue): Numeric;
|
|
54
|
+
static sum(...values: NumericValue[]): Numeric;
|
|
55
|
+
static tan(value: NumericValue): Numeric;
|
|
56
|
+
static tanh(value: NumericValue): Numeric;
|
|
57
|
+
static trunc(value: NumericValue): Numeric;
|
|
58
|
+
absoluteValue(): Numeric;
|
|
59
|
+
abs(): Numeric;
|
|
60
|
+
ceil(): Numeric;
|
|
61
|
+
clampedTo(min: NumericValue, max: NumericValue): Numeric;
|
|
62
|
+
clamp(min: NumericValue, max: NumericValue): Numeric;
|
|
63
|
+
comparedTo(value: NumericValue): number;
|
|
64
|
+
cmp(value: NumericValue): number;
|
|
65
|
+
cosine(): Numeric;
|
|
66
|
+
cos(): Numeric;
|
|
67
|
+
cubeRoot(): Numeric;
|
|
68
|
+
cbrt(): Numeric;
|
|
69
|
+
dividedBy(value: NumericValue): Numeric;
|
|
70
|
+
div(value: NumericValue): Numeric;
|
|
71
|
+
dividedToIntegerBy(value: NumericValue): Numeric;
|
|
72
|
+
divToInt(value: NumericValue): Numeric;
|
|
73
|
+
equals(value: NumericValue): boolean;
|
|
74
|
+
eq(value: NumericValue): boolean;
|
|
75
|
+
floor(): Numeric;
|
|
76
|
+
greaterThan(value: NumericValue): boolean;
|
|
77
|
+
gt(value: NumericValue): boolean;
|
|
78
|
+
greaterThanOrEqualTo(value: NumericValue): boolean;
|
|
79
|
+
gte(value: NumericValue): boolean;
|
|
80
|
+
hyperbolicCosine(): Numeric;
|
|
81
|
+
cosh(): Numeric;
|
|
82
|
+
hyperbolicSine(): Numeric;
|
|
83
|
+
sinh(): Numeric;
|
|
84
|
+
hyperbolicTangent(): Numeric;
|
|
85
|
+
tanh(): Numeric;
|
|
86
|
+
inverseCosine(): Numeric;
|
|
87
|
+
acos(): Numeric;
|
|
88
|
+
inverseHyperbolicCosine(): Numeric;
|
|
89
|
+
acosh(): Numeric;
|
|
90
|
+
inverseHyperbolicSine(): Numeric;
|
|
91
|
+
asinh(): Numeric;
|
|
92
|
+
inverseHyperbolicTangent(): Numeric;
|
|
93
|
+
atanh(): Numeric;
|
|
94
|
+
inverseSine(): Numeric;
|
|
95
|
+
asin(): Numeric;
|
|
96
|
+
inverseTangent(): Numeric;
|
|
97
|
+
atan(): Numeric;
|
|
98
|
+
lessThan(value: NumericValue): boolean;
|
|
99
|
+
lt(value: NumericValue): boolean;
|
|
100
|
+
lessThanOrEqualTo(value: NumericValue): boolean;
|
|
101
|
+
lte(value: NumericValue): boolean;
|
|
102
|
+
logarithm(value?: NumericValue): Numeric;
|
|
103
|
+
log(value?: NumericValue): Numeric;
|
|
104
|
+
minus(value: NumericValue): Numeric;
|
|
105
|
+
sub(value: NumericValue): Numeric;
|
|
106
|
+
modulo(value: NumericValue): Numeric;
|
|
107
|
+
mod(value: NumericValue): Numeric;
|
|
108
|
+
naturalExponential(): Numeric;
|
|
109
|
+
exp(): Numeric;
|
|
110
|
+
naturalLogarithm(): Numeric;
|
|
111
|
+
ln(): Numeric;
|
|
112
|
+
negated(): Numeric;
|
|
113
|
+
neg(): Numeric;
|
|
114
|
+
plus(value: NumericValue): Numeric;
|
|
115
|
+
add(value: NumericValue): Numeric;
|
|
116
|
+
round(): Numeric;
|
|
117
|
+
sine(): Numeric;
|
|
118
|
+
sin(): Numeric;
|
|
119
|
+
squareRoot(): Numeric;
|
|
120
|
+
sqrt(): Numeric;
|
|
121
|
+
tangent(): Numeric;
|
|
122
|
+
tan(): Numeric;
|
|
123
|
+
times(value: NumericValue): Numeric;
|
|
124
|
+
mul(value: NumericValue): Numeric;
|
|
125
|
+
toDecimalPlaces(decimalPlaces?: number, rounding?: Decimal.Rounding): Numeric;
|
|
126
|
+
toDP(decimalPlaces?: number, rounding?: Decimal.Rounding): Numeric;
|
|
127
|
+
toFraction(maxDenominator?: NumericValue): Numeric[];
|
|
128
|
+
toNearest(value: NumericValue, rounding?: Decimal.Rounding): Numeric;
|
|
129
|
+
toPower(value: NumericValue): Numeric;
|
|
130
|
+
pow(value: NumericValue): Numeric;
|
|
131
|
+
toSignificantDigits(decimalPlaces?: number, rounding?: Decimal.Rounding): Numeric;
|
|
132
|
+
toSD(decimalPlaces?: number, rounding?: Decimal.Rounding): Numeric;
|
|
133
|
+
truncated(): Numeric;
|
|
134
|
+
trunc(): Numeric;
|
|
135
|
+
inspect(depth: number, options: InspectOptionsStylized): string;
|
|
136
|
+
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agrozyme/numeric",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.32",
|
|
4
4
|
"description": "",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
|
-
"types": "./
|
|
8
|
-
"require": "./
|
|
9
|
-
"import": "./
|
|
7
|
+
"types": "./lib/index.d.ts",
|
|
8
|
+
"require": "./lib/index.js",
|
|
9
|
+
"import": "./lib/index.mjs"
|
|
10
10
|
}
|
|
11
11
|
},
|
|
12
|
-
"main": "./
|
|
13
|
-
"module": "./
|
|
14
|
-
"types": "./
|
|
12
|
+
"main": "./lib/index.js",
|
|
13
|
+
"module": "./lib/index.mjs",
|
|
14
|
+
"types": "./lib/index.d.ts",
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
17
17
|
"url": "git+ssh://git@gitlab.com:agrozyme-package/TypeScript/numeric.git"
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"tslib": "^2.8.1"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
|
-
"clean": "shx rm -rf dist",
|
|
46
|
+
"clean": "shx rm -rf dist lib",
|
|
47
47
|
"build": "rslib build"
|
|
48
48
|
}
|
|
49
49
|
}
|