cmath-js 1.0.3 → 1.0.4
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/.dockerignore +10 -0
- package/.editorconfig +7 -0
- package/.env +4 -0
- package/.eslintignore +2 -0
- package/.eslintrc.json +36 -0
- package/.gitattributes +1 -0
- package/.github/workflows/github-actions-verify.yml +22 -0
- package/.nvmrc +1 -0
- package/.prettierrc +10 -0
- package/.vscode/extensions.json +7 -0
- package/.vscode/launch.json +28 -14
- package/.vscode/settings.json +14 -0
- package/Dockerfile +11 -0
- package/LICENSE +1 -1
- package/README.md +13 -10
- package/dist/double/copysign.d.ts +1 -0
- package/dist/double/copysign.js +4 -0
- package/dist/double/copysign.js.map +1 -0
- package/dist/double/fabs.d.ts +1 -0
- package/dist/double/fabs.js +2 -0
- package/dist/double/fabs.js.map +1 -0
- package/dist/double/frexp.d.ts +1 -0
- package/dist/double/frexp.js +23 -0
- package/dist/double/frexp.js.map +1 -0
- package/dist/double/hypot.d.ts +1 -0
- package/dist/double/hypot.js +19 -0
- package/dist/double/hypot.js.map +1 -0
- package/dist/double/index.d.ts +8 -0
- package/dist/double/index.js +9 -0
- package/dist/double/index.js.map +1 -0
- package/dist/double/ldexp.d.ts +1 -0
- package/dist/double/ldexp.js +5 -0
- package/dist/double/ldexp.js.map +1 -0
- package/dist/double/nextafter.d.ts +1 -0
- package/dist/double/nextafter.js +22 -0
- package/dist/double/nextafter.js.map +1 -0
- package/dist/double/pow.d.ts +1 -0
- package/dist/double/pow.js +8 -0
- package/dist/double/pow.js.map +1 -0
- package/dist/double/signbit.d.ts +1 -0
- package/dist/double/signbit.js +4 -0
- package/dist/double/signbit.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/integer/abs.d.ts +1 -0
- package/dist/integer/abs.js +7 -0
- package/dist/integer/abs.js.map +1 -0
- package/dist/integer/index.d.ts +1 -0
- package/dist/integer/index.js +2 -0
- package/dist/integer/index.js.map +1 -0
- package/docker-compose.ci-verifier.yml +6 -0
- package/jest.config.js +12 -0
- package/jest.config.with-typechecking.js +9 -0
- package/package.json +48 -35
- package/src/double/copysign.test.ts +9 -0
- package/src/double/copysign.ts +8 -0
- package/src/double/fabs.test.ts +14 -0
- package/src/double/fabs.ts +3 -0
- package/src/double/frexp.test.ts +15 -0
- package/src/double/frexp.ts +40 -0
- package/src/double/hypot.test.ts +11 -0
- package/src/double/hypot.ts +25 -0
- package/src/double/index.ts +8 -0
- package/src/double/ldexp.test.ts +16 -0
- package/src/double/ldexp.ts +11 -0
- package/src/double/nextafter.test.ts +29 -0
- package/src/double/nextafter.ts +22 -0
- package/src/double/pow.test.ts +27 -0
- package/src/double/pow.ts +8 -0
- package/src/double/signbit.test.ts +13 -0
- package/src/double/signbit.ts +4 -0
- package/src/index.ts +11 -0
- package/src/integer/abs.test.ts +28 -0
- package/src/integer/abs.ts +8 -0
- package/src/integer/index.ts +1 -0
- package/suppressExperimentalWarnings.cjs +11 -0
- package/tsconfig.json +98 -17
- package/.vscode/ipch/5ab7b32c9fc14e9f/mmap_address.bin +0 -0
- package/.vscode/tasks.json +0 -22
- package/dist/cmath.d.ts +0 -9
- package/dist/cmath.js +0 -126
- package/dist/cmath.js.map +0 -1
- package/jest.config.json +0 -9
- package/src/cmath.ts +0 -146
- package/test/cmath.test.ts +0 -123
package/.dockerignore
ADDED
package/.editorconfig
ADDED
package/.env
ADDED
package/.eslintignore
ADDED
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
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
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* text=auto eol=lf
|
|
@@ -0,0 +1,22 @@
|
|
|
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
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
20
|
package/.prettierrc
ADDED
package/.vscode/launch.json
CHANGED
|
@@ -1,23 +1,37 @@
|
|
|
1
1
|
{
|
|
2
|
-
// Use IntelliSense to learn about possible attributes.
|
|
3
|
-
// Hover to view descriptions of existing attributes.
|
|
4
|
-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
2
|
"version": "0.2.0",
|
|
6
3
|
"configurations": [
|
|
7
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/**"],
|
|
8
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"],
|
|
9
30
|
"request": "launch",
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
],
|
|
15
|
-
"outFiles": [
|
|
16
|
-
"${workspaceFolder}/dist/**/*.js"
|
|
17
|
-
]
|
|
31
|
+
"runtimeArgs": ["run", "build"],
|
|
32
|
+
"runtimeExecutable": "npm",
|
|
33
|
+
"skipFiles": ["<node_internals>/**", "node_modules/**"],
|
|
34
|
+
"type": "node"
|
|
18
35
|
}
|
|
19
36
|
]
|
|
20
37
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
@@ -0,0 +1,14 @@
|
|
|
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
ADDED
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
# cmath-js
|
|
2
|
-
Implementations of some of C's math functions in JavaScript
|
|
2
|
+
Implementations of some of C's math functions in TypeScript/JavaScript.
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
## Floating-point functions
|
|
5
|
+
- copysign
|
|
6
|
+
- fabs
|
|
7
|
+
- frexp
|
|
8
|
+
- hypot
|
|
9
|
+
- ldexp
|
|
10
|
+
- nextafter
|
|
11
|
+
- pow
|
|
12
|
+
- signbit
|
|
13
13
|
|
|
14
|
+
## Integer functions
|
|
15
|
+
These accept either a `number` or a `bigint`:
|
|
16
|
+
- abs
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function copysign(num: number, sign: number): number;
|
|
@@ -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 @@
|
|
|
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,23 @@
|
|
|
1
|
+
export function frexp(num) {
|
|
2
|
+
const result = [num, 0];
|
|
3
|
+
if (num !== 0 && Number.isFinite(num)) {
|
|
4
|
+
const absNum = Math.abs(num);
|
|
5
|
+
let exp = Math.max(-1023, Math.floor(Math.log2(absNum)) + 1);
|
|
6
|
+
let x = absNum * 2 ** -exp;
|
|
7
|
+
while (x < 0.5) {
|
|
8
|
+
x *= 2;
|
|
9
|
+
--exp;
|
|
10
|
+
}
|
|
11
|
+
while (x >= 1) {
|
|
12
|
+
x *= 0.5;
|
|
13
|
+
++exp;
|
|
14
|
+
}
|
|
15
|
+
if (num < 0) {
|
|
16
|
+
x = -x;
|
|
17
|
+
}
|
|
18
|
+
result[0] = x;
|
|
19
|
+
result[1] = exp;
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
//# 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,MAAM,MAAM,GAAqB,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAE1C,IAAI,GAAG,KAAK,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QACtC,MAAM,MAAM,GAAW,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAErC,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;QACrE,IAAI,CAAC,GAAW,MAAM,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC;QAInC,OAAO,CAAC,GAAG,GAAG,EAAE;YACf,CAAC,IAAI,CAAC,CAAC;YACP,EAAE,GAAG,CAAC;SACN;QAGD,OAAO,CAAC,IAAI,CAAC,EAAE;YACd,CAAC,IAAI,GAAG,CAAC;YACT,EAAE,GAAG,CAAC;SACN;QAED,IAAI,GAAG,GAAG,CAAC,EAAE;YACZ,CAAC,GAAG,CAAC,CAAC,CAAC;SACP;QACD,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACd,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;KAChB;IACD,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function hypot(x: number, y: number, z?: number): number;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function hypot(x, y, z) {
|
|
2
|
+
let result = 0;
|
|
3
|
+
if (z !== undefined) {
|
|
4
|
+
result = Math.hypot(x, y, z);
|
|
5
|
+
}
|
|
6
|
+
else {
|
|
7
|
+
result = Infinity;
|
|
8
|
+
if (x !== Infinity && x !== -Infinity && y !== Infinity && y !== -Infinity) {
|
|
9
|
+
if (x === 0 || y === 0) {
|
|
10
|
+
result = Math.max(Math.abs(x), Math.abs(y));
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
result = Math.hypot(x, y);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
//# 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,MAAM,GAAW,CAAC,CAAC;IACvB,IAAI,CAAC,KAAK,SAAS,EAAE;QACpB,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;KAC7B;SAAM;QACN,MAAM,GAAG,QAAQ,CAAC;QAClB,IAAI,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;YAC3E,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;gBACvB,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;aAC5C;iBAAM;gBACN,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;aAC1B;SACD;KACD;IACD,OAAO,MAAM,CAAC;AACf,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":"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;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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function abs(number: bigint | number): number | bigint;
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/integer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC"}
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
};
|
package/package.json
CHANGED
|
@@ -1,37 +1,50 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
2
|
+
"name": "cmath-js",
|
|
3
|
+
"homepage": "https://github.com/oskarlh/cmath.js",
|
|
4
|
+
"repository": "github:oskarlh/cmath.js",
|
|
5
|
+
"version": "1.0.4",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"author": "Oskar Larsson Högfeldt <oskar@oskar.pm>",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"description": "C's math functions implemented in TypeScript/JavaScript",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"cmath",
|
|
14
|
+
"C",
|
|
15
|
+
"C++",
|
|
16
|
+
"Math",
|
|
17
|
+
"Maths",
|
|
18
|
+
"JavaScript",
|
|
19
|
+
"ECMAScript",
|
|
20
|
+
"TypeScript",
|
|
21
|
+
"Node",
|
|
22
|
+
"NodeJS",
|
|
23
|
+
"Web",
|
|
24
|
+
"Browser"
|
|
25
|
+
],
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@swc/cli": "^0.1.57",
|
|
28
|
+
"@swc/core": "^1.3.18",
|
|
29
|
+
"@swc/jest": "^0.2.23",
|
|
30
|
+
"@types/jest": "^29",
|
|
31
|
+
"@types/node": "^20",
|
|
32
|
+
"@typescript-eslint/eslint-plugin": "^6.2",
|
|
33
|
+
"@typescript-eslint/parser": "^6.2",
|
|
34
|
+
"eslint": "^8.5.0",
|
|
35
|
+
"eslint-config-prettier": "^8.3.0",
|
|
36
|
+
"eslint-plugin-prettier": "^5",
|
|
37
|
+
"jest": "^29.3.1",
|
|
38
|
+
"prettier": "^3",
|
|
39
|
+
"ts-jest": "^29.0.3",
|
|
40
|
+
"typescript": "~5.1"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsc",
|
|
44
|
+
"build-and-verify": "npm run test-with-typechecking --ci && npm run lint && npm run build",
|
|
45
|
+
"build-without-typechecking": "swc -C exclude=.test.ts -d dist -s true -- src",
|
|
46
|
+
"lint": "eslint .",
|
|
47
|
+
"test": "jest",
|
|
48
|
+
"test-with-typechecking": "jest --config=jest.config.with-typechecking.js"
|
|
49
|
+
}
|
|
37
50
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
});
|