def less_bit

stelliferous@0.0.2.0 · math_compare.bend:15

import stelliferous@0.0.2.0/math_compare.bend as MathCompare
import Base

15# Magnitudes fit in 31 bits, so the top bit of their difference is the
16# unsigned comparison. Reverse it for negatives and handle opposite signs.
17def less_bit(+left: U32,+right: U32) -> U32:
18  +a = U32.and(left,2147483647)
19  +b = U32.and(right,2147483647)
20  +negative = U32.shrn(left,31n)
21  +different = U32.shrn(U32.xor(left,right),31n)
22  +below = U32.shrn((a - b : U32),31n)
23  +above = U32.shrn((b - a : U32),31n)
24  +same = U32.xor(below,U32.and(negative,U32.xor(below,above)))
25  U32.and(U32.xor(same,U32.and(different,U32.xor(same,negative))),nonzero(U32.or(a,b)))

Uses (7)

Used by (2)