[fixedTools] make sure fixedToFloat function returns float on both python 2 and 3

This commit is contained in:
Cosimo Lupo 2015-07-24 16:46:21 +01:00
parent 4bfbdc8852
commit d7d59c527d
2 changed files with 5 additions and 1 deletions

View File

@ -26,7 +26,7 @@ def fixedToFloat(value, precisionBits):
hi = value + eps
# If the range of valid choices spans an integer, return the integer.
if int(lo) != int(hi):
return round(value)
return float(round(value))
fmt = "%.8f"
lo = fmt % lo
hi = fmt % hi

View File

@ -33,6 +33,10 @@ class FixedToolsTest(unittest.TestCase):
self.assertEqual(-16384, floatToFixed(-1, 14))
self.assertEqual(0, floatToFixed(0, 14))
def test_fixedToFloat_return_float(self):
value = fixedToFloat(16384, 14)
self.assertIsInstance(value, float)
if __name__ == "__main__":
unittest.main()