forked from miking-lang/miking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath-ext.mc
59 lines (44 loc) · 1.78 KB
/
math-ext.mc
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
let maxf: Float -> Float -> Float = lam r. lam l. if gtf r l then r else l
let absf: Float -> Float = lam f. maxf f (negf f)
let eqfApprox = lam epsilon. lam r. lam l.
if leqf (absf (subf r l)) epsilon then true else false
utest 1. with 1.01 using eqfApprox 0.011
utest negf 1.0 with negf 1.009 using eqfApprox 0.01
utest 0.0 with 0.0 using (eqfApprox 0.)
utest eqfApprox 0.01 1.0 1.011 with false
utest 1. with 1.000009 using eqfApprox 0.00001
utest eqfApprox 0.00001 1.0 1.000011 with false
let _eqf = eqfApprox 1e-15
utest maxf 0. 0. with 0. using eqf
utest maxf 1. 0. with 1. using eqf
utest maxf 0. 1. with 1. using eqf
external externalExp : Float -> Float
let exp = lam x: Float. externalExp x
utest exp 0. with 1. using eqf
external externalLog : Float -> Float
let log = lam x: Float. externalLog x
utest log (exp 7.) with 7. using eqf
utest exp (log 7.) with 7. using _eqf
external externalAtan : Float -> Float
let atan = lam x : Float. externalAtan x
utest atan 0. with 0. using eqf
let pi = mulf 4. (atan 1.)
external externalSin : Float -> Float
let sin = lam x : Float. externalSin x
utest sin (divf pi 2.) with 1. using eqf
utest sin 0. with 0. using eqf
external externalCos : Float -> Float
let cos = lam x : Float. externalCos x
utest cos (divf pi 2.) with 0. using _eqf
utest cos 0. with 1. using eqf
utest addf (mulf (sin 1.) (sin 1.)) (mulf (cos 1.) (cos 1.)) with 1.
using eqf
external externalAtan2 : Float -> Float -> Float
let atan2 = lam x : Float. lam y : Float. externalAtan2 x y
utest atan2 0. 1. with 0. using eqf
external externalPow : Float -> Float -> Float
let pow = lam x: Float. lam y: Float. externalPow x y
utest pow 3. 2. with 9. using eqf
external externalSqrt : Float -> Float
let sqrt: Float -> Float = lam x. externalSqrt x
utest sqrt 9. with 3. using eqf