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 +5 -0
- package/dist/all-numbers/index.d.ts +1 -0
- package/dist/all-numbers/index.js +1 -0
- package/dist/all-numbers/index.js.map +1 -1
- package/dist/all-numbers/signbit.js +2 -1
- package/dist/all-numbers/signbit.js.map +1 -1
- package/dist/doubles/copysign.js +2 -1
- package/dist/doubles/copysign.js.map +1 -1
- package/dist/doubles/index.d.ts +1 -0
- package/dist/doubles/index.js +1 -0
- package/dist/doubles/index.js.map +1 -1
- package/dist/doubles/nan.d.ts +1 -0
- package/dist/doubles/nan.js +10 -0
- package/dist/doubles/nan.js.map +1 -0
- package/dist/doubles/numbers.d.ts +13 -0
- package/dist/doubles/numbers.js +14 -0
- package/dist/doubles/numbers.js.map +1 -0
- package/dist/integers/div.d.ts +6 -0
- package/dist/integers/div.js +8 -0
- package/dist/integers/div.js.map +1 -0
- package/dist/integers/div_bigint.d.ts +5 -0
- package/dist/integers/div_bigint.js +13 -0
- package/dist/integers/div_bigint.js.map +1 -0
- package/dist/integers/div_number.d.ts +5 -0
- package/dist/integers/div_number.js +11 -0
- package/dist/integers/div_number.js.map +1 -0
- package/dist/integers/index.d.ts +1 -0
- package/dist/integers/index.js +1 -0
- package/dist/integers/index.js.map +1 -1
- package/dist/internal/floatFromBits.d.ts +1 -0
- package/dist/internal/floatFromBits.js +8 -0
- package/dist/internal/floatFromBits.js.map +1 -0
- package/dist/internal/floatOctets.d.ts +1 -0
- package/dist/internal/floatOctets.js +7 -0
- package/dist/internal/floatOctets.js.map +1 -0
- package/package.json +1 -1
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 @@
|
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signbit.js","sourceRoot":"","sources":["../../src/all-numbers/signbit.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/doubles/copysign.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copysign.js","sourceRoot":"","sources":["../../src/doubles/copysign.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/doubles/index.d.ts
CHANGED
package/dist/doubles/index.js
CHANGED
|
@@ -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 @@
|
|
|
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 @@
|
|
|
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"}
|
package/dist/integers/index.d.ts
CHANGED
|
@@ -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";
|
package/dist/integers/index.js
CHANGED
|
@@ -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 @@
|
|
|
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"}
|