Seems like SymPy makes it pretty easy to do the opposite - convert all floats to ints, but I'm curious how to do the reverse?
The specific problem I'm running into is with the RustCodeGen spitting out expressions with mixed f64/int types, which makes the compiler unhappy.
Any suggestions on ways to get around this programmatically would be greatly appreciated!
Simple example:
>> variables = [symbols('x1')]
>> expression = 'x1 % 0.5'
>> expr = parse_expr(expression, evaluate=0)
>> print(expr) # Notice it has injected a multiply by 2
0.5*(Mod(2*x1, 1))
>> CG = RustCodeGen()
>> routine = CG.routine("", expr, variables, {})
>> CG._call_printer(routine)
['let out1 = 0.5*(2*x1 - (2*x1).floor());\n', 'out1', '\n']
which doesn't compile:
error[E0277]: cannot multiply `{integer}` by `{float}`
--> src/main.rs:5:22
|
5 | let out1 = 0.5*(2*x1 - (2*x1).floor());
| ^ no implementation for `{integer} * {float}`