Skip to content

Commit

Permalink
Add minf to float.mc
Browse files Browse the repository at this point in the history
  • Loading branch information
br4sco committed Apr 6, 2024
1 parent 26d201f commit 1070a5a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 14 additions & 0 deletions stdlib/float.mc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ utest isNaN (maxf nan 0.) with true
utest isNaN (maxf 0. nan) with true


-- `minf l r` returns the minimum of `l` and `r`. If either is `nan` it returns
-- `nan`. If `minf 0. -0.` and `minf -0. 0.` returns `-0.`.
let minf: Float -> Float -> Float = lam r. lam l.
if or (isNaN l) (isNaN r) then nan
else
if ltf r l then r else l

utest minf 0. 0. with 0.
utest minf 1. 0. with 0.
utest minf 0. 1. with 0.
utest isNaN (minf nan 0.) with true
utest isNaN (minf 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)

Expand Down
4 changes: 0 additions & 4 deletions stdlib/math.mc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ include "bool.mc"
include "float.mc"

-- Float stuff
let minf: Float -> Float -> Float = lam r. lam l. if ltf r l then r else l
utest minf 0. 0. with 0. using eqf
utest minf 1. 0. with 0. using eqf
utest minf 0. 1. with 0. using eqf

let cmpfApprox : Float -> Float -> Float -> Int =
lam epsilon. lam l. lam r.
Expand Down

0 comments on commit 1070a5a

Please sign in to comment.