Skip to content

Commit 9f08f91

Browse files
committed
Add abs function to OCaml backend, following aa702f2 (rehabilitate abs function in backends, 2022-11-22)
1 parent 6afbd75 commit 9f08f91

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

examples/ocaml/mvalue.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ let m_floor (x : m_value) : m_value =
141141
if x.undefined then m_undef
142142
else { undefined = false; value = floor (x.value +. 0.000001) }
143143

144+
let m_abs (x : m_value) : m_value =
145+
if x.undefined then m_undef
146+
else { undefined = false; value = abs_float x.value }
147+
144148
let m_present (x : m_value) : m_value = if x.undefined then m_zero else m_one
145149

146150
let m_multimax (bound_variable : m_value) (variable_array : m_array)

src/mlang/backend_compilers/bir_to_ocaml.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ let rec generate_ocaml_expr (e : Bir.expression Pos.marked) :
7171
| FunctionCall (InfFunc, [ arg ]) ->
7272
let s, local = generate_ocaml_expr arg in
7373
(Format.asprintf "(m_floor %s)" s, local)
74+
| FunctionCall (AbsFunc, [ arg ]) ->
75+
let se, s = generate_ocaml_expr arg in
76+
(Format.asprintf "(m_abs %s)" se, s)
7477
| FunctionCall (MaxFunc, [ e1; e2 ]) ->
7578
let s1, local1 = generate_ocaml_expr e1 in
7679
let s2, local2 = generate_ocaml_expr e2 in

0 commit comments

Comments
 (0)