def number_inc_gt(typechar, loopvar, stop, step, sgn): """ Increase number and check if it exceeds a limit. """ if sgn == 0: return False if typechar in ('#', '!'): fp_left = fp.from_bytes(loopvar).iadd(step) loopvar[:] = fp_left.to_bytes() return fp_left.gt(stop) if sgn > 0 else stop.gt(fp_left) else: int_left = vartypes.integer_to_int_signed(vartypes.bytes_to_integer(loopvar)) + step loopvar[:] = vartypes.integer_to_bytes(vartypes.int_to_integer_signed(int_left)) return int_left > stop if sgn > 0 else stop > int_left
def number_inc_gt(typechar, loopvar, stop, step, sgn): """ Increase number and check if it exceeds a limit. """ if sgn == 0: return False if typechar in ('#', '!'): fp_left = fp.from_bytes(loopvar).iadd(step) loopvar[:] = fp_left.to_bytes() return fp_left.gt(stop) if sgn > 0 else stop.gt(fp_left) else: int_left = vartypes.sint_to_value(loopvar) + step loopvar[:] = vartypes.value_to_sint(int_left) return int_left > stop if sgn > 0 else stop > int_left
return oct(vartypes.integer_to_int_unsigned(inp))[1:] def integer_to_str_hex(inp): """ Convert integer to str in hex representation. """ return hex(vartypes.integer_to_int_unsigned(inp))[2:].upper() # floating point to string # for to_str # for numbers, tab and LF are whitespace number_whitespace = ' \t\n' # string representations Single.lim_top = from_bytes(bytearray('\x7f\x96\x18\x98')) # 9999999, highest float less than 10e+7 Single.lim_bot = from_bytes(bytearray('\xff\x23\x74\x94')) # 999999.9, highest float less than 10e+6 Single.type_sign, Single.exp_sign = '!', 'E' Double.lim_top = from_bytes(bytearray('\xff\xff\x03\xbf\xc9\x1b\x0e\xb6')) # highest float less than 10e+16 Double.lim_bot = from_bytes(bytearray('\xff\xff\x9f\x31\xa9\x5f\x63\xb2')) # highest float less than 10e+15 Double.type_sign, Double.exp_sign = '#', 'D' def just_under(n_in): """ Return the largest floating-point number less than the given value. """ # decrease mantissa by one return n_in.__class__(n_in.neg, n_in.man - 0x100, n_in.exp) def get_digits(num, digits, remove_trailing=True): """ Get the digits for an int. """
def integer_to_str_hex(inp): """ Convert integer to str in hex representation. """ return hex(vartypes.integer_to_int_unsigned(inp))[2:].upper() # floating point to string # for to_str # for numbers, tab and LF are whitespace number_whitespace = ' \t\n' # string representations Single.lim_top = from_bytes( bytearray('\x7f\x96\x18\x98')) # 9999999, highest float less than 10e+7 Single.lim_bot = from_bytes( bytearray('\xff\x23\x74\x94')) # 999999.9, highest float less than 10e+6 Single.type_sign, Single.exp_sign = '!', 'E' Double.lim_top = from_bytes(bytearray( '\xff\xff\x03\xbf\xc9\x1b\x0e\xb6')) # highest float less than 10e+16 Double.lim_bot = from_bytes(bytearray( '\xff\xff\x9f\x31\xa9\x5f\x63\xb2')) # highest float less than 10e+15 Double.type_sign, Double.exp_sign = '#', 'D' def just_under(n_in): """ Return the largest floating-point number less than the given value. """ # decrease mantissa by one return n_in.__class__(n_in.neg, n_in.man - 0x100, n_in.exp)