Skip to content

Commit

Permalink
Check for interger divisions and cast them to double in printer.
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquinffernandez committed Apr 20, 2023
1 parent 4fa29df commit c76b250
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/mmoc/util/visitors/expression_printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "expression_printer.h"

#include <iomanip>
#include <sstream>

#include <ast/ast_builder.h>
Expand All @@ -27,6 +28,7 @@
#include <util/error.h>
#include <util/model_config.h>
#include <util/util.h>
#include <util/visitors/is_constant_expression.h>

namespace MicroModelica {
using namespace IR;
Expand Down Expand Up @@ -118,7 +120,7 @@ string ExpressionPrinter::foldTraverseElement(AST_Expression exp)
break;
}
case EXPREAL:
buffer << exp->getAsReal()->val();
buffer << std::scientific << exp->getAsReal()->val();
break;
case EXPSTRING:
buffer << exp->getAsString()->str();
Expand Down Expand Up @@ -163,9 +165,10 @@ string ExpressionPrinter::foldTraverseElement(string l, string r, BinOpType bot)
case BINOPSUB:
buffer << l << "-" << r;
break;
case BINOPDIV:
buffer << l << "/" << r;
break;
case BINOPDIV: {
IsConstantExpression constant_exp(true, true);
buffer << l << "/" << ((constant_exp.apply(_right)) ? "(double)" : "") << r;
} break;
case BINOPMULT:
buffer << l << "*" << r;
break;
Expand Down

0 comments on commit c76b250

Please sign in to comment.