Integer comparisons via bit operations

No, that's not about performance.

I found a bug in my "standard library free" implementation of "func <" used in a side project. The code in question looks like:

    static func < (a: XUInt64, b: XUInt64) -> XBool {
        let c = a - b
        if case .i = c.tuple.elements.7.bits.elements.7 {
            return .true
        }
        return .false
    }

As written it doesn't handle overflows correctly, and the listed "allowed" primitive operations is about all I have available at my disposal.


OTOH, I could just use a loop and scan through the bit string from the most significant to the least significant bits and find the first difference. Will give that a try as well.