.true. when a < b with both operands read as unsigned 64-bit
values.
Fortran’s < compares the two’s-complement patterns as signed, so it
reports -huge(0_int64) - 1_int64 (that is, 263 unsigned) as less than
zero. Flipping the sign bit of both operands maps the unsigned order
onto the signed order exactly, which is why this is a comparison of
ieor(a, SIGN_BIT) against ieor(b, SIGN_BIT) and not a sequence of
sign tests.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=int64), | intent(in) | :: | a | |||
| integer(kind=int64), | intent(in) | :: | b |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=int64), | private, | parameter | :: | SIGN_BIT | = | ishft(1_int64, 63) |
pure function u64_less(a, b) result(r) !! `.true.` when `a < b` with both operands read as unsigned 64-bit !! values. !! !! Fortran's `<` compares the two's-complement patterns as signed, so it !! reports `-huge(0_int64) - 1_int64` (that is, 2**63 unsigned) as *less than* !! zero. Flipping the sign bit of both operands maps the unsigned order !! onto the signed order exactly, which is why this is a comparison of !! `ieor(a, SIGN_BIT)` against `ieor(b, SIGN_BIT)` and not a sequence of !! sign tests. integer(int64), intent(in) :: a integer(int64), intent(in) :: b logical :: r integer(int64), parameter :: SIGN_BIT = ishft(1_int64, 63) r = ieor(a, SIGN_BIT) < ieor(b, SIGN_BIT) end function u64_less