Skip to content
Snippets Groups Projects
Commit df34b3d0 authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Fix bug where (1/2) is literally passed to C++, which results in 0 due to integever division

parent f1022a6c
No related branches found
No related tags found
No related merge requests found
......@@ -253,16 +253,17 @@ def expr_to_cpp(
if isinstance(expr, sp.Symbol):
# Must be part of local variables.
assert expr in cpp.function_args
return str(expr)
elif isinstance(expr, sp.Number):
# Will be turned into a literal.
pass
# The number can also be something like (1/2), where "1 / 2" would be 0 in C++.
# So we pre-evaluate these constants in Python, and pass the result literal to C++.
return str(eval(str(expr)))
else:
raise TypeError(f"Got expr {expr} of type {type(expr)}")
return str(expr)
else:
# Non-leaf
print(f"{indent}Node: {expr}")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment