diff --git a/modcc/symdiff.cpp b/modcc/symdiff.cpp index 27c2ff2bbba0c345d53ea570ce190683b650311f..03b3d4f20448b086032ca912421afa37c7f57009 100644 --- a/modcc/symdiff.cpp +++ b/modcc/symdiff.cpp @@ -430,6 +430,9 @@ public: else if (expr_value(rhs)==1) { result_ = e->lhs()->clone(); } + else if (is_number(rhs)) { + result_ = make_expression<MulBinaryExpression>(loc, std::move(lhs), make_expression<NumberExpression>(loc, 1.0/expr_value(rhs))); + } else { result_ = make_expression<DivBinaryExpression>(loc, std::move(lhs), std::move(rhs)); } diff --git a/test/unit-modcc/test_printers.cpp b/test/unit-modcc/test_printers.cpp index d99d6c8b1e1e066912c1e1af36612d50cae7b845..fa8bd3ab608184fa8e8dae6658823386e600ddd2 100644 --- a/test/unit-modcc/test_printers.cpp +++ b/test/unit-modcc/test_printers.cpp @@ -200,7 +200,7 @@ TEST(CPrinter, proc_body_const) { TEST(CPrinter, proc_body_inlined) { const char* expected = - "r_9_=s2[i_]/3;\n" + "r_9_=s2[i_]*0.33333333333333331;\n" "r_8_=s1[i_]+2;\n" "if(s1[i_]==3){\n" " r_7_=2*r_8_;\n"