avance
This commit is contained in:
parent
cc4d92205f
commit
968f4b16e8
|
|
@ -9,7 +9,8 @@ primitives to suit maths conventions.
|
|||
(** Sign function
|
||||
@param x integer
|
||||
*)
|
||||
let sign x = 0
|
||||
let sign x =
|
||||
if x >= 0 then 1 else -1;;
|
||||
|
||||
(* Integer quotient implementation ; main use is in case of quotient
|
||||
of an integer by a natural number.
|
||||
|
|
@ -20,7 +21,10 @@ let sign x = 0
|
|||
@param a dividend
|
||||
@param b natural number you divide by.
|
||||
*)
|
||||
let quot a b = 0
|
||||
let quot a b =
|
||||
match sign a = -1 && a mod b <> 0 with
|
||||
true -> a/b - 1
|
||||
| _ -> (a/b);;
|
||||
|
||||
(* Integer modulo implementations. Negative case need be taken into
|
||||
account ; representant is expected non-negative. This is not OCAML
|
||||
|
|
@ -35,7 +39,10 @@ let quot a b = 0
|
|||
@param a input integer
|
||||
@param b moduli a natural number.
|
||||
*)
|
||||
let modulo a b = 0
|
||||
let modulo a b =
|
||||
match sign a = -1 && a mod b != 0 with
|
||||
true -> a mod b + b
|
||||
| _ -> a mod b;;
|
||||
|
||||
(* Integer modulo implementations. Negative case need be taken into
|
||||
account ; representant is expected non-negative. This is not OCAML
|
||||
|
|
@ -48,4 +55,5 @@ let modulo a b = 0
|
|||
@param a dividend
|
||||
@param b integer you divide by.
|
||||
*)
|
||||
let div a b = (0, 0)
|
||||
|
||||
let div a b = (quot a b, modulo a b);;
|
||||
|
|
|
|||
Loading…
Reference in New Issue