diff options
| author | Pierre-Marie Pédrot | 2020-12-11 13:18:45 +0100 |
|---|---|---|
| committer | Pierre-Marie Pédrot | 2020-12-11 13:18:45 +0100 |
| commit | 6ce1c1d1b661a6cbb4a415f9f7960b2ff53b32c5 (patch) | |
| tree | 5049e6475c9b554146264e64b6d8efb7d01b8ace /kernel/uint63_31.ml | |
| parent | d40ef2467b8e84115b027200aff61becdd899f57 (diff) | |
| parent | f4dcd1d9f696972e7cbdaa8d70e5abb1a18820ef (diff) | |
Merge PR #13540: Clean support of primitive integers
Reviewed-by: ppedrot
Reviewed-by: proux01
Diffstat (limited to 'kernel/uint63_31.ml')
| -rw-r--r-- | kernel/uint63_31.ml | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/kernel/uint63_31.ml b/kernel/uint63_31.ml index 5b2d934b5d..988611df3e 100644 --- a/kernel/uint63_31.ml +++ b/kernel/uint63_31.ml @@ -23,9 +23,10 @@ let one = Int64.one (* conversion from an int *) let mask63 i = Int64.logand i maxuint63 -let of_int i = Int64.of_int i +let of_int i = mask63 (Int64.of_int i) let to_int2 i = (Int64.to_int (Int64.shift_right_logical i 31), Int64.to_int i) -let of_int64 i = i +let of_int64 = mask63 +let to_int64 i = i let to_int_min n m = if Int64.(compare n (of_int m)) < 0 then Int64.to_int n else m @@ -41,13 +42,6 @@ let hash i = (* conversion of an uint63 to a string *) let to_string i = Int64.to_string i -let of_string s = - let i64 = Int64.of_string s in - if Int64.compare Int64.zero i64 <= 0 - && Int64.compare i64 maxuint63 <= 0 - then i64 - else raise (Failure "Int63.of_string") - (* Compiles an unsigned int to OCaml code *) let compile i = Printf.sprintf "Uint63.of_int64 (%LiL)" i @@ -72,12 +66,12 @@ let l_xor x y = Int64.logxor x y (* addition of int63 *) let add x y = mask63 (Int64.add x y) -let addcarry x y = add (add x y) Int64.one +let addcarry x y = mask63 Int64.(add (add x y) one) (* subtraction *) let sub x y = mask63 (Int64.sub x y) -let subcarry x y = sub (sub x y) Int64.one +let subcarry x y = mask63 Int64.(sub (sub x y) one) (* multiplication *) let mul x y = mask63 (Int64.mul x y) |
