Skip to content

Commit adc2f7e

Browse files
committed
more consistent naming, move libm
1 parent 5b41c1f commit adc2f7e

25 files changed

+19957
-932
lines changed

lib/libm/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# ![AS](https://avatars1.githubusercontent.com/u/28916798?s=48) libm
2+
3+
AssemblyScript's math routines for double and single precision as a library.
4+
5+
```ts
6+
const libm = require("@assemblyscript/libm");
7+
const libmf = libm.libmf;
8+
...
9+
```
10+
11+
Both `libm` and `libmf` have the same general interface as JavaScript's `Math`, with `libmf` doing single precision math.

lib/libm/assembly/libm.ts

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
export const E = Math.E;
2+
export const LN10 = Math.LN10;
3+
export const LN2 = Math.LN2;
4+
export const LOG10E = Math.LOG10E;
5+
export const LOG2E = Math.LOG2E;
6+
export const PI = Math.PI;
7+
export const SQRT1_2 = Math.SQRT1_2;
8+
export const SQRT2 = Math.SQRT2;
9+
10+
export function abs(x: f64): f64 {
11+
return Math.abs(x);
12+
}
13+
14+
export function acos(x: f64): f64 {
15+
return Math.acos(x);
16+
}
17+
18+
export function acosh(x: f64): f64 {
19+
return Math.acosh(x);
20+
}
21+
22+
export function asin(x: f64): f64 {
23+
return Math.asin(x);
24+
}
25+
26+
export function asinh(x: f64): f64 {
27+
return Math.asinh(x);
28+
}
29+
30+
export function atan(x: f64): f64 {
31+
return Math.atan(x);
32+
}
33+
34+
export function atanh(x: f64): f64 {
35+
return Math.atanh(x);
36+
}
37+
38+
export function atan2(y: f64, x: f64): f64 {
39+
return Math.atan2(y, x);
40+
}
41+
42+
export function cbrt(x: f64): f64 {
43+
return Math.cbrt(x);
44+
}
45+
46+
export function ceil(x: f64): f64 {
47+
return Math.ceil(x);
48+
}
49+
50+
export function clz32(x: f64): f64 {
51+
return Math.clz32(x);
52+
}
53+
54+
export function cos(x: f64): f64 {
55+
return Math.cos(x);
56+
}
57+
58+
export function cosh(x: f64): f64 {
59+
return Math.cosh(x);
60+
}
61+
62+
export function exp(x: f64): f64 {
63+
return Math.exp(x);
64+
}
65+
66+
export function expm1(x: f64): f64 {
67+
return Math.expm1(x);
68+
}
69+
70+
export function floor(x: f64): f64 {
71+
return Math.floor(x);
72+
}
73+
74+
export function fround(x: f64): f64 {
75+
return Math.fround(x);
76+
}
77+
78+
export function hypot(a: f64, b: f64): f64 {
79+
return Math.hypot(a, b);
80+
}
81+
82+
export function imul(a: f64, b: f64): f64 {
83+
return Math.imul(a, b);
84+
}
85+
86+
export function log(x: f64): f64 {
87+
return Math.log(x);
88+
}
89+
90+
export function log10(x: f64): f64 {
91+
return Math.log10(x);
92+
}
93+
94+
export function log1p(x: f64): f64 {
95+
return Math.log1p(x);
96+
}
97+
98+
export function log2(x: f64): f64 {
99+
return Math.log2(x);
100+
}
101+
102+
export function max(a: f64, b: f64): f64 {
103+
return Math.max(a, b);
104+
}
105+
106+
export function min(a: f64, b: f64): f64 {
107+
return Math.min(a, b);
108+
}
109+
110+
export function pow(x: f64, y: f64): f64 {
111+
return Math.pow(x, y);
112+
}
113+
114+
export function round(x: f64): f64 {
115+
return Math.round(x);
116+
}
117+
118+
export function sign(x: f64): f64 {
119+
return Math.sign(x);
120+
}
121+
122+
export function sin(x: f64): f64 {
123+
return Math.sin(x);
124+
}
125+
126+
export function sinh(x: f64): f64 {
127+
return Math.sinh(x);
128+
}
129+
130+
export function sqrt(x: f64): f64 {
131+
return Math.sqrt(x);
132+
}
133+
134+
export function tan(x: f64): f64 {
135+
return Math.tan(x);
136+
}
137+
138+
export function tanh(x: f64): f64 {
139+
return Math.tanh(x);
140+
}
141+
142+
export function trunc(x: f64): f64 {
143+
return Math.trunc(x);
144+
}

lib/libm/assembly/libmf.ts

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
export const E = Mathf.E;
2+
export const LN10 = Mathf.LN10;
3+
export const LN2 = Mathf.LN2;
4+
export const LOG10E = Mathf.LOG10E;
5+
export const LOG2E = Mathf.LOG2E;
6+
export const PI = Mathf.PI;
7+
export const SQRT1_2 = Mathf.SQRT1_2;
8+
export const SQRT2 = Mathf.SQRT2;
9+
10+
export function abs(x: f32): f32 {
11+
return Mathf.abs(x);
12+
}
13+
14+
export function acos(x: f32): f32 {
15+
return Mathf.acos(x);
16+
}
17+
18+
export function acosh(x: f32): f32 {
19+
return Mathf.acosh(x);
20+
}
21+
22+
export function asin(x: f32): f32 {
23+
return Mathf.asin(x);
24+
}
25+
26+
export function asinh(x: f32): f32 {
27+
return Mathf.asinh(x);
28+
}
29+
30+
export function atan(x: f32): f32 {
31+
return Mathf.atan(x);
32+
}
33+
34+
export function atanh(x: f32): f32 {
35+
return Mathf.atanh(x);
36+
}
37+
38+
export function atan2(y: f32, x: f32): f32 {
39+
return Mathf.atan2(y, x);
40+
}
41+
42+
export function cbrt(x: f32): f32 {
43+
return Mathf.cbrt(x);
44+
}
45+
46+
export function ceil(x: f32): f32 {
47+
return Mathf.ceil(x);
48+
}
49+
50+
export function clz32(x: f32): f32 {
51+
return Mathf.clz32(x);
52+
}
53+
54+
export function cos(x: f32): f32 {
55+
return Mathf.cos(x);
56+
}
57+
58+
export function cosh(x: f32): f32 {
59+
return Mathf.cosh(x);
60+
}
61+
62+
export function exp(x: f32): f32 {
63+
return Mathf.exp(x);
64+
}
65+
66+
export function expm1(x: f32): f32 {
67+
return Mathf.expm1(x);
68+
}
69+
70+
export function floor(x: f32): f32 {
71+
return Mathf.floor(x);
72+
}
73+
74+
export function fround(x: f32): f32 {
75+
return Mathf.fround(x);
76+
}
77+
78+
export function hypot(a: f32, b: f32): f32 {
79+
return Mathf.hypot(a, b);
80+
}
81+
82+
export function imul(a: f32, b: f32): f32 {
83+
return Mathf.imul(a, b);
84+
}
85+
86+
export function log(x: f32): f32 {
87+
return Mathf.log(x);
88+
}
89+
90+
export function log10(x: f32): f32 {
91+
return Mathf.log10(x);
92+
}
93+
94+
export function log1p(x: f32): f32 {
95+
return Mathf.log1p(x);
96+
}
97+
98+
export function log2(x: f32): f32 {
99+
return Mathf.log2(x);
100+
}
101+
102+
export function max(a: f32, b: f32): f32 {
103+
return Mathf.max(a, b);
104+
}
105+
106+
export function min(a: f32, b: f32): f32 {
107+
return Mathf.min(a, b);
108+
}
109+
110+
export function pow(x: f32, y: f32): f32 {
111+
return Mathf.pow(x, y);
112+
}
113+
114+
export function round(x: f32): f32 {
115+
return Mathf.round(x);
116+
}
117+
118+
export function sign(x: f32): f32 {
119+
return Mathf.sign(x);
120+
}
121+
122+
export function sin(x: f32): f32 {
123+
return Mathf.sin(x);
124+
}
125+
126+
export function sinh(x: f32): f32 {
127+
return Mathf.sinh(x);
128+
}
129+
130+
export function sqrt(x: f32): f32 {
131+
return Mathf.sqrt(x);
132+
}
133+
134+
export function tan(x: f32): f32 {
135+
return Mathf.tan(x);
136+
}
137+
138+
export function tanh(x: f32): f32 {
139+
return Mathf.tanh(x);
140+
}
141+
142+
export function trunc(x: f32): f32 {
143+
return Mathf.trunc(x);
144+
}

lib/libm/assembly/tsconfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "../../../std/assembly.json",
3+
"include": [
4+
"./**/*.ts"
5+
]
6+
}

lib/libm/build/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.wasm
2+
*.wasm.map

0 commit comments

Comments
 (0)