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.
Files changed (86) hide show
  1. package/.dockerignore +10 -0
  2. package/.editorconfig +7 -0
  3. package/.env +4 -0
  4. package/.eslintignore +2 -0
  5. package/.eslintrc.json +36 -0
  6. package/.gitattributes +1 -0
  7. package/.github/workflows/github-actions-verify.yml +22 -0
  8. package/.nvmrc +1 -0
  9. package/.prettierrc +10 -0
  10. package/.vscode/extensions.json +7 -0
  11. package/.vscode/launch.json +28 -14
  12. package/.vscode/settings.json +14 -0
  13. package/Dockerfile +11 -0
  14. package/LICENSE +1 -1
  15. package/README.md +13 -10
  16. package/dist/double/copysign.d.ts +1 -0
  17. package/dist/double/copysign.js +4 -0
  18. package/dist/double/copysign.js.map +1 -0
  19. package/dist/double/fabs.d.ts +1 -0
  20. package/dist/double/fabs.js +2 -0
  21. package/dist/double/fabs.js.map +1 -0
  22. package/dist/double/frexp.d.ts +1 -0
  23. package/dist/double/frexp.js +23 -0
  24. package/dist/double/frexp.js.map +1 -0
  25. package/dist/double/hypot.d.ts +1 -0
  26. package/dist/double/hypot.js +19 -0
  27. package/dist/double/hypot.js.map +1 -0
  28. package/dist/double/index.d.ts +8 -0
  29. package/dist/double/index.js +9 -0
  30. package/dist/double/index.js.map +1 -0
  31. package/dist/double/ldexp.d.ts +1 -0
  32. package/dist/double/ldexp.js +5 -0
  33. package/dist/double/ldexp.js.map +1 -0
  34. package/dist/double/nextafter.d.ts +1 -0
  35. package/dist/double/nextafter.js +22 -0
  36. package/dist/double/nextafter.js.map +1 -0
  37. package/dist/double/pow.d.ts +1 -0
  38. package/dist/double/pow.js +8 -0
  39. package/dist/double/pow.js.map +1 -0
  40. package/dist/double/signbit.d.ts +1 -0
  41. package/dist/double/signbit.js +4 -0
  42. package/dist/double/signbit.js.map +1 -0
  43. package/dist/index.d.ts +2 -0
  44. package/dist/index.js +3 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/integer/abs.d.ts +1 -0
  47. package/dist/integer/abs.js +7 -0
  48. package/dist/integer/abs.js.map +1 -0
  49. package/dist/integer/index.d.ts +1 -0
  50. package/dist/integer/index.js +2 -0
  51. package/dist/integer/index.js.map +1 -0
  52. package/docker-compose.ci-verifier.yml +6 -0
  53. package/jest.config.js +12 -0
  54. package/jest.config.with-typechecking.js +9 -0
  55. package/package.json +48 -35
  56. package/src/double/copysign.test.ts +9 -0
  57. package/src/double/copysign.ts +8 -0
  58. package/src/double/fabs.test.ts +14 -0
  59. package/src/double/fabs.ts +3 -0
  60. package/src/double/frexp.test.ts +15 -0
  61. package/src/double/frexp.ts +40 -0
  62. package/src/double/hypot.test.ts +11 -0
  63. package/src/double/hypot.ts +25 -0
  64. package/src/double/index.ts +8 -0
  65. package/src/double/ldexp.test.ts +16 -0
  66. package/src/double/ldexp.ts +11 -0
  67. package/src/double/nextafter.test.ts +29 -0
  68. package/src/double/nextafter.ts +22 -0
  69. package/src/double/pow.test.ts +27 -0
  70. package/src/double/pow.ts +8 -0
  71. package/src/double/signbit.test.ts +13 -0
  72. package/src/double/signbit.ts +4 -0
  73. package/src/index.ts +11 -0
  74. package/src/integer/abs.test.ts +28 -0
  75. package/src/integer/abs.ts +8 -0
  76. package/src/integer/index.ts +1 -0
  77. package/suppressExperimentalWarnings.cjs +11 -0
  78. package/tsconfig.json +98 -17
  79. package/.vscode/ipch/5ab7b32c9fc14e9f/mmap_address.bin +0 -0
  80. package/.vscode/tasks.json +0 -22
  81. package/dist/cmath.d.ts +0 -9
  82. package/dist/cmath.js +0 -126
  83. package/dist/cmath.js.map +0 -1
  84. package/jest.config.json +0 -9
  85. package/src/cmath.ts +0 -146
  86. package/test/cmath.test.ts +0 -123
package/.dockerignore ADDED
@@ -0,0 +1,10 @@
1
+ /.github
2
+ /.vscode
3
+ /dist
4
+
5
+ /.dockerignore
6
+ /LICENSE
7
+ /README.md
8
+ /docker-compose.yml
9
+ /Dockerfile
10
+ /tsconfig.tsbuildinfo
package/.editorconfig ADDED
@@ -0,0 +1,7 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ end_of_line = lf
6
+ indent_style = tab
7
+ insert_final_newline = true
package/.env ADDED
@@ -0,0 +1,4 @@
1
+ # To make .gitignored configuration changes,
2
+ # create a file like this and call it .env.local
3
+
4
+ SECONDS_BETWEEN_MESSAGES="2"
package/.eslintignore ADDED
@@ -0,0 +1,2 @@
1
+ /dist
2
+ /node_modules
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
@@ -0,0 +1,10 @@
1
+ {
2
+ "arrowParens": "always",
3
+ "bracketSpacing": true,
4
+ "endOfLine": "lf",
5
+ "printWidth": 100,
6
+ "quoteProps": "as-needed",
7
+ "semi": true,
8
+ "singleQuote": false,
9
+ "useTabs": true
10
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "recommendations": [
3
+ "dbaeumer.vscode-eslint",
4
+ "esbenp.prettier-vscode",
5
+ "orta.vscode-jest",
6
+ ]
7
+ }
@@ -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
- "name": "Launch Program",
11
- "program": "${workspaceFolder}\\test\\cmath.test.ts",
12
- "runtimeArgs": [
13
- "--experimental-modules"
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
@@ -0,0 +1,11 @@
1
+ # syntax=docker/dockerfile:1
2
+
3
+ FROM node:20-alpine as pre-build
4
+ WORKDIR /app
5
+ COPY . .
6
+ RUN NODE_ENV=development npm install
7
+
8
+ FROM pre-build AS ci-verifier
9
+ ENV NODE_ENV development
10
+ CMD ["npm", "run", "build-and-verify"]
11
+
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2019 Oskar L Högfeldt
3
+ Copyright (c) 2021 Oskar Larsson Högfeldt
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,13 +1,16 @@
1
1
  # cmath-js
2
- Implementations of some of C's math functions in JavaScript/TypeScript:
2
+ Implementations of some of C's math functions in TypeScript/JavaScript.
3
3
 
4
- * nextafter
5
- * signbit
6
- * frexp
7
- * ldexp
8
- * copysign
9
- * fabs
10
- * abs
11
- * hypot
12
- * pow
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,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,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,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":"AASA,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":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,6 @@
1
+ version: "3.9"
2
+ services:
3
+ ci-verifier:
4
+ build:
5
+ context: .
6
+ target: ci-verifier
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
+ };
@@ -0,0 +1,9 @@
1
+ import withoutTypechecking from "./jest.config.js";
2
+
3
+ /** @type {import('ts-jest').JestConfigWithTsJest} */
4
+ export default {
5
+ ...withoutTypechecking,
6
+ transform: {
7
+ "^.+\\.ts$": ["ts-jest"],
8
+ },
9
+ };
package/package.json CHANGED
@@ -1,37 +1,50 @@
1
1
  {
2
- "name": "cmath-js",
3
- "version": "1.0.3",
4
- "description": "C's math functions implemented in TypeScript/JavaScript",
5
- "main": "dist/cmath.js",
6
- "types": "dist/cmath.d.ts",
7
- "homepage": "https://github.com/oskarlh/cmath.js",
8
- "repository": "github:oskarlh/cmath.js",
9
- "scripts": {
10
- "compile": "tsc",
11
- "test": "jest --config jest.config.json --coverage"
12
- },
13
- "keywords": [
14
- "cmath",
15
- "C",
16
- "C++",
17
- "Math",
18
- "Maths",
19
- "JavaScript",
20
- "ECMAScript",
21
- "TypeScript",
22
- "Node",
23
- "NodeJS",
24
- "Web",
25
- "Browser"
26
- ],
27
- "author": "Oskar Larsson Högfeldt",
28
- "license": "MIT",
29
- "type": "module",
30
- "devDependencies": {
31
- "@types/jest": "^26.0.19",
32
- "@types/node": "^14.14.17",
33
- "jest": "^26.6.3",
34
- "ts-jest": "^26.4.4",
35
- "typescript": "^4.1.3"
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
+ });
@@ -0,0 +1,3 @@
1
+ // fabs is just like JavaScript's Math.abs
2
+ // Cppreference: https://en.cppreference.com/w/c/numeric/math/fabs
3
+ export const fabs = Math.abs;