@numio/bigmath 2.4.0 → 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,9 @@
1
+ ### 2.4.2
2
+ Improve performance of MAD, FDR, sorting
3
+
4
+ ### 2.4.1
5
+ Modulo - fix calculation
6
+
1
7
  ### 2.4.0
2
8
  Add Mod - Modulo operation, which finds the remainder when one number is divided by another
3
9
 
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.0",
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
@@ -1,6 +1,11 @@
1
1
  import { bi2s, s2bi } from "../shared/utils.js";
2
2
  import { modInner } from "./utils.js";
3
- export const mod = (left, right, options = { precision: 20 }) => {
4
- const bi = modInner(s2bi(left), s2bi(right), options);
5
- return bi2s(bi);
3
+ export const mod = (left, right) => {
4
+ const bil = s2bi(left);
5
+ const bir = s2bi(right);
6
+ if (bil[1] > 0)
7
+ throw new Error(`${left} is not valid. It should be integer to take a modulo`);
8
+ if (bir[1] > 0)
9
+ throw new Error(`${right} is not valid. It should be integer to take a modulo`);
10
+ return bi2s(modInner(bil, bir));
6
11
  };
@@ -1,6 +1,3 @@
1
1
  import type { BI } from "../shared/types.d.ts";
2
- export type ModOptions = {
3
- precision: number;
4
- };
5
- export type Mod = (left: string, right: string, options?: ModOptions) => string;
6
- export type ModInner = (left: BI, right: BI, options: ModOptions) => BI;
2
+ export type Mod = (left: string, right: string) => string;
3
+ export type ModInner = (left: BI, right: BI) => BI;
package/src/mod/utils.js CHANGED
@@ -1,6 +1,3 @@
1
- import { divInner } from "../operations/div/utils.js";
2
- import { tryBigInt } from "../shared/utils.js";
3
- export const modInner = (left, right, { precision }) => {
4
- const bi = divInner([left, right], precision);
5
- return bi[1] === 0 ? [0n, 0] : [bi[0] % (10n ** tryBigInt(bi[1])), 0];
1
+ export const modInner = (left, right) => {
2
+ return [((left[0] % right[0]) + right[0]) % right[0], 0];
6
3
  };
@@ -1,5 +1,4 @@
1
1
  import type { BI2S } from "../shared/types.d.ts";
2
- import type { ModOptions } from "../mod/types.d.ts";
3
2
  /** Using this function you can chain operations (add, sub, div, mul). */
4
3
  export declare class Pipe {
5
4
  #private;
@@ -9,7 +8,7 @@ export declare class Pipe {
9
8
  div(array: string[], precision?: number): Pipe;
10
9
  mul(array: string[]): Pipe;
11
10
  abs(): Pipe;
12
- mod(value: string, options?: ModOptions): Pipe;
11
+ mod(value: string): Pipe;
13
12
  calc(): ReturnType<BI2S>;
14
13
  resultToBase(radix: number): string;
15
14
  }
package/src/pipe/pipe.js CHANGED
@@ -47,11 +47,15 @@ export class Pipe {
47
47
  __classPrivateFieldSet(this, _Pipe_result, absInner(__classPrivateFieldGet(this, _Pipe_result, "f")), "f");
48
48
  return this;
49
49
  }
50
- mod(value, options = { precision: 20 }) {
51
- if (!__classPrivateFieldGet(this, _Pipe_result, "f")) {
50
+ mod(value) {
51
+ const right = s2bi(value);
52
+ if (!__classPrivateFieldGet(this, _Pipe_result, "f"))
52
53
  throw new Error("Value is undefined.");
53
- }
54
- __classPrivateFieldSet(this, _Pipe_result, modInner(__classPrivateFieldGet(this, _Pipe_result, "f"), s2bi(value), options), "f");
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.`);
58
+ __classPrivateFieldSet(this, _Pipe_result, modInner(__classPrivateFieldGet(this, _Pipe_result, "f"), s2bi(value)), "f");
55
59
  return this;
56
60
  }
57
61
  calc() {