from Compiler.GC.types import sbitfix, cbits import math sbitfix.set_precision(16, 32) def test(a, b, value_type=None): try: b = int(round((b * (1 << a.f)))) if b < 0: b += 2 ** sbitfix.k 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 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, 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 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))