Python: creating a SingleFloat with an integer didn't work. Updated the tester to exercise this path.

This commit is contained in:
A.J. Beamon 2019-03-01 09:25:53 -08:00
parent af69ba035a
commit 8669aea22b
3 changed files with 10 additions and 2 deletions

View File

@ -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)

View File

@ -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))

View File

@ -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()