Module Scalar.Integer_comparison

type t =
  1. | Ceq
    (*

    Equal (signed or unsigned - same result)

    *)
  2. | Cne
    (*

    Not equal (signed or unsigned - same result)

    *)
  3. | Clt
    (*

    Less than (signed)

    *)
  4. | Cgt
    (*

    Greater than (signed)

    *)
  5. | Cle
    (*

    Less or equal (signed)

    *)
  6. | Cge
    (*

    Greater or equal (signed)

    *)
  7. | Cult
    (*

    Less than (unsigned)

    *)
  8. | Cugt
    (*

    Greater than (unsigned)

    *)
  9. | Cule
    (*

    Less or equal (unsigned)

    *)
  10. | 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 : t -> t -> bool
val to_string : t -> string
val swap : t -> t
val negate : t -> t
val create : Signedness.t -> lt:bool -> eq:bool -> gt:bool -> (t, bool) result

Creates 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