Skip to content

Commit

Permalink
Add min and max operators.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode committed Sep 2, 2015
1 parent 02668bb commit d072c59
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ml-proto/src/arithmetic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ struct
| Mul -> ( *.)
| Div -> (/.)
| CopySign -> copysign
| Min -> fun _ _ -> 0.0 (* TODO *)

This comment has been minimized.

Copy link
@rossberg

rossberg Sep 3, 2015

Member

An approximative implementation actually is trivial:

| Min -> min
| Max -> max

This comment has been minimized.

Copy link
@sunfishcode

sunfishcode Sep 3, 2015

Author Member

Ok, I added a patch to do this.

| Max -> fun _ _ -> 0.0 (* TODO *)
in
fun v1 v2 -> Float.to_value (f (Float.of_value 1 v1) (Float.of_value 2 v2))

Expand Down
2 changes: 1 addition & 1 deletion ml-proto/src/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ end
module FloatOp () =
struct
type unop = Neg | Abs | Ceil | Floor | Trunc | Nearest | Sqrt
type binop = Add | Sub | Mul | Div | CopySign
type binop = Add | Sub | Mul | Div | CopySign | Min | Max
type relop = Eq | Neq | Lt | Le | Gt | Ge
type cvt = ToInt32S | ToInt32U | ToInt64S | ToInt64U | ToIntCast
| ToFloat32 | ToFloat64
Expand Down
2 changes: 2 additions & 0 deletions ml-proto/src/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ rule token = parse
| "mul."(fxx as t) { BINARY (floatop t F32.Mul F64.Mul) }
| "div."(fxx as t) { BINARY (floatop t F32.Div F64.Div) }
| "copysign."(fxx as t) { BINARY (floatop t F32.CopySign F64.CopySign) }
| "min."(fxx as t) { BINARY (floatop t F32.Min F64.Min) }
| "max."(fxx as t) { BINARY (floatop t F32.Max F64.Max) }

| "eq."(ixx as t) { COMPARE (intop t I32.Eq I64.Eq) }
| "neq."(ixx as t) { COMPARE (intop t I32.Neq I64.Neq) }
Expand Down

0 comments on commit d072c59

Please sign in to comment.