Merge pull request #1216 from ajbeamon/fix-python-singlefloat-with-int
Python: creating a SingleFloat with an integer didn't work.
This commit is contained in:
commit
c8b9c998e9
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -20,6 +20,8 @@ Performance
|
|||
Fixes
|
||||
-----
|
||||
|
||||
* Python: Creating a ``SingleFloat`` for the tuple layer didn't work with integers. `(PR #1216) <https://github.com/apple/foundationdb/pull/1216>`_
|
||||
|
||||
Status
|
||||
------
|
||||
|
||||
|
|
Loading…
Reference in New Issue