-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmath.echo
More file actions
89 lines (71 loc) · 1.42 KB
/
Copy pathmath.echo
File metadata and controls
89 lines (71 loc) · 1.42 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
; std/math — numeric helpers (f64 float ops + int abs/min/max).
; Suite: xo test std/math.echo
/ runtime
/ std/test
$ abs_i = (n) {
^ runtime.math_abs_i(n)
}
$ min = (a, b) {
? a < b {
^ a
}
^ b
}
$ max = (a, b) {
? a > b {
^ a
}
^ b
}
$ sqrt = (x) {
^ runtime.math_sqrt(x)
}
$ sin = (x) {
^ runtime.math_sin(x)
}
$ cos = (x) {
^ runtime.math_cos(x)
}
$ tan = (x) {
^ runtime.math_tan(x)
}
$ floor = (x) {
^ runtime.math_floor(x)
}
$ ceil = (x) {
^ runtime.math_ceil(x)
}
$ abs_f = (x) {
^ runtime.math_abs_f(x)
}
$ pow = (a, b) {
^ runtime.math_pow(a, b)
}
test.it("abs_min_max", () {
test.eq(abs_i(-3), 3)
test.eq(min(2, 5), 2)
test.eq(max(2, 5), 5)
})
test.it("sqrt4", () {
$ x = <f64>4.0
$ y = sqrt(x)
test.true(y == <f64>2.0)
})
test.it("floor_ceil_pow", () {
test.true(floor(<f64>3.7) == <f64>3.0)
test.true(ceil(<f64>3.2) == <f64>4.0)
test.true(pow(<f64>2.0, <f64>3.0) == <f64>8.0)
test.true(abs_f(<f64>-2.5) == <f64>2.5)
test.true(sin(<f64>0.0) == <f64>0.0)
test.true(cos(<f64>0.0) == <f64>1.0)
test.true(tan(<f64>0.0) == <f64>0.0)
})
; Co-located benchmarks: `xo test --bench std` / `xo test --bench std/math.echo`.
test.bench("abs_i", () {
$ n = abs_i(-42)
})
test.bench("sqrt", () {
$ x = <f64>2.0
$ y = sqrt(x)
})
\ abs_i, min, max, sqrt, sin, cos, tan, floor, ceil, abs_f, pow