cmath-js 1.2.1 → 1.4.0

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/README.md CHANGED
@@ -7,6 +7,7 @@ Implementation of parts of C's & C++'s numerics libraries in TypeScript/JavaScri
7
7
  - [`frexp`](https://en.cppreference.com/w/c/numeric/math/frexp)
8
8
  - [`hypot`](https://en.cppreference.com/w/cpp/numeric/math/hypot)
9
9
  - [`ldexp`](https://en.cppreference.com/w/c/numeric/math/ldexp)
10
+ - [`nan](https://en.cppreference.com/w/c/numeric/math/nan)
10
11
  - [`nextafter`](https://en.cppreference.com/w/c/numeric/math/nextafter)
11
12
  - [`pow`](https://en.cppreference.com/w/c/numeric/math/pow)
12
13
 
@@ -17,6 +18,7 @@ These functions accept either a `bigint` or an integer `number`:
17
18
  - [`countl_zero`](https://en.cppreference.com/w/cpp/numeric/countl_zero)
18
19
  - [`countr_one`](https://en.cppreference.com/w/cpp/numeric/countr_one)
19
20
  - [`countr_zero`](https://en.cppreference.com/w/cpp/numeric/countr_zero)
21
+ - [`div`](https://en.cppreference.com/w/cpp/numeric/math/div)
20
22
  - [`gcd`](https://en.cppreference.com/w/cpp/numeric/gcd)
21
23
  - [`lcm`](https://en.cppreference.com/w/cpp/numeric/lcm)
22
24
  - [`popcount`](https://en.cppreference.com/w/cpp/numeric/popcount)
@@ -25,6 +27,9 @@ These functions accept either a `bigint` or an integer `number`:
25
27
  - [`iota`](https://en.cppreference.com/w/cpp/algorithm/iota)
26
28
  - [`signbit`](https://en.cppreference.com/w/c/numeric/math/signbit)
27
29
 
30
+ ## Mathematical constants
31
+ - Constants in [the `std::numbers` namespace](https://en.cppreference.com/w/cpp/numeric/constants)
32
+
28
33
  ## Test coverage
29
34
  The test coverage is a perfect 100% and enforced by the publishing and pull request verification workflows.
30
35
 
@@ -1 +1,2 @@
1
+ export { iota } from "./iota.js";
1
2
  export { signbit } from "./signbit.js";
@@ -1,2 +1,3 @@
1
+ export { iota } from "./iota.js";
1
2
  export { signbit } from "./signbit.js";
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/all-numbers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/all-numbers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
@@ -1,4 +1,5 @@
1
+ import { floatOctets } from "../internal/floatOctets.js";
1
2
  export function signbit(num) {
2
- return Object.is(num, -0) || num < 0;
3
+ return floatOctets(Number(num))[7] > 127;
3
4
  }
4
5
  //# sourceMappingURL=signbit.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"signbit.js","sourceRoot":"","sources":["../../src/all-numbers/signbit.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,OAAO,CAAC,GAAoB;IAC3C,OAAO,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC;AACtC,CAAC"}
1
+ {"version":3,"file":"signbit.js","sourceRoot":"","sources":["../../src/all-numbers/signbit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAGzD,MAAM,UAAU,OAAO,CAAC,GAAoB;IAC3C,OAAO,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;AAC1C,CAAC"}
@@ -1,4 +1,5 @@
1
+ import { signbit } from "../all-numbers";
1
2
  export function copysign(num, sign) {
2
- return Math.abs(num) * (Object.is(0 * Math.sign(sign), -0) ? -1 : 1);
3
+ return signbit(num) === signbit(sign) ? num : -num;
3
4
  }
4
5
  //# sourceMappingURL=copysign.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"copysign.js","sourceRoot":"","sources":["../../src/doubles/copysign.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,QAAQ,CAAY,GAAW,EAAa,IAAY;IACvE,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtE,CAAC"}
1
+ {"version":3,"file":"copysign.js","sourceRoot":"","sources":["../../src/doubles/copysign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAOzC,MAAM,UAAU,QAAQ,CAAY,GAAW,EAAa,IAAY;IACvE,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AACpD,CAAC"}
@@ -1,3 +1,4 @@
1
+ export * as numbers from "./numbers.js";
1
2
  export { copysign } from "./copysign.js";
2
3
  export { fabs } from "./fabs.js";
3
4
  export { frexp } from "./frexp.js";
@@ -1,3 +1,4 @@
1
+ export * as numbers from "./numbers.js";
1
2
  export { copysign } from "./copysign.js";
2
3
  export { fabs } from "./fabs.js";
3
4
  export { frexp } from "./frexp.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/doubles/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/doubles/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function nan(arg: string): number;
@@ -0,0 +1,10 @@
1
+ import { floatFromBits } from "../internal/floatFromBits.js";
2
+ export function nan(arg) {
3
+ let bits = 0n;
4
+ const isIntegerString = /^(0|[1-9]\d*|0x[0-9a-zA-Z]+)$/.test(arg);
5
+ if (isIntegerString) {
6
+ bits = BigInt.asUintN(51, BigInt(arg));
7
+ }
8
+ return floatFromBits(9221120237041090560n | bits);
9
+ }
10
+ //# sourceMappingURL=nan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nan.js","sourceRoot":"","sources":["../../src/doubles/nan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAe7D,MAAM,UAAU,GAAG,CAAC,GAAW;IAC9B,IAAI,IAAI,GAAG,EAAE,CAAC;IAKd,MAAM,eAAe,GAAG,+BAA+B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAElE,IAAI,eAAe,EAAE,CAAC;QACrB,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,aAAa,CASnB,oBAAkF,GAAG,IAAI,CACzF,CAAC;AACH,CAAC"}
@@ -0,0 +1,13 @@
1
+ export declare const e: number;
2
+ export declare const egamma = 0.5772156649015329;
3
+ export declare const inv_pi = 0.3183098861837907;
4
+ export declare const inv_sqrt3 = 0.5773502691896257;
5
+ export declare const inv_sqrtpi = 0.5641895835477563;
6
+ export declare const ln10: number;
7
+ export declare const ln2: number;
8
+ export declare const log10: number;
9
+ export declare const log2e: number;
10
+ export declare const phi = 1.618033988749895;
11
+ export declare const pi: number;
12
+ export declare const sqrt2: number;
13
+ export declare const sqrt3 = 1.7320508075688772;
@@ -0,0 +1,14 @@
1
+ export const e = Math.E;
2
+ export const egamma = 0.5772156649015329;
3
+ export const inv_pi = 0.3183098861837907;
4
+ export const inv_sqrt3 = 0.5773502691896257;
5
+ export const inv_sqrtpi = 0.5641895835477563;
6
+ export const ln10 = Math.LN10;
7
+ export const ln2 = Math.LN2;
8
+ export const log10 = Math.LOG10E;
9
+ export const log2e = Math.LOG2E;
10
+ export const phi = 1.618033988749895;
11
+ export const pi = Math.PI;
12
+ export const sqrt2 = Math.SQRT2;
13
+ export const sqrt3 = 1.7320508075688772;
14
+ //# sourceMappingURL=numbers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numbers.js","sourceRoot":"","sources":["../../src/doubles/numbers.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;AACxB,MAAM,CAAC,MAAM,MAAM,GAAG,kBAAkB,CAAC;AACzC,MAAM,CAAC,MAAM,MAAM,GAAG,kBAAkB,CAAC;AACzC,MAAM,CAAC,MAAM,SAAS,GAAG,kBAAkB,CAAC;AAC5C,MAAM,CAAC,MAAM,UAAU,GAAG,kBAAkB,CAAC;AAC7C,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;AAC9B,MAAM,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;AAC5B,MAAM,CAAC,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;AACjC,MAAM,CAAC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;AAChC,MAAM,CAAC,MAAM,GAAG,GAAG,iBAAiB,CAAC;AACrC,MAAM,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;AAC1B,MAAM,CAAC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;AAChC,MAAM,CAAC,MAAM,KAAK,GAAG,kBAAkB,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { type div_t_bigint } from "./div_bigint";
2
+ import { type div_t_number } from "./div_number";
3
+ export { type div_t_bigint };
4
+ export { type div_t_number };
5
+ export declare function div(aInteger: bigint, bInteger: bigint): div_t_bigint;
6
+ export declare function div(aInteger: number, bInteger: number): div_t_number;
@@ -0,0 +1,8 @@
1
+ import { div_bigint } from "./div_bigint";
2
+ import { div_number } from "./div_number";
3
+ export function div(aInteger, bInteger) {
4
+ return typeof aInteger === "number"
5
+ ? div_number(aInteger, bInteger)
6
+ : div_bigint(aInteger, bInteger);
7
+ }
8
+ //# sourceMappingURL=div.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"div.js","sourceRoot":"","sources":["../../src/integers/div.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAqB,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAqB,MAAM,cAAc,CAAC;AAO7D,MAAM,UAAU,GAAG,CAClB,QAAyB,EACzB,QAAyB;IAEzB,OAAO,OAAO,QAAQ,KAAK,QAAQ;QAClC,CAAC,CAAC,UAAU,CAAC,QAAQ,EAAE,QAAkB,CAAC;QAC1C,CAAC,CAAC,UAAU,CAAC,QAAQ,EAAE,QAAkB,CAAC,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,5 @@
1
+ export interface div_t_bigint {
2
+ quot: bigint;
3
+ rem: bigint;
4
+ }
5
+ export declare function div_bigint(aInteger: bigint, bInteger: bigint): div_t_bigint;
@@ -0,0 +1,13 @@
1
+ export function div_bigint(aInteger, bInteger) {
2
+ if (bInteger === 0n) {
3
+ return {
4
+ quot: 0n,
5
+ rem: 0n,
6
+ };
7
+ }
8
+ return {
9
+ quot: aInteger / bInteger,
10
+ rem: aInteger % bInteger,
11
+ };
12
+ }
13
+ //# sourceMappingURL=div_bigint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"div_bigint.js","sourceRoot":"","sources":["../../src/integers/div_bigint.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,UAAU,CAAC,QAAgB,EAAE,QAAgB;IAG5D,IAAI,QAAQ,KAAK,EAAE,EAAE,CAAC;QACrB,OAAO;YACN,IAAI,EAAE,EAAE;YACR,GAAG,EAAE,EAAE;SACP,CAAC;IACH,CAAC;IAED,OAAO;QACN,IAAI,EAAE,QAAQ,GAAG,QAAQ;QACzB,GAAG,EAAE,QAAQ,GAAG,QAAQ;KACxB,CAAC;AACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ export interface div_t_number {
2
+ quot: number;
3
+ rem: number;
4
+ }
5
+ export declare function div_number(aInteger: number, bInteger: number): div_t_number;
@@ -0,0 +1,11 @@
1
+ export function div_number(aInteger, bInteger) {
2
+ let quot = Math.trunc(aInteger / bInteger) || 0;
3
+ if (!Number.isFinite(quot)) {
4
+ quot = 0;
5
+ }
6
+ return {
7
+ quot,
8
+ rem: aInteger % bInteger || 0,
9
+ };
10
+ }
11
+ //# sourceMappingURL=div_number.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"div_number.js","sourceRoot":"","sources":["../../src/integers/div_number.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,UAAU,CAAC,QAAgB,EAAE,QAAgB;IAM5D,IAAI,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAChD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5B,IAAI,GAAG,CAAC,CAAC;IACV,CAAC;IAED,OAAO;QACN,IAAI;QACJ,GAAG,EAAE,QAAQ,GAAG,QAAQ,IAAI,CAAC;KAC7B,CAAC;AACH,CAAC"}
@@ -3,6 +3,7 @@ export { countl_one } from "./countl_one.js";
3
3
  export { countl_zero } from "./countl_zero.js";
4
4
  export { countr_one } from "./countr_one.js";
5
5
  export { countr_zero } from "./countr_zero.js";
6
+ export { div, type div_t_bigint, type div_t_number } from "./div.js";
6
7
  export { gcd } from "./gcd.js";
7
8
  export { lcm } from "./lcm.js";
8
9
  export { popcount } from "./popcount.js";
@@ -3,6 +3,7 @@ export { countl_one } from "./countl_one.js";
3
3
  export { countl_zero } from "./countl_zero.js";
4
4
  export { countr_one } from "./countr_one.js";
5
5
  export { countr_zero } from "./countr_zero.js";
6
+ export { div } from "./div.js";
6
7
  export { gcd } from "./gcd.js";
7
8
  export { lcm } from "./lcm.js";
8
9
  export { popcount } from "./popcount.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/integers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/integers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,GAAG,EAAwC,MAAM,UAAU,CAAC;AACrE,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function floatFromBits(bits64: bigint): number;
@@ -0,0 +1,8 @@
1
+ const floatArray = new Float64Array(1);
2
+ const asUint32s = new Uint32Array(floatArray.buffer);
3
+ export function floatFromBits(bits64) {
4
+ asUint32s[0] = Number(BigInt.asUintN(32, bits64));
5
+ asUint32s[1] = Number(BigInt.asUintN(32, bits64 >> 32n));
6
+ return floatArray[0];
7
+ }
8
+ //# sourceMappingURL=floatFromBits.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"floatFromBits.js","sourceRoot":"","sources":["../../src/internal/floatFromBits.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,GAAG,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC;AACvC,MAAM,SAAS,GAAG,IAAI,WAAW,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AAErD,MAAM,UAAU,aAAa,CAAC,MAAc;IAC3C,SAAS,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;IAClD,SAAS,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC;IAEzD,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC;AACtB,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function floatOctets(num: number): Readonly<Uint8Array>;
@@ -0,0 +1,7 @@
1
+ const floatArray = new Float64Array(1);
2
+ const octets = new Uint8Array(floatArray.buffer);
3
+ export function floatOctets(num) {
4
+ floatArray[0] = num;
5
+ return octets;
6
+ }
7
+ //# sourceMappingURL=floatOctets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"floatOctets.js","sourceRoot":"","sources":["../../src/internal/floatOctets.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,GAAG,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC;AACvC,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AAIjD,MAAM,UAAU,WAAW,CAAC,GAAW;IACtC,UAAU,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;IACpB,OAAO,MAAM,CAAC;AACf,CAAC"}
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/oskarlh/cmath-js.git"
7
7
  },
8
- "version": "1.2.1",
8
+ "version": "1.4.0",
9
9
  "exports": "./dist/index.js",
10
10
  "types": "./dist/index.d.ts",
11
11
  "type": "module",