diff --git a/stdlib/float.mc b/stdlib/float.mc index 43ab3f2d7..cc9fb6a70 100644 --- a/stdlib/float.mc +++ b/stdlib/float.mc @@ -27,3 +27,13 @@ utest maxf 1. 0. with 1. utest maxf 0. 1. with 1. utest isNaN (maxf nan 0.) with true utest isNaN (maxf 0. nan) with true + + +-- `absf a` returns the absolute value of `a` or `nan` if `a` is `nan`. +let absf: Float -> Float = lam f. maxf f (negf f) + +utest absf 0. with 0. using eqf +utest absf 1. with 1. using eqf +utest absf -1. with 1. using eqf +utest absf -0. with 0. using eqf +utest isNaN (absf nan) with true diff --git a/stdlib/math.mc b/stdlib/math.mc index 432ab05ca..5868a148f 100644 --- a/stdlib/math.mc +++ b/stdlib/math.mc @@ -8,10 +8,6 @@ utest minf 0. 0. with 0. using eqf utest minf 1. 0. with 0. using eqf utest minf 0. 1. with 0. using eqf -utest absf 0. with 0. using eqf -utest absf 1. with 1. using eqf -utest absf (negf 1.) with 1. using eqf - let cmpfApprox : Float -> Float -> Float -> Int = lam epsilon. lam l. lam r. if eqfApprox epsilon l r then 0