cmath-js 1.0.14 → 1.0.16

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.
@@ -0,0 +1 @@
1
+ export declare function copysign(num: number, sign: number): number;
@@ -0,0 +1,4 @@
1
+ export function copysign(num, sign) {
2
+ return Math.abs(num) * (Object.is(0 * Math.sign(sign), -0) ? -1 : 1);
3
+ }
4
+ //# sourceMappingURL=copysign.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copysign.js","sourceRoot":"","sources":["../../src/double/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"}
@@ -0,0 +1 @@
1
+ export declare const fabs: (x: number) => number;
@@ -0,0 +1,2 @@
1
+ export const fabs = Math.abs;
2
+ //# sourceMappingURL=fabs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fabs.js","sourceRoot":"","sources":["../../src/double/fabs.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function frexp(num: number): [fraction: number, exponent: number];
@@ -0,0 +1,21 @@
1
+ export function frexp(num) {
2
+ if (num === 0 || !Number.isFinite(num)) {
3
+ return [num, 0];
4
+ }
5
+ const absNum = Math.abs(num);
6
+ let exp = Math.max(-1023, Math.floor(Math.log2(absNum)) + 1);
7
+ let x = absNum * 2 ** -exp;
8
+ while (x < 0.5) {
9
+ x *= 2;
10
+ --exp;
11
+ }
12
+ while (x >= 1) {
13
+ x *= 0.5;
14
+ ++exp;
15
+ }
16
+ if (num < 0) {
17
+ x = -x;
18
+ }
19
+ return [x, exp];
20
+ }
21
+ //# sourceMappingURL=frexp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frexp.js","sourceRoot":"","sources":["../../src/double/frexp.ts"],"names":[],"mappings":"AAQA,MAAM,UAAU,KAAK,CACT,GAAW;IAEtB,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QACvC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;KAChB;IAED,MAAM,MAAM,GAAW,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAErC,IAAI,GAAG,GAAW,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACrE,IAAI,CAAC,GAAW,MAAM,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC;IAInC,OAAO,CAAC,GAAG,GAAG,EAAE;QACf,CAAC,IAAI,CAAC,CAAC;QACP,EAAE,GAAG,CAAC;KACN;IAGD,OAAO,CAAC,IAAI,CAAC,EAAE;QACd,CAAC,IAAI,GAAG,CAAC;QACT,EAAE,GAAG,CAAC;KACN;IAED,IAAI,GAAG,GAAG,CAAC,EAAE;QACZ,CAAC,GAAG,CAAC,CAAC,CAAC;KACP;IAED,OAAO,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AACjB,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function hypot(x: number, y: number, z?: number): number;
@@ -0,0 +1,13 @@
1
+ export function hypot(x, y, z) {
2
+ if (z !== undefined) {
3
+ return Math.hypot(x, y, z);
4
+ }
5
+ if (x !== Infinity && x !== -Infinity && y !== Infinity && y !== -Infinity) {
6
+ if (x === 0 || y === 0) {
7
+ return Math.max(Math.abs(x), Math.abs(y));
8
+ }
9
+ return Math.hypot(x, y);
10
+ }
11
+ return Infinity;
12
+ }
13
+ //# sourceMappingURL=hypot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hypot.js","sourceRoot":"","sources":["../../src/double/hypot.ts"],"names":[],"mappings":"AASA,MAAM,UAAU,KAAK,CAAY,CAAS,EAAa,CAAS,EAAa,CAAU;IACtF,IAAI,CAAC,KAAK,SAAS,EAAE;QAEpB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;KAC3B;IACD,IAAI,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;QAC3E,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YACvB,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;SAC1C;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;KACxB;IACD,OAAO,QAAQ,CAAC;AACjB,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { copysign } from "./copysign.js";
2
+ export { fabs } from "./fabs.js";
3
+ export { frexp } from "./frexp.js";
4
+ export { hypot } from "./hypot.js";
5
+ export { ldexp } from "./ldexp.js";
6
+ export { nextafter } from "./nextafter.js";
7
+ export { pow } from "./pow.js";
8
+ export { signbit } from "./signbit.js";
@@ -0,0 +1,9 @@
1
+ export { copysign } from "./copysign.js";
2
+ export { fabs } from "./fabs.js";
3
+ export { frexp } from "./frexp.js";
4
+ export { hypot } from "./hypot.js";
5
+ export { ldexp } from "./ldexp.js";
6
+ export { nextafter } from "./nextafter.js";
7
+ export { pow } from "./pow.js";
8
+ export { signbit } from "./signbit.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/double/index.ts"],"names":[],"mappings":"AAEA,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;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function ldexp(factor: number, exponent: number): number;
@@ -0,0 +1,5 @@
1
+ export function ldexp(factor, exponent) {
2
+ const halfPowerRoundedTowardZero = 2 ** Math.trunc(exponent * 0.5);
3
+ return (factor * halfPowerRoundedTowardZero * halfPowerRoundedTowardZero * 2 ** Math.sign(exponent % 2));
4
+ }
5
+ //# sourceMappingURL=ldexp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ldexp.js","sourceRoot":"","sources":["../../src/double/ldexp.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,KAAK,CAAY,MAAc,EAAU,QAAgB;IACxE,MAAM,0BAA0B,GAAW,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,GAAG,CAAC,CAAC;IAC3E,OAAO,CACN,MAAM,GAAG,0BAA0B,GAAG,0BAA0B,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,CAC/F,CAAC;AACH,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function nextafter(num: number, toward: number): number;
@@ -0,0 +1,22 @@
1
+ export function nextafter(num, toward) {
2
+ if (num === toward) {
3
+ return toward;
4
+ }
5
+ if (num === 0) {
6
+ return Math.sign(toward) * Number.MIN_VALUE;
7
+ }
8
+ if (num === Infinity || num === -Infinity) {
9
+ return Number.MAX_VALUE * Math.sign(num);
10
+ }
11
+ if (num === -Number.MIN_VALUE && toward > num) {
12
+ return -0;
13
+ }
14
+ let differenceMultiplier = 0.5 * Math.sign(num) * (num < toward ? 1 : -1);
15
+ let result;
16
+ do {
17
+ result = num + num * (Number.EPSILON * differenceMultiplier);
18
+ differenceMultiplier *= 2;
19
+ } while (result === num);
20
+ return result;
21
+ }
22
+ //# sourceMappingURL=nextafter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nextafter.js","sourceRoot":"","sources":["../../src/double/nextafter.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,SAAS,CAAY,GAAW,EAAa,MAAc;IAC1E,IAAI,GAAG,KAAK,MAAM,EAAE;QACnB,OAAO,MAAM,CAAC;KACd;IACD,IAAI,GAAG,KAAK,CAAC,EAAE;QACd,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC;KAC5C;IACD,IAAI,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,CAAC,QAAQ,EAAE;QAC1C,OAAO,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KACzC;IACD,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,SAAS,IAAI,MAAM,GAAG,GAAG,EAAE;QAC9C,OAAO,CAAC,CAAC,CAAC;KACV;IACD,IAAI,oBAAoB,GAAG,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1E,IAAI,MAAc,CAAC;IACnB,GAAG;QACF,MAAM,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,OAAO,GAAG,oBAAoB,CAAC,CAAC;QAC7D,oBAAoB,IAAI,CAAC,CAAC;KAC1B,QAAQ,MAAM,KAAK,GAAG,EAAE;IACzB,OAAO,MAAM,CAAC;AACf,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function pow(base: number, exponent: number): number;
@@ -0,0 +1,8 @@
1
+ export function pow(base, exponent) {
2
+ let result = base ** exponent;
3
+ if (base === 1 || (base === -1 && (exponent === Infinity || exponent === -Infinity))) {
4
+ result = 1;
5
+ }
6
+ return result;
7
+ }
8
+ //# sourceMappingURL=pow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pow.js","sourceRoot":"","sources":["../../src/double/pow.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,GAAG,CAAY,IAAY,EAAa,QAAgB;IACvE,IAAI,MAAM,GAAG,IAAI,IAAI,QAAQ,CAAC;IAC9B,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,CAAC,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE;QACrF,MAAM,GAAG,CAAC,CAAC;KACX;IACD,OAAO,MAAM,CAAC;AACf,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function signbit(num: number): boolean;
@@ -0,0 +1,4 @@
1
+ export function signbit(num) {
2
+ return Object.is(num, -0) || num < 0;
3
+ }
4
+ //# sourceMappingURL=signbit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signbit.js","sourceRoot":"","sources":["../../src/double/signbit.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,OAAO,CAAY,GAAW;IAC7C,OAAO,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC;AACtC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./double/index.js";
2
+ export * from "./integer/index.js";
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./double/index.js";
2
+ export * from "./integer/index.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function abs(number: bigint | number): number | bigint;
@@ -0,0 +1,7 @@
1
+ export function abs(number) {
2
+ if (number < 0 || Object.is(number, -0)) {
3
+ return -number;
4
+ }
5
+ return number;
6
+ }
7
+ //# sourceMappingURL=abs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abs.js","sourceRoot":"","sources":["../../src/integer/abs.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,GAAG,CAAC,MAAuB;IAC1C,IAAI,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE;QACxC,OAAO,CAAC,MAAM,CAAC;KACf;IACD,OAAO,MAAM,CAAC;AACf,CAAC"}
@@ -0,0 +1 @@
1
+ export { abs } from "./abs.js";
@@ -0,0 +1,2 @@
1
+ export { abs } from "./abs.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/integer/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC"}
package/package.json CHANGED
@@ -5,9 +5,9 @@
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/oskarlh/cmath-js.git"
7
7
  },
8
- "version": "1.0.14",
9
- "main": "dist/index.js",
10
- "types": "dist/index.d.ts",
8
+ "version": "1.0.16",
9
+ "exports": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
11
  "type": "module",
12
12
  "author": "Oskar Larsson Högfeldt <oskar@oskar.pm>",
13
13
  "contributors": [
@@ -20,6 +20,7 @@
20
20
  "C++",
21
21
  "cmath",
22
22
  "ECMAScript",
23
+ "frexp",
23
24
  "JavaScript",
24
25
  "Math",
25
26
  "Maths",
@@ -45,13 +46,13 @@
45
46
  },
46
47
  "scripts": {
47
48
  "build": "tsc",
48
- "build-and-verify": "npm run test-with-typechecking --ci && npm run lint && npm run build",
49
- "build-without-typechecking": "swc -C exclude=.test.ts -d dist -s true -- src",
50
49
  "lint": "eslint .",
51
50
  "lint-fix": "eslint . --fix",
52
51
  "prepack": "npm run build",
53
52
  "test": "jest",
54
- "test-with-typechecking": "jest --config=jest.config.with-typechecking.js"
53
+ "test-with-typechecking": "jest --config=jest.config.with-typechecking.js",
54
+ "typecheck": "tsc --noEmit",
55
+ "verify": "npm run test-with-typechecking --ci && npm run lint && npm run typecheck"
55
56
  },
56
57
  "files": [
57
58
  "dist"