diff --git a/bindings/bindingtester/tests/test_util.py b/bindings/bindingtester/tests/test_util.py index 5e3c406aa1..f731ed6922 100644 --- a/bindings/bindingtester/tests/test_util.py +++ b/bindings/bindingtester/tests/test_util.py @@ -60,7 +60,12 @@ class RandomGenerator(object): sign = -1 if random.random() < 0.5 else 1 exponent = random.randint(-(1 << (exp_bits - 1)) - 10, (1 << (exp_bits - 1) - 1)) mantissa = random.random() - return sign * math.pow(2, exponent) * mantissa + + result = sign * math.pow(2, exponent) * mantissa + if random.random() < 0.05: + result = float(int(result)) + + return result def random_tuple(self, max_size, incomplete_versionstamps=False): size = random.randint(1, max_size) diff --git a/bindings/python/fdb/tuple.py b/bindings/python/fdb/tuple.py index c05f1c2659..62fe258035 100644 --- a/bindings/python/fdb/tuple.py +++ b/bindings/python/fdb/tuple.py @@ -79,7 +79,7 @@ class SingleFloat(object): self.value = ctypes.c_float(value).value elif isinstance(value, ctypes.c_float): self.value = value.value - elif isinstance(value, six.integertypes): + elif isinstance(value, six.integer_types): self.value = ctypes.c_float(value).value else: raise ValueError("Incompatible type for single-precision float: " + repr(value)) diff --git a/bindings/python/tests/tester.py b/bindings/python/tests/tester.py index 6aefe7ebd7..1001dfb717 100644 --- a/bindings/python/tests/tester.py +++ b/bindings/python/tests/tester.py @@ -21,6 +21,7 @@ import ctypes +import math import sys import os import struct @@ -498,6 +499,8 @@ class Tester: elif inst.op == six.u("ENCODE_FLOAT"): f_bytes = inst.pop() f = struct.unpack(">f", f_bytes)[0] + if not math.isnan(f) and not math.isinf(f) and not f == -0.0 and f == int(f): + f = int(f) inst.push(fdb.tuple.SingleFloat(f)) elif inst.op == six.u("ENCODE_DOUBLE"): d_bytes = inst.pop()