Module Scalar.Integer_comparison
type t = | Ceq(*Equal (signed or unsigned - same result)
*)| Cne(*Not equal (signed or unsigned - same result)
*)| Clt(*Less than (signed)
*)| Cgt(*Greater than (signed)
*)| Cle(*Less or equal (signed)
*)| Cge(*Greater or equal (signed)
*)| Cult(*Less than (unsigned)
*)| Cugt(*Greater than (unsigned)
*)| Cule(*Less or equal (unsigned)
*)| Cuge(*Greater or equal (unsigned)
*)
Integer comparison operators supporting both signed and unsigned comparisons.
The first six operators (Ceq through Cge) perform signed comparisons, treating the most significant bit as a sign bit in two's complement representation.
The last four operators (Cult through Cuge) perform unsigned comparisons, treating all bits as magnitude. This means negative signed integers are compared as large positive values:
- In 8-bit: -1 (0xFF) is treated as 255, thus -1 > 127 unsigned
- In 32-bit: -1 (0xFFFFFFFF) is treated as 4294967295
Examples with 8-bit integers:
- Signed: -128 < -1 < 0 < 1 < 127
- Unsigned: 0 < 1 < 127 < 128 (which is -128 signed) < 255 (which is -1 signed)
val equal :
Ocaml_typing.Scalar.Integer_comparison.t ->
Ocaml_typing.Scalar.Integer_comparison.t ->
boolval to_string : Ocaml_typing.Scalar.Integer_comparison.t -> stringval create :
Ocaml_typing.Scalar.Signedness.t ->
lt:bool ->
eq:bool ->
gt:bool ->
(Ocaml_typing.Scalar.Integer_comparison.t, bool) Stdlib.resultCreates a comparison operator from the behavior that should happen in each condition, with the given signedness. If every case is the same, returns Error of that case