Skip to content

Commit

Permalink
Add absf to float.mc
Browse files Browse the repository at this point in the history
  • Loading branch information
br4sco committed Apr 6, 2024
1 parent 98a23e2 commit 26d201f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 10 additions & 0 deletions stdlib/float.mc
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 0 additions & 4 deletions stdlib/math.mc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 26d201f

Please sign in to comment.