@numio/bigmath 2.2.0 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ### 2.2.2
2
+ Throw an error if input for MAD and IQR is less than 3 elements
3
+ Add home-page url
4
+
5
+ ### 2.2.1
6
+ Add Number format validation examples (README.md)
7
+
1
8
  ### 2.2.0
2
9
  Added `isHex(str: string): boolean` - Checks if a string is a valid hexadecimal number (prefixed with `0x` or `-0x`).
3
10
  Added `isBinary(str: string): boolean` - Checks if a string is a valid binary number (prefixed with `0b` or `-0b`).
package/README.md CHANGED
@@ -23,7 +23,7 @@
23
23
  * **Round Based on Significant Figures:** Control rounding based on the number of significant figures, crucial for scientific and engineering applications.
24
24
  * **Calculate Roots:**
25
25
  * **Calculate Square Root (`sqrt`):** Compute the square root of a number with arbitrary precision. You can also specify the desired precision of the result.
26
- * **NEW! Calculate Cube Root (`cbrt`):** Determine the cube root of a number with arbitrary precision, allowing you to specify the desired accuracy.
26
+ * ****NEW! Calculate Cube Root (`cbrt`):** Determine the cube root of a number with arbitrary precision, allowing you to specify the desired accuracy.
27
27
 
28
28
  * **Chain Operations with Pipe:** Simplify complex calculations by chaining arithmetic operations in a readable and intuitive manner.
29
29
  * **Analyze Data Distribution:**
@@ -33,12 +33,12 @@
33
33
  * **Compare Numbers:**
34
34
  * **Check for Equality (`isEqual`):** Accurately determine if two arbitrary-precision numbers are equal.
35
35
  * **Check if Left is Greater (`isLeftGreater`):** Precisely compare two arbitrary-precision numbers to see if the left operand is greater than the right.
36
- * **NEW! Check if Left is Greater or Equal (`isLeftGreaterOrEqual`):** Precisely compare two arbitrary-precision numbers to determine if the left operand is greater than or equal to the right.
36
+ * ****NEW! Check if Left is Greater or Equal (`isLeftGreaterOrEqual`):** Precisely compare two arbitrary-precision numbers to determine if the left operand is greater than or equal to the right.
37
37
  * **Sort Numbers Accurately:** Sort arrays of numbers, including negative and decimal values, in ascending or descending order, correctly handling string representations of numbers that JavaScript's native sort might misinterpret.
38
38
  * **Calculate Central Tendency:** Easily compute the mean (average) of a set of numbers.
39
39
  * **Identify Extremes:** Find the maximum and minimum values within an array of numbers.
40
- * **NEW! Calculate Absolute Value (`abs`):** Determine the non-negative value of a number, regardless of its sign.
41
- * **NEW! Convert Number to Another Base (`toBase`):** Seamlessly convert numbers between decimal, hexadecimal (HEX), binary, and octal representations.
40
+ * ****NEW! Calculate Absolute Value (`abs`):** Determine the non-negative value of a number, regardless of its sign.
41
+ * ****NEW! Convert Number to Another Base (`toBase`):** Seamlessly convert numbers between decimal, hexadecimal (HEX), binary, and octal representations.
42
42
 
43
43
  ## When is @numio/bigmath essential?
44
44
 
@@ -377,6 +377,40 @@ toBase({ value: "0b1101", toBase: 16 }) // d
377
377
  toBase({ value: "0o11", toBase: 10 }) // 9
378
378
  ```
379
379
 
380
+ ### Number format validation
381
+
382
+ ```javascript
383
+ import { isHex, isBinary, isDecimal, isOctal, isNumber } from "@numio/bigmath";
384
+
385
+ console.log(isHex("0x1A")); // true
386
+ console.log(isHex("1A")); // false (no 0x prefix)
387
+ console.log(isHex("-0x2f")); // true
388
+ console.log(isHex("0xG")); // false (invalid hex digit)
389
+
390
+ console.log(isBinary("0b101")); // true
391
+ console.log(isBinary("101")); // false (no 0b prefix)
392
+ console.log(isBinary("-0b11")); // true
393
+ console.log(isBinary("0b12")); // false (invalid binary digit)
394
+
395
+ console.log(isDecimal("123")); // true
396
+ console.log(isDecimal("123.45"));// true
397
+ console.log(isDecimal("-0.5")); // true
398
+ console.log(isDecimal(".5")); // false (leading dot)
399
+ console.log(isDecimal("10.")); // false (trailing dot)
400
+
401
+ console.log(isOctal("0o77")); // true
402
+ console.log(isOctal("77")); // false (no 0o prefix)
403
+ console.log(isOctal("-0o12")); // true
404
+ console.log(isOctal("0o19")); // false (invalid octal digit)
405
+
406
+ console.log(isNumber("0x1A")); // true (hex)
407
+ console.log(isNumber("0b101")); // true (binary)
408
+ console.log(isNumber("123.45"));// true (decimal)
409
+ console.log(isNumber("0o77")); // true (octal)
410
+ console.log(isNumber("123")); // true (decimal)
411
+ console.log(isNumber("abc")); // false (not a valid number)
412
+ ```
413
+
380
414
  Does not have a limitation on the number of digits. You can use any length you'd
381
415
  like
382
416
 
@@ -397,7 +431,7 @@ Download from NPM - https://www.npmjs.com/package/@numio/bigmath
397
431
 
398
432
  Download from JSR - https://jsr.io/@numio/bigmath
399
433
 
400
- Home page - https://github.com/shpunter/numio-bigmath/blob/main/README.md
434
+ Home page - https://numio.deno.dev
401
435
 
402
436
  Change log - https://github.com/shpunter/numio-bigmath/blob/main/CHANGELOG.md
403
437
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@numio/bigmath",
3
3
  "description": "@numio/bigmath is an arbitrary-precision arithmetic library. It can be used for basic operations with decimal numbers (integers and float)",
4
- "version": "2.2.0",
4
+ "version": "2.2.2",
5
5
  "keywords": [
6
6
  "precision",
7
7
  "arithmetic",
@@ -51,7 +51,8 @@
51
51
  "octal",
52
52
  "binary",
53
53
  "decimal",
54
- "binary"
54
+ "binary",
55
+ "cube root"
55
56
  ],
56
57
  "repository": {
57
58
  "type": "git",
package/src/IQR/utils.js CHANGED
@@ -4,6 +4,9 @@ import { PipeInner } from "../pipe/utils.js";
4
4
  import { quartileInner } from "../quartile/utils.js";
5
5
  export const MIN_LENGTH_FOR_MAD = 30;
6
6
  export const IQRInner = (array, sigNum = false) => {
7
+ if (array.length < 3) {
8
+ throw Error("To calculate IQR you need at least 3 elements");
9
+ }
7
10
  const { Q1, Q3 } = quartileInner(array);
8
11
  const sub = new PipeInner().sub([Q3, Q1]).calc();
9
12
  if (sigNum) {
package/src/MAD/utils.js CHANGED
@@ -3,6 +3,9 @@ import { quartileInner } from "../quartile/utils.js";
3
3
  import { ASC } from "../sort/constants.js";
4
4
  import { sortInner } from "../sort/utils.js";
5
5
  export const MADInner = (array) => {
6
+ if (array.length < 3) {
7
+ throw Error("To calculate MAD you need at least 3 elements");
8
+ }
6
9
  const median = quartileInner(array).Q2;
7
10
  const madArray = array.map((el) => {
8
11
  const [bi, fpe] = new PipeInner().sub([el, median]).calc();