X-Git-Url: https://scm.cri.mines-paristech.fr/git/Faustine.git/blobdiff_plain/8c48d01c4b78dba6159c13438b06cb7e07a1f338..de2caab6239e9119fa066debce669e33e514784a:/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.");;