cmath-js 1.0.4 → 1.0.5
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/package.json +6 -2
- package/.dockerignore +0 -10
- package/.editorconfig +0 -7
- package/.env +0 -4
- package/.eslintignore +0 -2
- package/.eslintrc.json +0 -36
- package/.gitattributes +0 -1
- package/.github/workflows/github-actions-verify.yml +0 -22
- package/.nvmrc +0 -1
- package/.prettierrc +0 -10
- package/.vscode/extensions.json +0 -7
- package/.vscode/launch.json +0 -37
- package/.vscode/settings.json +0 -14
- package/Dockerfile +0 -11
- package/docker-compose.ci-verifier.yml +0 -6
- package/jest.config.js +0 -12
- package/jest.config.with-typechecking.js +0 -9
- package/src/double/copysign.test.ts +0 -9
- package/src/double/copysign.ts +0 -8
- package/src/double/fabs.test.ts +0 -14
- package/src/double/fabs.ts +0 -3
- package/src/double/frexp.test.ts +0 -15
- package/src/double/frexp.ts +0 -40
- package/src/double/hypot.test.ts +0 -11
- package/src/double/hypot.ts +0 -25
- package/src/double/index.ts +0 -8
- package/src/double/ldexp.test.ts +0 -16
- package/src/double/ldexp.ts +0 -11
- package/src/double/nextafter.test.ts +0 -29
- package/src/double/nextafter.ts +0 -22
- package/src/double/pow.test.ts +0 -27
- package/src/double/pow.ts +0 -8
- package/src/double/signbit.test.ts +0 -13
- package/src/double/signbit.ts +0 -4
- package/src/index.ts +0 -11
- package/src/integer/abs.test.ts +0 -28
- package/src/integer/abs.ts +0 -8
- package/src/integer/index.ts +0 -1
- package/suppressExperimentalWarnings.cjs +0 -11
- package/tsconfig.json +0 -102
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "cmath-js",
|
|
3
3
|
"homepage": "https://github.com/oskarlh/cmath.js",
|
|
4
4
|
"repository": "github:oskarlh/cmath.js",
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.5",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"type": "module",
|
|
@@ -46,5 +46,9 @@
|
|
|
46
46
|
"lint": "eslint .",
|
|
47
47
|
"test": "jest",
|
|
48
48
|
"test-with-typechecking": "jest --config=jest.config.with-typechecking.js"
|
|
49
|
-
}
|
|
49
|
+
},
|
|
50
|
+
"files": [
|
|
51
|
+
"dist",
|
|
52
|
+
"README.md"
|
|
53
|
+
]
|
|
50
54
|
}
|
package/.dockerignore
DELETED
package/.editorconfig
DELETED
package/.env
DELETED
package/.eslintignore
DELETED
package/.eslintrc.json
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"root": true,
|
|
3
|
-
"parser": "@typescript-eslint/parser",
|
|
4
|
-
"plugins": ["@typescript-eslint", "prettier"],
|
|
5
|
-
"extends": [
|
|
6
|
-
"eslint:recommended",
|
|
7
|
-
"plugin:@typescript-eslint/eslint-recommended",
|
|
8
|
-
"plugin:@typescript-eslint/recommended",
|
|
9
|
-
"prettier"
|
|
10
|
-
],
|
|
11
|
-
"env": {
|
|
12
|
-
"node": true
|
|
13
|
-
},
|
|
14
|
-
"rules": {
|
|
15
|
-
"@typescript-eslint/ban-ts-comment": "off",
|
|
16
|
-
"@typescript-eslint/no-empty-function": "off",
|
|
17
|
-
"@typescript-eslint/no-explicit-any": "off",
|
|
18
|
-
"@typescript-eslint/no-unused-vars": "off",
|
|
19
|
-
"curly": ["warn", "multi-line"],
|
|
20
|
-
"no-else-return": ["warn", { "allowElseIf": true }],
|
|
21
|
-
"no-param-reassign": [
|
|
22
|
-
"error",
|
|
23
|
-
{
|
|
24
|
-
"props": true
|
|
25
|
-
}
|
|
26
|
-
],
|
|
27
|
-
"prefer-const": ["warn", { "destructuring": "all" }],
|
|
28
|
-
"prettier/prettier": "warn",
|
|
29
|
-
"sort-keys": [
|
|
30
|
-
"warn",
|
|
31
|
-
"asc",
|
|
32
|
-
{ "allowLineSeparatedGroups": true, "minKeys": 2, "natural": true }
|
|
33
|
-
],
|
|
34
|
-
"sort-vars": "warn"
|
|
35
|
-
}
|
|
36
|
-
}
|
package/.gitattributes
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
* text=auto eol=lf
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
name: Test, lint, verify modules
|
|
2
|
-
on: [ "pull_request", "push" ]
|
|
3
|
-
jobs:
|
|
4
|
-
verify:
|
|
5
|
-
runs-on: ubuntu-latest
|
|
6
|
-
env:
|
|
7
|
-
COMPOSE_FILE: docker-compose.ci-verifier.yml
|
|
8
|
-
steps:
|
|
9
|
-
- name: Code checkout
|
|
10
|
-
uses: actions/checkout@v3
|
|
11
|
-
|
|
12
|
-
- name: DockerHub Login
|
|
13
|
-
uses: docker/login-action@v2.1.0
|
|
14
|
-
with:
|
|
15
|
-
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
|
|
16
|
-
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
17
|
-
|
|
18
|
-
- name: Build image with tests
|
|
19
|
-
run: docker compose -f $COMPOSE_FILE build
|
|
20
|
-
|
|
21
|
-
- name: Run tests, run linter, verify Node modules
|
|
22
|
-
run: docker compose -f $COMPOSE_FILE run ci-verifier
|
package/.nvmrc
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
20
|
package/.prettierrc
DELETED
package/.vscode/extensions.json
DELETED
package/.vscode/launch.json
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": "0.2.0",
|
|
3
|
-
"configurations": [
|
|
4
|
-
{
|
|
5
|
-
"internalConsoleOptions": "openOnSessionStart",
|
|
6
|
-
"name": "Watch, build (without typechecking) & run",
|
|
7
|
-
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
|
|
8
|
-
"request": "launch",
|
|
9
|
-
"restart": true,
|
|
10
|
-
"runtimeArgs": ["run", "watch"],
|
|
11
|
-
"runtimeExecutable": "npm",
|
|
12
|
-
"skipFiles": ["<node_internals>/**", "node_modules/**"],
|
|
13
|
-
"type": "node",
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"internalConsoleOptions": "openOnSessionStart",
|
|
17
|
-
"name": "Build (with typechecking) & run",
|
|
18
|
-
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
|
|
19
|
-
"preLaunchTask": "npm: build",
|
|
20
|
-
"request": "launch",
|
|
21
|
-
"runtimeArgs": ["run", "start-debug"],
|
|
22
|
-
"runtimeExecutable": "npm",
|
|
23
|
-
"skipFiles": ["<node_internals>/**", "node_modules/**"],
|
|
24
|
-
"type": "node"
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
"internalConsoleOptions": "openOnSessionStart",
|
|
28
|
-
"name": "Build (with typechecking)",
|
|
29
|
-
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
|
|
30
|
-
"request": "launch",
|
|
31
|
-
"runtimeArgs": ["run", "build"],
|
|
32
|
-
"runtimeExecutable": "npm",
|
|
33
|
-
"skipFiles": ["<node_internals>/**", "node_modules/**"],
|
|
34
|
-
"type": "node"
|
|
35
|
-
}
|
|
36
|
-
]
|
|
37
|
-
}
|
package/.vscode/settings.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
|
|
3
|
-
"eslint.format.enable": true,
|
|
4
|
-
"editor.formatOnSave": true,
|
|
5
|
-
"editor.formatOnPaste": true,
|
|
6
|
-
"editor.formatOnType": true,
|
|
7
|
-
"search.exclude": {
|
|
8
|
-
"**/node_module": true,
|
|
9
|
-
},
|
|
10
|
-
"editor.insertSpaces": false,
|
|
11
|
-
"eslint.rules.customizations": [
|
|
12
|
-
{ "rule": "prettier/prettier", "severity": "off" }
|
|
13
|
-
]
|
|
14
|
-
}
|
package/Dockerfile
DELETED
package/jest.config.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
2
|
-
export default {
|
|
3
|
-
moduleNameMapper: {
|
|
4
|
-
"^(\\.{1,2}/.*)\\.js$": "$1",
|
|
5
|
-
},
|
|
6
|
-
rootDir: "./src",
|
|
7
|
-
testEnvironment: "node",
|
|
8
|
-
testRegex: "\\.test\\.ts$",
|
|
9
|
-
transform: {
|
|
10
|
-
"^.+\\.ts$": ["@swc/jest"],
|
|
11
|
-
},
|
|
12
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { copysign } from "./copysign.js";
|
|
2
|
-
|
|
3
|
-
describe("copysign", () => {
|
|
4
|
-
it("return a number with the sign from another number", () => {
|
|
5
|
-
expect(copysign(8, -4)).toBe(-8);
|
|
6
|
-
expect(copysign(-8, -0.00000000000000000000001)).toBe(-8);
|
|
7
|
-
expect(copysign(-Infinity, 0.00000000000000000000001)).toBe(Infinity);
|
|
8
|
-
});
|
|
9
|
-
});
|
package/src/double/copysign.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// copysign produces a value with the magnitude of 'num' and the sign 'sign'
|
|
2
|
-
// Note: ECMAScript does not have negative NaNs
|
|
3
|
-
// C spec: https://web.archive.org/web/20181230041359if_/http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf#subsection.7.12.11
|
|
4
|
-
// Cppreference: https://en.cppreference.com/w/c/numeric/math/copysign
|
|
5
|
-
// The implementation is complicated by the need to handle positive and negative zero
|
|
6
|
-
export function copysign(/*double*/ num: number, /*double*/ sign: number): /*double*/ number {
|
|
7
|
-
return Math.abs(num) * (Object.is(0 * Math.sign(sign), -0) ? -1 : 1);
|
|
8
|
-
}
|
package/src/double/fabs.test.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { fabs } from "./fabs.js";
|
|
2
|
-
|
|
3
|
-
describe("fabs", () => {
|
|
4
|
-
it("returns the absolute value of a floating-point number", () => {
|
|
5
|
-
expect(fabs(123084109743)).toBe(123084109743);
|
|
6
|
-
expect(fabs(-123.4)).toBe(123.4);
|
|
7
|
-
expect(fabs(0)).toBe(0);
|
|
8
|
-
expect(fabs(12523423523523532)).toBe(12523423523523532);
|
|
9
|
-
expect(fabs(-5252342352352353000000000000)).toBe(5252342352352353000000000000);
|
|
10
|
-
expect(fabs(-0)).toBe(0);
|
|
11
|
-
expect(fabs(-Infinity)).toBe(Infinity);
|
|
12
|
-
expect(fabs(NaN)).toBe(NaN);
|
|
13
|
-
});
|
|
14
|
-
});
|
package/src/double/fabs.ts
DELETED
package/src/double/frexp.test.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { frexp } from "./frexp.js";
|
|
2
|
-
|
|
3
|
-
describe("frexp", () => {
|
|
4
|
-
it("decomposes a number into a normalized fraction and an integral power of two", () => {
|
|
5
|
-
expect(frexp(1)).toStrictEqual([0.5, 1]);
|
|
6
|
-
expect(frexp(1.5)).toStrictEqual([0.75, 1]);
|
|
7
|
-
expect(frexp(3 * 2 ** 500)).toStrictEqual([0.75, 502]);
|
|
8
|
-
expect(frexp(-4)).toStrictEqual([-0.5, 3]);
|
|
9
|
-
expect(frexp(Number.MAX_VALUE)).toStrictEqual([0.9999999999999999, 1024]);
|
|
10
|
-
expect(frexp(Number.MIN_VALUE)).toStrictEqual([0.5, -1073]);
|
|
11
|
-
expect(frexp(-Infinity)).toStrictEqual([-Infinity, 0]);
|
|
12
|
-
expect(frexp(-0)).toStrictEqual([-0, 0]);
|
|
13
|
-
expect(frexp(NaN)).toStrictEqual([NaN, 0]);
|
|
14
|
-
});
|
|
15
|
-
});
|
package/src/double/frexp.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// Note: Instead of "double frexp(double arg, int* exp)" this is built as "[double, int] frexp(double arg)" due to ECMAScripts's lack of pointers
|
|
2
|
-
// A hypothetical issue with this implementation is that the precision the ** operator is not defined in the ECMAScript standard,
|
|
3
|
-
// however, sane ECMAScript implementations should give precise results for 2**<integer> expressions
|
|
4
|
-
// Cppreference: http://en.cppreference.com/w/c/numeric/math/frexp for a more detailed description
|
|
5
|
-
// Object.is(n, frexp(n)[0] * 2 ** frexp(n)[1]) for all number values of n except when Math.isFinite(n) && Math.abs(n) > 2**1023
|
|
6
|
-
// Object.is(n, (2 * frexp(n)[0]) * 2 ** (frexp(n)[1] - 1)) for all number values of n
|
|
7
|
-
// Object.is(n, frexp(n)[0]) for these values of n: 0, -0, NaN, Infinity, -Infinity
|
|
8
|
-
// Math.abs(frexp(n)[0]) is >= 0.5 and < 1.0 for any other number-type value of n
|
|
9
|
-
export function frexp(
|
|
10
|
-
/*double*/ num: number,
|
|
11
|
-
): [/*double*/ fraction: number, /*int*/ exponent: number] {
|
|
12
|
-
const result: [number, number] = [num, 0];
|
|
13
|
-
|
|
14
|
-
if (num !== 0 && Number.isFinite(num)) {
|
|
15
|
-
const absNum: number = Math.abs(num);
|
|
16
|
-
|
|
17
|
-
let exp: number = Math.max(-1023, Math.floor(Math.log2(absNum)) + 1);
|
|
18
|
-
let x: number = absNum * 2 ** -exp;
|
|
19
|
-
|
|
20
|
-
// These while loops compensate for rounding errors that may occur because of ECMAScript's Math.log2's undefined precision
|
|
21
|
-
// and the first one also helps work around the issue of 2 ** -exp === Infinity when exp <= -1024
|
|
22
|
-
while (x < 0.5) {
|
|
23
|
-
x *= 2;
|
|
24
|
-
--exp;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// istanbul ignore next This might not run and that's okay. See the above comment
|
|
28
|
-
while (x >= 1) {
|
|
29
|
-
x *= 0.5;
|
|
30
|
-
++exp;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (num < 0) {
|
|
34
|
-
x = -x;
|
|
35
|
-
}
|
|
36
|
-
result[0] = x;
|
|
37
|
-
result[1] = exp;
|
|
38
|
-
}
|
|
39
|
-
return result;
|
|
40
|
-
}
|
package/src/double/hypot.test.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { hypot } from "./hypot.js";
|
|
2
|
-
|
|
3
|
-
describe("hypot", () => {
|
|
4
|
-
it("computes the square root of the sum of the squares of x and y, without undue overflow or underflow", () => {
|
|
5
|
-
expect(hypot(105, 100)).toBeCloseTo(145, 3);
|
|
6
|
-
expect(hypot(-Infinity, 0)).toBe(Infinity);
|
|
7
|
-
expect(hypot(0, -0.1451493619437592)).toBe(0.1451493619437592);
|
|
8
|
-
expect(hypot(0, 0, -0.1451493619437592)).toBe(0.1451493619437592);
|
|
9
|
-
expect(hypot(-3, -2, -1)).toBeCloseTo(3.741657386773941, 3);
|
|
10
|
-
});
|
|
11
|
-
});
|
package/src/double/hypot.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// hypot computes the square root of the sum of the squares of x and y, without undue overflow or underflow
|
|
2
|
-
// This implementation allows an optional third argument, as specified in the C++ standard
|
|
3
|
-
// C spec: https://web.archive.org/web/20181230041359if_/http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf#subsection.7.12.7
|
|
4
|
-
// C spec: https://web.archive.org/web/20181230041359if_/http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf#subsection.13.10.4
|
|
5
|
-
// C++ spec for 3-arg version: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4659.pdf#subsection.29.9.3
|
|
6
|
-
// Cppreference C version (limited to 2 args): https://en.cppreference.com/w/c/numeric/math/hypot
|
|
7
|
-
// Cppreference C++ version (2 or 3 args): https://en.cppreference.com/w/cpp/numeric/math/hypot
|
|
8
|
-
// ECMAScript's Math.hypot: https://www.ecma-international.org/ecma-262/9.0/index.html#sec-math.hypot
|
|
9
|
-
// Complicated by the requirements for implementations for IEC 60559 floating-point environments, which thankfully only apply to the 2-arg (C) version
|
|
10
|
-
export function hypot(/*double*/ x: number, /*double*/ y: number, /*double*/ z?: number): number {
|
|
11
|
-
let result: number = 0;
|
|
12
|
-
if (z !== undefined) {
|
|
13
|
-
result = Math.hypot(x, y, z);
|
|
14
|
-
} else {
|
|
15
|
-
result = Infinity;
|
|
16
|
-
if (x !== Infinity && x !== -Infinity && y !== Infinity && y !== -Infinity) {
|
|
17
|
-
if (x === 0 || y === 0) {
|
|
18
|
-
result = Math.max(Math.abs(x), Math.abs(y));
|
|
19
|
-
} else {
|
|
20
|
-
result = Math.hypot(x, y);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return result;
|
|
25
|
-
}
|
package/src/double/index.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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";
|
package/src/double/ldexp.test.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ldexp } from "./ldexp";
|
|
2
|
-
|
|
3
|
-
describe("ldexp", () => {
|
|
4
|
-
it("multiplies a number by 2 raised to an exponent power", () => {
|
|
5
|
-
expect(ldexp(1.5, -1)).toBe(0.75);
|
|
6
|
-
expect(ldexp(2 ** 25, -3)).toBe(2 ** 22);
|
|
7
|
-
expect(ldexp(2 ** -1072, 1073)).toBe(2);
|
|
8
|
-
expect(ldexp(2, 4)).toBe(2 ** 5);
|
|
9
|
-
expect(ldexp(2, 5)).toBe(2 ** 6);
|
|
10
|
-
expect(ldexp(NaN, -3)).toBe(NaN);
|
|
11
|
-
|
|
12
|
-
expect(ldexp(NaN, NaN)).toBe(NaN);
|
|
13
|
-
expect(ldexp(6, NaN)).toBe(NaN);
|
|
14
|
-
expect(ldexp(Infinity, 43)).toBe(Infinity);
|
|
15
|
-
});
|
|
16
|
-
});
|
package/src/double/ldexp.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// ldexp multiplies a floating-point number by an integral power of 2
|
|
2
|
-
// ldexp returns factor * 2**exponent
|
|
3
|
-
// C spec: https://web.archive.org/web/20181230041359if_/http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf#subsection.7.12.6
|
|
4
|
-
// Cppreference: https://en.cppreference.com/w/c/numeric/math/ldexp
|
|
5
|
-
// Implementation is complicated by the need to avoid underflow/overflow given a large exponent (-1075< >1023)
|
|
6
|
-
export function ldexp(/*double*/ factor: number, /*int*/ exponent: number): /*double*/ number {
|
|
7
|
-
const halfPowerRoundedTowardZero: number = 2 ** Math.trunc(exponent * 0.5);
|
|
8
|
-
return (
|
|
9
|
-
factor * halfPowerRoundedTowardZero * halfPowerRoundedTowardZero * 2 ** Math.sign(exponent % 2)
|
|
10
|
-
);
|
|
11
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { nextafter } from "./nextafter.js";
|
|
2
|
-
|
|
3
|
-
describe("nextafter", () => {
|
|
4
|
-
it("returns the next representable value in the direction of another number", () => {
|
|
5
|
-
expect(nextafter(-3.5, 3.5)).toBe(-3.5 + Number.EPSILON * 2);
|
|
6
|
-
expect(nextafter(1, 2)).toBe(1 + Number.EPSILON);
|
|
7
|
-
expect(nextafter(3, 4)).toBe(3 + Number.EPSILON * 2);
|
|
8
|
-
expect(nextafter(3.5, 3.5)).toBe(3.5);
|
|
9
|
-
expect(nextafter(-3.5, -3.5)).toBe(-3.5);
|
|
10
|
-
expect(nextafter(1024, -Infinity)).toBe(1024 - (Number.EPSILON * 1024) / 2);
|
|
11
|
-
expect(nextafter(-0, 0)).toBe(0);
|
|
12
|
-
expect(nextafter(0, -0)).toBe(-0);
|
|
13
|
-
expect(nextafter(-0, -0)).toBe(-0);
|
|
14
|
-
expect(nextafter(NaN, NaN)).toBe(NaN);
|
|
15
|
-
expect(nextafter(NaN, 0)).toBe(NaN);
|
|
16
|
-
expect(nextafter(0, NaN)).toBe(NaN);
|
|
17
|
-
expect(nextafter(Infinity, Infinity)).toBe(Infinity);
|
|
18
|
-
expect(nextafter(Infinity, -Infinity)).toBe(Number.MAX_VALUE);
|
|
19
|
-
expect(nextafter(-Infinity, Infinity)).toBe(-Number.MAX_VALUE);
|
|
20
|
-
expect(nextafter(-Infinity, -Infinity)).toBe(-Infinity);
|
|
21
|
-
expect(nextafter(Number.MAX_VALUE, Infinity)).toBe(Infinity);
|
|
22
|
-
expect(nextafter(-Number.MAX_VALUE, -Infinity)).toBe(-Infinity);
|
|
23
|
-
expect(nextafter(Number.MIN_VALUE, -1)).toBe(0);
|
|
24
|
-
expect(nextafter(-Number.MIN_VALUE, Infinity)).toBe(-0);
|
|
25
|
-
expect(nextafter(Number.MIN_VALUE, -0)).toBe(0);
|
|
26
|
-
expect(nextafter(Number.MIN_VALUE, 1)).toBe(Number.MIN_VALUE * 2);
|
|
27
|
-
expect(nextafter(-Number.MIN_VALUE, -1)).toBe(-Number.MIN_VALUE * 2);
|
|
28
|
-
});
|
|
29
|
-
});
|
package/src/double/nextafter.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// Cppreference: https://en.cppreference.com/w/c/numeric/math/nextafter
|
|
2
|
-
export function nextafter(/*double*/ num: number, /*double*/ toward: number): /*double*/ number {
|
|
3
|
-
if (num === toward) {
|
|
4
|
-
return toward;
|
|
5
|
-
}
|
|
6
|
-
if (num === 0) {
|
|
7
|
-
return Math.sign(toward) * Number.MIN_VALUE;
|
|
8
|
-
}
|
|
9
|
-
if (num === Infinity || num === -Infinity) {
|
|
10
|
-
return Number.MAX_VALUE * Math.sign(num);
|
|
11
|
-
}
|
|
12
|
-
if (num === -Number.MIN_VALUE && toward > num) {
|
|
13
|
-
return -0;
|
|
14
|
-
}
|
|
15
|
-
let differenceMultiplier = 0.5 * Math.sign(num) * (num < toward ? 1 : -1);
|
|
16
|
-
let result: number;
|
|
17
|
-
do {
|
|
18
|
-
result = num + num * (Number.EPSILON * differenceMultiplier);
|
|
19
|
-
differenceMultiplier *= 2;
|
|
20
|
-
} while (result === num);
|
|
21
|
-
return result;
|
|
22
|
-
}
|
package/src/double/pow.test.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { pow } from "./pow.js";
|
|
2
|
-
|
|
3
|
-
describe("pow", () => {
|
|
4
|
-
it("returns the value of a base raised to a power exponent", () => {
|
|
5
|
-
expect(pow(0, -3)).toBe(Infinity);
|
|
6
|
-
expect(pow(-0, -3)).toBe(-Infinity);
|
|
7
|
-
expect(pow(0, -4)).toBe(Infinity);
|
|
8
|
-
expect(pow(-0, -4)).toBe(Infinity);
|
|
9
|
-
expect(pow(0, -4.4)).toBe(Infinity);
|
|
10
|
-
expect(pow(-0, -4.4)).toBe(Infinity);
|
|
11
|
-
expect(pow(0, -Infinity)).toBe(Infinity);
|
|
12
|
-
expect(pow(-0, -Infinity)).toBe(Infinity);
|
|
13
|
-
expect(pow(NaN, 0)).toBe(1);
|
|
14
|
-
expect(pow(1, NaN)).toBe(1);
|
|
15
|
-
expect(pow(1, 45)).toBe(1);
|
|
16
|
-
expect(pow(1, -654132432423)).toBe(1);
|
|
17
|
-
expect(pow(-1, Infinity)).toBe(1);
|
|
18
|
-
expect(pow(-1, -Infinity)).toBe(1);
|
|
19
|
-
expect(pow(0, 555)).toBe(0);
|
|
20
|
-
expect(pow(-0, 713737315)).toBe(-0);
|
|
21
|
-
expect(pow(Infinity, -0.2)).toBe(0);
|
|
22
|
-
expect(pow(Infinity, 3737315.5)).toBe(Infinity);
|
|
23
|
-
expect(pow(-Infinity, 3737315)).toBe(-Infinity);
|
|
24
|
-
expect(pow(-Infinity, 3737315.5)).toBe(Infinity);
|
|
25
|
-
expect(pow(-3, 3)).toBe(-27);
|
|
26
|
-
});
|
|
27
|
-
});
|
package/src/double/pow.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// Cppreference: https://en.cppreference.com/w/c/numeric/math/pow
|
|
2
|
-
export function pow(/*double*/ base: number, /*double*/ exponent: number): /*double*/ number {
|
|
3
|
-
let result = base ** exponent;
|
|
4
|
-
if (base === 1 || (base === -1 && (exponent === Infinity || exponent === -Infinity))) {
|
|
5
|
-
result = 1;
|
|
6
|
-
}
|
|
7
|
-
return result;
|
|
8
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { signbit } from "./signbit.js";
|
|
2
|
-
|
|
3
|
-
describe("signbit", () => {
|
|
4
|
-
it("determines if a number is negative", () => {
|
|
5
|
-
expect(signbit(-Infinity)).toBe(true);
|
|
6
|
-
expect(signbit(-53245432534253)).toBe(true);
|
|
7
|
-
expect(signbit(-0)).toBe(true);
|
|
8
|
-
expect(signbit(0)).toBe(false);
|
|
9
|
-
expect(signbit(98970789063)).toBe(false);
|
|
10
|
-
expect(signbit(Infinity)).toBe(false);
|
|
11
|
-
expect(signbit(NaN)).toBe(false);
|
|
12
|
-
});
|
|
13
|
-
});
|
package/src/double/signbit.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// These functions are JavaScript versions of math functions from C and C++
|
|
2
|
-
// They follow the rules for IEEE-754 implementations.
|
|
3
|
-
// References:
|
|
4
|
-
// C17: https://web.archive.org/web/20181230041359if_/http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf#subsection.13.10.4
|
|
5
|
-
// C++17: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4659.pdf
|
|
6
|
-
// IEEE-754:2008 (IEC 60559): http://irem.univ-reunion.fr/IMG/pdf/ieee-754-2008.pdf
|
|
7
|
-
// https://en.cppreference.com/
|
|
8
|
-
// When reading this code it's important to remember that 0 === -0, but Object.is(0, -0) === false
|
|
9
|
-
|
|
10
|
-
export * from "./double/index.js";
|
|
11
|
-
export * from "./integer/index.js";
|
package/src/integer/abs.test.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { abs } from "./abs.js";
|
|
2
|
-
|
|
3
|
-
describe("abs", () => {
|
|
4
|
-
it("returns the absolute value of an integer number or bigint", () => {
|
|
5
|
-
expect(abs(123084109743)).toBe(123084109743);
|
|
6
|
-
expect(abs(123084109743n)).toBe(123084109743n);
|
|
7
|
-
|
|
8
|
-
expect(abs(-123084109743)).toBe(123084109743);
|
|
9
|
-
expect(abs(-123084109743n)).toBe(123084109743n);
|
|
10
|
-
|
|
11
|
-
expect(abs(-123084109743)).toBe(123084109743);
|
|
12
|
-
expect(abs(-123084109743n)).toBe(123084109743n);
|
|
13
|
-
|
|
14
|
-
expect(abs(0)).toBe(0);
|
|
15
|
-
expect(abs(0n)).toBe(0n);
|
|
16
|
-
|
|
17
|
-
expect(abs(12523423523523532)).toBe(12523423523523532);
|
|
18
|
-
expect(abs(12523423523523532n)).toBe(12523423523523532n);
|
|
19
|
-
|
|
20
|
-
expect(abs(-5252342352352353000000000000)).toBe(5252342352352353000000000000);
|
|
21
|
-
expect(abs(-5252342352352353000000000000n)).toBe(5252342352352353000000000000n);
|
|
22
|
-
|
|
23
|
-
// These do not have bigint equivalents
|
|
24
|
-
expect(abs(-0)).toBe(0);
|
|
25
|
-
expect(abs(-Infinity)).toBe(Infinity);
|
|
26
|
-
expect(abs(NaN)).toBe(NaN);
|
|
27
|
-
});
|
|
28
|
-
});
|
package/src/integer/abs.ts
DELETED
package/src/integer/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { abs } from "./abs.js";
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// This is a bit of a hack. It suppresses Node's warnings about experimental features.
|
|
4
|
-
// Use it like this: node --require=./NAME-OF-THIS-FILE-HERE example.js
|
|
5
|
-
|
|
6
|
-
const { emitWarning } = process;
|
|
7
|
-
process.emitWarning = (warning, ...args) => {
|
|
8
|
-
if (args[0] !== "ExperimentalWarning" && (typeof args[0] !== "object" || args[0].type !== "ExperimentalWarning")) {
|
|
9
|
-
return emitWarning(warning, ...args);
|
|
10
|
-
}
|
|
11
|
-
};
|
package/tsconfig.json
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
|
4
|
-
|
|
5
|
-
/* Projects */
|
|
6
|
-
// "incremental": false, // Enable incremental compilation
|
|
7
|
-
// "composite": true, // Enable constraints that allow a TypeScript project to be used with project references.
|
|
8
|
-
// "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */
|
|
9
|
-
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */
|
|
10
|
-
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
11
|
-
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
|
-
|
|
13
|
-
/* Language and Environment */
|
|
14
|
-
"target": "ESNEXT", // Set the JavaScript language version for emitted JavaScript and include compatible library declarations.
|
|
15
|
-
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
16
|
-
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
17
|
-
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
|
|
18
|
-
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
19
|
-
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
|
|
20
|
-
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
21
|
-
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */
|
|
22
|
-
// "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */
|
|
23
|
-
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
24
|
-
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
25
|
-
|
|
26
|
-
/* Modules */
|
|
27
|
-
"module": "ESNext", // Specify what module code is generated.
|
|
28
|
-
"rootDir": "./src", // Specify the root folder within your source files.
|
|
29
|
-
"moduleResolution": "node", // Specify how TypeScript looks up a file from a given module specifier.
|
|
30
|
-
// "baseUrl": "./src", // Specify the base directory to resolve non-relative module names.
|
|
31
|
-
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
32
|
-
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
33
|
-
// "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
|
|
34
|
-
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
35
|
-
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
36
|
-
// "resolveJsonModule": true, /* Enable importing .json files */
|
|
37
|
-
// "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
|
|
38
|
-
|
|
39
|
-
/* JavaScript Support */
|
|
40
|
-
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
|
|
41
|
-
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
42
|
-
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */
|
|
43
|
-
|
|
44
|
-
/* Emit */
|
|
45
|
-
"declaration": true, // Generate .d.ts files from TypeScript and JavaScript files in your project.
|
|
46
|
-
// "declarationMap": true, // Create sourcemaps for d.ts files.
|
|
47
|
-
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
48
|
-
"sourceMap": true, // Create source map files for emitted JavaScript files.
|
|
49
|
-
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
|
|
50
|
-
"outDir": "./dist", // Specify an output folder for all emitted files.
|
|
51
|
-
"removeComments": true, // Disable emitting comments.
|
|
52
|
-
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
53
|
-
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
54
|
-
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
|
|
55
|
-
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
56
|
-
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
57
|
-
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
58
|
-
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
59
|
-
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
60
|
-
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
61
|
-
"newLine": "lf", // Set the newline character for emitting files.
|
|
62
|
-
// "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
|
|
63
|
-
// "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
|
|
64
|
-
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
65
|
-
// "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
|
|
66
|
-
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
67
|
-
|
|
68
|
-
/* Interop Constraints */
|
|
69
|
-
"isolatedModules": true, // Ensure that each file can be safely transpiled without relying on other imports.
|
|
70
|
-
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
71
|
-
"esModuleInterop": true, // Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility.
|
|
72
|
-
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
73
|
-
"forceConsistentCasingInFileNames": true, // Ensure that casing is correct in imports.
|
|
74
|
-
|
|
75
|
-
/* Type Checking */
|
|
76
|
-
"strict": true, // Enable all strict type-checking options.
|
|
77
|
-
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
|
|
78
|
-
// "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
|
|
79
|
-
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
80
|
-
// "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
|
|
81
|
-
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
82
|
-
// "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */
|
|
83
|
-
// "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */
|
|
84
|
-
"alwaysStrict": true, // Ensure 'use strict' is always emitted.
|
|
85
|
-
// "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */
|
|
86
|
-
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */
|
|
87
|
-
"exactOptionalPropertyTypes": true, // Interpret optional property types as written, rather than adding 'undefined'.
|
|
88
|
-
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
89
|
-
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
90
|
-
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
|
91
|
-
"noImplicitOverride": true, // Ensure overriding members in derived classes are marked with an override modifier.
|
|
92
|
-
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */
|
|
93
|
-
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
94
|
-
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
95
|
-
|
|
96
|
-
/* Completeness */
|
|
97
|
-
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
98
|
-
"skipLibCheck": true // Skip type checking all .d.ts files.
|
|
99
|
-
},
|
|
100
|
-
"exclude": ["src/**/*.test.ts"],
|
|
101
|
-
"include": ["src/**/*"],
|
|
102
|
-
}
|