X-Git-Url: https://scm.cri.mines-paristech.fr/git/Faustine.git/blobdiff_plain/a6be79ccb7456a5181561f094c1f2a4f90aadb02..f1f94803668061f90a5ce88bf06ee72bba8e41a5:/interpretor/basic.ml?ds=sidebyside diff --git a/interpretor/basic.ml b/interpretor/basic.ml index 1e56142..ae096af 100644 --- a/interpretor/basic.ml +++ b/interpretor/basic.ml @@ -398,3 +398,39 @@ let basic_smaller : basic -> basic -> basic = basic_larger_than_zero (b2 -~ b1);; +let basic_max : basic -> basic -> basic = + fun b1 -> + fun b2 -> + let compare = basic_larger_than_zero (b1 -~ b2) in + match compare with + | N i -> + if i = 1 then b1 + else if i = 0 then b2 + else raise (Basic_operation "compare result not bool.") + | Vec vec -> + let basics = Array.init vec#size vec#nth in + let sum = basic_to_int (Array.fold_left basic_add Zero basics) in + if sum = vec#size then b1 + else if sum = 0 then b2 + else Error + | Error -> Error + | _ -> raise (Basic_operation "compare result not bool.");; + + +let basic_min : basic -> basic -> basic = + fun b1 -> + fun b2 -> + let compare = basic_larger_than_zero (b1 -~ b2) in + match compare with + | N i -> + if i = 1 then b2 + else if i = 0 then b1 + else raise (Basic_operation "compare result not bool.") + | Vec vec -> + let basics = Array.init vec#size vec#nth in + let sum = basic_to_int (Array.fold_left basic_add Zero basics) in + if sum = vec#size then b2 + else if sum = 0 then b1 + else Error + | Error -> Error + | _ -> raise (Basic_operation "compare result not bool.");;