@numio/bigmath 2.4.1 → 2.4.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,6 @@
1
+ ### 2.4.2
2
+ Improve performance of MAD, FDR, sorting
3
+
1
4
  ### 2.4.1
2
5
  Modulo - fix calculation
3
6
 
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Oleksandr Brudnovskyi
3
+ Copyright (c) 2025 Oleksandr Brudnovskyi
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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.4.1",
4
+ "version": "2.4.2",
5
5
  "keywords": [
6
6
  "precision",
7
7
  "arithmetic",
package/src/MAD/utils.js CHANGED
@@ -9,7 +9,7 @@ export const MADInner = (array, { from }) => {
9
9
  }
10
10
  const fromMap = {
11
11
  median: quartileInner(array).Q2,
12
- mean: meanInner(array)
12
+ mean: meanInner(array),
13
13
  };
14
14
  const madArray = array.map((el) => {
15
15
  return new PipeInner().sub([el, fromMap[from]]).abs().bi;
@@ -18,6 +18,10 @@ export const minInner = (array) => {
18
18
  export const compareInner = (l, r) => {
19
19
  const [biL, fpeL] = l;
20
20
  const [biR, fpeR] = r;
21
+ if (fpeL === fpeR && biL > biR)
22
+ return [l, 1];
23
+ if (fpeL === fpeR && biL < biR)
24
+ return [r, -1];
21
25
  if (biL > 0n && biR < 0n)
22
26
  return [l, 1];
23
27
  if (biL < 0n && biR > 0n)
package/src/mod/mod.js CHANGED
@@ -4,8 +4,8 @@ export const mod = (left, right) => {
4
4
  const bil = s2bi(left);
5
5
  const bir = s2bi(right);
6
6
  if (bil[1] > 0)
7
- throw new Error(`${left} is no valid. It should be integer`);
7
+ throw new Error(`${left} is not valid. It should be integer to take a modulo`);
8
8
  if (bir[1] > 0)
9
- throw new Error(`${right} is no valid. It should be integer`);
9
+ throw new Error(`${right} is not valid. It should be integer to take a modulo`);
10
10
  return bi2s(modInner(bil, bir));
11
11
  };
package/src/pipe/pipe.js CHANGED
@@ -48,9 +48,13 @@ export class Pipe {
48
48
  return this;
49
49
  }
50
50
  mod(value) {
51
- if (!__classPrivateFieldGet(this, _Pipe_result, "f")) {
51
+ const right = s2bi(value);
52
+ if (!__classPrivateFieldGet(this, _Pipe_result, "f"))
52
53
  throw new Error("Value is undefined.");
53
- }
54
+ if (__classPrivateFieldGet(this, _Pipe_result, "f")[1] > 0)
55
+ throw new Error(`${bi2s(__classPrivateFieldGet(this, _Pipe_result, "f"))} is not valid. It should be integer to take a modulo.`);
56
+ if (right[1] > 0)
57
+ throw new Error(`${value} is not valid. It should be integer to take a modulo.`);
54
58
  __classPrivateFieldSet(this, _Pipe_result, modInner(__classPrivateFieldGet(this, _Pipe_result, "f"), s2bi(value)), "f");
55
59
  return this;
56
60
  }