Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compyle/tests/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def test_literal_to_float():
# Given/When/Then
assert literal_to_float(1.0) == '1.0f'
assert literal_to_float(1.01325e5) == '101325.0f'
assert literal_to_float(1.01325e-5) == '1.01325f-05'
assert literal_to_float(1.01325e-5) == '1.01325e-05f'
assert literal_to_float(1.01325E5) == '101325.0f'
assert literal_to_float(1.01325e-05) == '1.01325f-05'
assert literal_to_float(1.0e-5) == '1.0f-05'
assert literal_to_float(1.01325e-05) == '1.01325e-05f'
assert literal_to_float(1.0e-5) == '1e-05f'
assert literal_to_float(1.0, use_double=True) == '1.0'
assert literal_to_float(10, use_double=True) == '10'
assert literal_to_float(1.01325e5, use_double=True) == '101325.0'
Expand Down
11 changes: 1 addition & 10 deletions compyle/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,7 @@ def literal_to_float(value, use_double=False):
"""Convert numerical value to a string in 32 bit floating point notation.
"""
if isinstance(value, float) and not use_double:
vs = str(value)
if 'e' in vs:
e_idx = vs.find('e')
mantissa = vs[:e_idx]
if '.' not in mantissa:
return mantissa + '.0f' + vs[(e_idx + 1):]
else:
return vs.replace('e', 'f')
else:
return vs + 'f'
return str(value) + 'f'
else:
return str(value)

Expand Down
Loading