bigdecimal.js
Advanced tools
+61
-43
@@ -459,7 +459,9 @@ /** | ||
| * | ||
| * @param augend value to be added to this `BigDecimal`. | ||
| * @param mc the context to use. | ||
| * @param augend value to be added to this `BigDecimal`. This value will | ||
| * be converted to a `BigDecimal` before the operation. | ||
| * See the {@link Big | constructor} to learn more about the conversion. | ||
| * @param mc the context to use. | ||
| * @return `this + augend`, rounded as necessary. | ||
| */ | ||
| add(augend: BigDecimal, mc?: MathContext): BigDecimal; | ||
| add(augend: BigDecimal | BigInt | number | string, mc?: MathContext): BigDecimal; | ||
| /** | ||
@@ -472,7 +474,9 @@ * Returns a `BigDecimal` whose value is `(this - subtrahend)`, | ||
| * | ||
| * @param subtrahend value to be subtracted from this `BigDecimal`. | ||
| * @param mc the context to use. | ||
| * @param subtrahend value to be subtracted from this `BigDecimal`. This value | ||
| * will be converted to a `BigDecimal` before the operation. | ||
| * See the {@link Big | constructor} to learn more about the conversion. | ||
| * @param mc the context to use. | ||
| * @return `this - subtrahend`, rounded as necessary. | ||
| */ | ||
| subtract(subtrahend: BigDecimal, mc?: MathContext): BigDecimal; | ||
| subtract(subtrahend: BigDecimal | BigInt | number | string, mc?: MathContext): BigDecimal; | ||
| /** | ||
@@ -482,7 +486,9 @@ * Returns a `BigDecimal` whose value is <code>(this × | ||
| * | ||
| * @param multiplicand value to be multiplied by this `BigDecimal`. | ||
| * @param mc the context to use. | ||
| * @param multiplicand value to be multiplied by this `BigDecimal`. This | ||
| * value will be converted to a `BigDecimal` before the operation. | ||
| * See the {@link Big | constructor} to learn more about the conversion. | ||
| * @param mc the context to use. | ||
| * @return `this * multiplicand`, rounded as necessary. | ||
| */ | ||
| multiply(multiplicand: BigDecimal, mc?: MathContext): BigDecimal; | ||
| multiply(multiplicand: BigDecimal | BigInt | number | string, mc?: MathContext): BigDecimal; | ||
| /** | ||
@@ -494,5 +500,7 @@ * Returns a `BigDecimal` whose value is `(this / divisor)`, | ||
| * | ||
| * @param divisor value by which this `BigDecimal` is to be divided. | ||
| * @param scale scale of the `BigDecimal` quotient to be returned. | ||
| * @param roundingMode rounding mode to apply. | ||
| * @param divisor value by which this `BigDecimal` is to be divided. | ||
| * This value will be converted to a `BigDecimal` before the operation. | ||
| * See the {@link Big | constructor} to learn more about the conversion. | ||
| * @param scale scale of the `BigDecimal` quotient to be returned. | ||
| * @param roundingMode rounding mode to apply. | ||
| * @return `this / divisor` | ||
@@ -505,3 +513,3 @@ * @throws RangeError | ||
| */ | ||
| divide(divisor: BigDecimal, scale?: number, roundingMode?: RoundingMode): BigDecimal; | ||
| divide(divisor: BigDecimal | BigInt | number | string, scale?: number, roundingMode?: RoundingMode): BigDecimal; | ||
| /** | ||
@@ -511,4 +519,6 @@ * Returns a `BigDecimal` whose value is `(this / | ||
| * | ||
| * @param divisor value by which this `BigDecimal` is to be | ||
| * @param mc the context to use. | ||
| * @param divisor value by which this `BigDecimal` is to be divided. | ||
| * This value will be converted to a `BigDecimal` before the operation. | ||
| * See the {@link Big | constructor} to learn more about the conversion. | ||
| * @param mc the context to use. | ||
| * @throws RangeError if the exact quotient does not have a | ||
@@ -518,3 +528,3 @@ * terminating decimal expansion, including dividing by zero | ||
| */ | ||
| divideWithMathContext(divisor: BigDecimal, mc?: MathContext): BigDecimal; | ||
| divideWithMathContext(divisor: BigDecimal | BigInt | number | string, mc?: MathContext): BigDecimal; | ||
| /** | ||
@@ -531,4 +541,6 @@ * Returns a `BigDecimal` whose value is the integer part | ||
| * | ||
| * @param divisor value by which this `BigDecimal` is to be divided. | ||
| * @param mc the context to use. | ||
| * @param divisor value by which this `BigDecimal` is to be divided. | ||
| * This value will be converted to a `BigDecimal` before the operation. | ||
| * See the {@link Big | constructor} to learn more about the conversion. | ||
| * @param mc the context to use. | ||
| * @return The integer part of `this / divisor`. | ||
@@ -539,3 +551,3 @@ * @throws RangeError if divisor is 0 | ||
| */ | ||
| divideToIntegralValue(divisor: BigDecimal, mc?: MathContext): BigDecimal; | ||
| divideToIntegralValue(divisor: BigDecimal | BigInt | number | string, mc?: MathContext): BigDecimal; | ||
| /** | ||
@@ -553,4 +565,6 @@ * Returns a `BigDecimal` whose value is `(this % divisor)`, with rounding according to the context settings. | ||
| * | ||
| * @param divisor value by which this `BigDecimal` is to be divided. | ||
| * @param mc the context to use. | ||
| * @param divisor value by which this `BigDecimal` is to be divided. | ||
| * This value will be converted to a `BigDecimal` before the operation. | ||
| * See the {@link Big | constructor} to learn more about the conversion. | ||
| * @param mc the context to use. | ||
| * @return `this % divisor`, rounded as necessary. | ||
@@ -564,3 +578,3 @@ * @throws RangeError if divisor is 0 | ||
| */ | ||
| remainder(divisor: BigDecimal, mc?: MathContext): BigDecimal; | ||
| remainder(divisor: BigDecimal | BigInt | number | string, mc?: MathContext): BigDecimal; | ||
| /** | ||
@@ -580,3 +594,3 @@ * Compares this `BigDecimal` with the specified | ||
| * | ||
| * @param value to which this `BigDecimal` is | ||
| * @param value to which this `BigDecimal` is | ||
| * to be compared. | ||
@@ -600,5 +614,7 @@ * @return true if and only if the specified value is a | ||
| * | ||
| * @param divisor value by which this `BigDecimal` is to be divided, | ||
| * and the remainder computed. | ||
| * @param mc the context to use. | ||
| * @param divisor value by which this `BigDecimal` is to be divided, | ||
| * and the remainder computed. This value will be converted to a | ||
| * `BigDecimal` before the operation. See the | ||
| * {@link Big | constructor} to learn more about the conversion. | ||
| * @param mc the context to use. | ||
| * @return a two element `BigDecimal` array: the quotient | ||
@@ -615,3 +631,3 @@ * (the result of `divideToIntegralValue`) is the | ||
| */ | ||
| divideAndRemainder(divisor: BigDecimal, mc?: MathContext): [BigDecimal, BigDecimal]; | ||
| divideAndRemainder(divisor: BigDecimal | BigInt | number | string, mc?: MathContext): [BigDecimal, BigDecimal]; | ||
| /** | ||
@@ -713,8 +729,9 @@ * Returns an approximation to the square root of `this` | ||
| * @param val `BigDecimal` to which this `BigDecimal` is | ||
| * to be compared. | ||
| * @param val value to which this `BigDecimal` is to be compared. | ||
| * This value will be converted to a `BigDecimal` before the operation. | ||
| * See the {@link Big | constructor} to learn more about the conversion. | ||
| * @return -1, 0, or 1 as this `BigDecimal` is numerically | ||
| * less than, equal to, or greater than `val`. | ||
| */ | ||
| compareTo(val: BigDecimal): number; | ||
| compareTo(val: BigDecimal | BigInt | number | string): number; | ||
| /** | ||
@@ -750,4 +767,4 @@ * Converts this BigDecimal to number. | ||
| * | ||
| * @param newScale scale of the `BigDecimal` value to be returned. | ||
| * @param roundingMode The rounding mode to apply. By default it is set to `UNNECESSARY`. | ||
| * @param newScale scale of the `BigDecimal` value to be returned. | ||
| * @param roundingMode The rounding mode to apply. By default it is set to `UNNECESSARY`. | ||
| * @return a `BigDecimal` whose scale is the specified value, | ||
@@ -809,4 +826,4 @@ * and whose unscaled value is determined by multiplying or | ||
| * | ||
| * @param n power to raise this `BigDecimal` to. | ||
| * @param mc the context to use. | ||
| * @param n power to raise this `BigDecimal` to. | ||
| * @param mc the context to use. | ||
| * @return <code>this<sup>n</sup></code> using the ANSI standard X3.274-1996 | ||
@@ -845,3 +862,3 @@ * algorithm | ||
| * | ||
| * @param n number of places to move the decimal point to the left. | ||
| * @param n number of places to move the decimal point to the left. | ||
| * @return a `BigDecimal` which is equivalent to this one with the | ||
@@ -861,3 +878,3 @@ * decimal point moved `n` places to the left. | ||
| * | ||
| * @param n number of places to move the decimal point to the right. | ||
| * @param n number of places to move the decimal point to the right. | ||
| * @return a `BigDecimal` which is equivalent to this one | ||
@@ -871,3 +888,3 @@ * with the decimal point moved `n` places to the right. | ||
| * | ||
| * @param val value with which the minimum is to be computed. | ||
| * @param val value with which the minimum is to be computed. | ||
| * @return the `BigDecimal` whose value is the lesser of this | ||
@@ -883,3 +900,3 @@ * `BigDecimal` and `val`. If they are equal, | ||
| * | ||
| * @param val value with which the maximum is to be computed. | ||
| * @param val value with which the maximum is to be computed. | ||
| * @return the `BigDecimal` whose value is the greater of this | ||
@@ -1054,4 +1071,4 @@ * `BigDecimal` and `val`. If they are equal, | ||
| interface BigDecimalConstructor { | ||
| (n: any, scale?: number, mc?: MathContext): BigDecimal; | ||
| new (n: any, scale?: number, mc?: MathContext): BigDecimal; | ||
| (n: BigDecimal | BigInt | number | string, scale?: number, mc?: MathContext): BigDecimal; | ||
| new (n: BigDecimal | BigInt | number | string, scale?: number, mc?: MathContext): BigDecimal; | ||
| } | ||
@@ -1066,2 +1083,3 @@ /** | ||
| * Big(123n, 3, MC(2, RoundingMode.HALF_UP)); // bigint, scale and mc, 0.12 | ||
| * Big(aBigDecimal) // Copies the BigDecimal passed. "scale" and "mc" arguments will not used. | ||
| * Big(123n, undefined, MC(2, RoundingMode.HALF_UP)); // bigint and mc, 1.2E+2 | ||
@@ -1095,4 +1113,4 @@ * Big('1.13e12'); // string, 1.13E+12 | ||
| * | ||
| * @param n Any value to build a BigDecimal from. Types other than `Number`, `BigInt` and `BigDecimal` will be internally | ||
| * converted to string and parsed. | ||
| * @param n Any value to build a BigDecimal from. Types other than `Number` (as safe integer), `BigInt` and `BigDecimal` | ||
| * will be internally converted to string and parsed. | ||
| * @param scale Scale to use, by default 0. | ||
@@ -1106,3 +1124,3 @@ * @param mc MathContext object which allows you to set precision and rounding mode. | ||
| * * If value is a double and scale is given. | ||
| * * If value is not a `number`, a `BigInt` or a `BigDecimal`, it will be converted to string. | ||
| * * If value is not a `safe integer`, a `BigInt` or a `BigDecimal`, it will be converted to string. | ||
| * An error will be thrown if the string format is invalid. | ||
@@ -1109,0 +1127,0 @@ * * If value is not a `BigInt` or `number`, and scale is given. |
+9
-7
| { | ||
| "name": "bigdecimal.js", | ||
| "version": "1.1.3", | ||
| "version": "1.2.0", | ||
| "description": "A BigDecimal implementation with native BigInts", | ||
@@ -24,3 +24,3 @@ "exports": { | ||
| "lint": "eslint --cache --fix .", | ||
| "benchmark": "node benchmarks/runBench.js", | ||
| "benchmark": "node benchmarks", | ||
| "generate-test-files": "node util/generateTestFiles.js", | ||
@@ -61,13 +61,15 @@ "prepareESM": "mv lib/esm/bigdecimal.js lib/bigdecimal.mjs && rm -rf lib/esm", | ||
| }, | ||
| "homepage": "https://srknzl.github.io/bigdecimal.js/api/current/docs", | ||
| "homepage": "https://srknzl.github.io/bigdecimal.js/", | ||
| "devDependencies": { | ||
| "@istanbuljs/nyc-config-typescript": "~1.0.2", | ||
| "@typescript-eslint/eslint-plugin": "~5.10.0", | ||
| "@typescript-eslint/parser": "~5.10.0", | ||
| "@typescript-eslint/eslint-plugin": "~5.10.2", | ||
| "@typescript-eslint/parser": "~5.10.2", | ||
| "benchmark": "~2.1.4", | ||
| "big.js": "~6.1.1", | ||
| "bigdecimal": "~0.6.1", | ||
| "bignumber.js": "^9.0.2", | ||
| "chai": "~4.3", | ||
| "eslint": "~8.7.0", | ||
| "mocha": "~9.1.4", | ||
| "decimal.js": "^10.3.1", | ||
| "eslint": "~8.8.0", | ||
| "mocha": "~9.2.0", | ||
| "nyc": "~15.1.0", | ||
@@ -74,0 +76,0 @@ "rimraf": "~3.0.2", |
+23
-16
@@ -86,3 +86,5 @@ # BigDecimal.js | ||
| * [big.js](https://github.com/MikeMcl/big.js) | ||
| * [GWT based BigDecimal](https://github.com/iriscouch/bigdecimal.js) | ||
| * [bigdecimal](https://github.com/iriscouch/bigdecimal.js) | ||
| * [bignumber.js](https://github.com/MikeMcl/bignumber.js) | ||
| * [decimal.js](https://github.com/MikeMcl/decimal.js) | ||
@@ -96,25 +98,30 @@ To run the benchmark run `npm install` and then `npm run benchmark`. | ||
| * Test Machine: | ||
| * M1 2020 Macbook Air | ||
| * 8 GB Ram | ||
| * MacOS Monterey 12.0.1 | ||
| * Update Date: January 7th 2022 | ||
| * M1 2021 MacBook Pro | ||
| * 32 GB Ram | ||
| * MacOS Monterey 12.2.1 | ||
| * Update Date: June 16th 2022 | ||
| * Library versions used: | ||
| * big.js 6.1.1 | ||
| * (this library) bigdecimal.js 1.1.1 | ||
| * (this library) bigdecimal.js 1.1.3 | ||
| * bigdecimal 0.6.1 | ||
| * bignumber.js: 9.0.2 | ||
| * decimal.js:10.3.1 | ||
| * Each operation is run with fixed set of decimal numbers composed of both simple and complex numbers. | ||
| * Micro benchmark framework used is [benchmark](https://www.npmjs.com/package/benchmark). Check out [benchmarks folder](https://github.com/srknzl/bigdecimal.js/tree/main/benchmarks) for source code of benchmarks. | ||
| * For now, benchmarked the following operations, all operations will be added soon. | ||
| * For now, benchmarked the following operations, more operations will be added soon. | ||
| * Operations per second(op/s): | ||
| | Operation | Bigdecimal.js | Big.js | GWT | Winner | | ||
| | --- | --- | --- | --- | --- | | ||
| | Add | 79,130 | 18,675 | 85.21 | BigDecimal.js | | ||
| | Multiply | 495,894 | 33,534 | 2,607 | BigDecimal.js | | ||
| | Subtract | 72,754 | 18,190 | 88.47 | BigDecimal.js | | ||
| | Divide | 15,123 | 1,122 | 658 | BigDecimal.js | | ||
| | Abs | 751,232 | 1,405,722 | 13,732 | Big.js | | ||
| | Compare | 529,009 | 1,152,995 | 1,010,368 | Big.js | | ||
| | Remainder | 9,705 | 3,878 | 2,487 | BigDecimal.js | | ||
| | Operation | Bigdecimal.js | Big.js | BigNumber.js | decimal.js | GWTBased | | ||
| | --- | --- | --- | --- | --- | --- | | ||
| | Constructor | 44,267 ( - ) | 38,737 (<span style="color:red">-12%</span>) | 42,046 (<span style="color:red">-5%</span>) | 42,947 (<span style="color:red">-3%</span>) | 2,819 (<span style="color:red">-94%</span>) | | ||
| | Add | 80,650 ( - ) | 18,308 (<span style="color:red">-77%</span>) | 101,400 (<span style="color:green">**+26%**</span>) | 61,821 (<span style="color:red">-23%</span>) | 90 (<span style="color:red">-100%</span>) | | ||
| | Subtract | 74,916 ( - ) | 17,771 (<span style="color:red">-76%</span>) | 96,674 (<span style="color:green">**+29%**</span>) | 58,300 (<span style="color:red">-22%</span>) | 92 (<span style="color:red">-100%</span>) | | ||
| | Multiply | 498,855 ( - ) | 33,907 (<span style="color:red">-93%</span>) | 27,577 (<span style="color:red">-94%</span>) | 84,791 (<span style="color:red">-83%</span>) | 2,735 (<span style="color:red">-99%</span>) | | ||
| | Divide | 15,874 ( - ) | 1,146 (<span style="color:red">-93%</span>) | 12,482 (<span style="color:red">-21%</span>) | 14,581 (<span style="color:red">-8%</span>) | 672 (<span style="color:red">-96%</span>) | | ||
| | Remainder | 10,174 ( - ) | 3,992 (<span style="color:red">-61%</span>) | 14,122 (<span style="color:green">**+39%**</span>) | 23,369 (<span style="color:green">**+130%**</span>) | 2,562 (<span style="color:red">-75%</span>) | | ||
| | Positive pow | 28,110 ( - ) | 25 (<span style="color:red">-100%</span>) | 128 (<span style="color:red">-100%</span>) | 3,847 (<span style="color:red">-86%</span>) | 6 (<span style="color:red">-100%</span>) | | ||
| | Negative pow | 5,178 ( - ) | 21 (<span style="color:red">-100%</span>) | 122 (<span style="color:red">-98%</span>) | 2,147 (<span style="color:red">-59%</span>) | 282 (<span style="color:red">-95%</span>) | | ||
| | Abs | 801,274 ( - ) | 1,520,066 (<span style="color:green">**+90%**</span>) | 957,966 (<span style="color:green">**+20%**</span>) | 391,313 (<span style="color:red">-51%</span>) | 14,215 (<span style="color:red">-98%</span>) | | ||
| | Compare | 557,156 ( - ) | 1,235,655 (<span style="color:green">**+122%**</span>) | 801,622 (<span style="color:green">**+44%**</span>) | 431,935 (<span style="color:red">-22%</span>) | 1,034,051 (<span style="color:green">**+86%**</span>) | | ||
@@ -121,0 +128,0 @@ [npm-image]: https://img.shields.io/npm/v/bigdecimal.js.svg |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
431114
1.67%9263
0.65%0
-100%130
5.69%17
13.33%