import math

sbitfix.set_precision(16, 32)

def test(a, b, value_type=None):
    try:
        b = int(round((b * (1 << a.f))))
        b += 2 ** sbitfix.k if b < 0 else 0
        a = a.v.reveal()
    except AttributeError:
        pass
    try:
        a = a.reveal()
    except AttributeError:
        pass
    import inspect
    print_ln('%s: %s %s %s', inspect.currentframe().f_back.f_lineno, \
             (a ^ cbits(b)).reveal(), a, (b))

aa = 53.21
bb = 142

for a_sign, b_sign in (1, -1), (-1, -1):
    a = a_sign * aa
    b = b_sign * bb

    sa = sbitfix(a)
    sb = sbitfix(b)

    test(sa + sb, a+b)
    test(sa - sb, a-b)
    test(sa * sb, a*b)
    test(sa / sb, a/b)

    test(-sa, -a)

    test(sa + b, a+b)
    test(sa - b, a-b)
    test(sa * b, a*b)
    test(sa / b, a/b)

    test(a + sb, a+b)
    test(a - sb, a-b)
    test(a * sb, a*b)
    test(a / sb, a/b)

a = 126
b = 125
sa = sbitfix(a)
sb = sbitfix(b)

test(sa < sb, int(a<b))
test(sa < sa, int(a<a))
test(sa < sa + sbitfix(1), int(a<a+1))
test(-sa < sa, int(-a<a))
test(-sb < sb, int(-b<b))
test(sa < -sb, int(a<-b))
test(-sa < -sb, int(-a<-b))
test(sa > sb, int(a>b))
test(sa <= sb, int(a<=b))
test(sa >= sb, int(a>=b))
test(sa == sb, int(a==b))
test(sa != sb, int(a!=b))
test(sa != sa, int(a!=a))

test(sa < b, int(a<b))
test(sa < a, int(a<a))
test(sa < a + sbitfix(1), int(a<a+1))
test(-sa < a, int(-a<a))
test(-sb < b, int(-b<b))
test(sa < -b, int(a<-b))
test(-sa < -b, int(-a<-b))
test(sa > b, int(a>b))
test(sa <= b, int(a<=b))
test(sa >= b, int(a>=b))
test(sa == b, int(a==b))
test(sa != b, int(a!=b))
test(sa != a, int(a!=a))

test(a < sb, int(a<b))
test(a < sa, int(a<a))
test(a < sa + sbitfix(1), int(a<a+1))
test(-a < sa, int(-a<a))
test(-b < sb, int(-b<b))
test(a < -sb, int(a<-b))
test(-a < -sb, int(-a<-b))
test(a > sb, int(a>b))
test(a <= sb, int(a<=b))
test(a >= sb, int(a>=b))
test(a == sb, int(a==b))
test(a != sb, int(a!=b))
test(a != sa, int(a!=a))
