Skip to content
Snippets Groups Projects

Fix RoundOff problems

Merged Markus Holzer requested to merge holzer/pystencils:RoundOffError into master
Compare and
3 files
+ 6
5
Preferences
Compare changes
Files
3
@@ -441,7 +441,7 @@ class CustomSympyPrinter(CCodePrinter):
def _print_Pow(self, expr):
"""Don't use std::pow function, for small integer exponents, write as multiplication"""
if not expr.free_symbols:
return self._typed_number(expr.evalf(), get_type_of_expression(expr.base))
return self._typed_number(expr.evalf(17), get_type_of_expression(expr.base))
if expr.exp.is_integer and expr.exp.is_number and 0 < expr.exp < 8:
return f"({self._print(sp.Mul(*[expr.base] * expr.exp, evaluate=False))})"
@@ -452,7 +452,7 @@ class CustomSympyPrinter(CCodePrinter):
def _print_Rational(self, expr):
"""Evaluate all rationals i.e. print 0.25 instead of 1.0/4.0"""
res = str(expr.evalf().num)
res = str(expr.evalf(17))
return res
def _print_Equality(self, expr):