Skip to content

Commit

Permalink
- integer-function should now work according to modelica specificatio…
Browse files Browse the repository at this point in the history
…n (cpp runtime)
  • Loading branch information
Marcus Walther committed Aug 27, 2015
1 parent e683e8b commit a783b5e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Compiler/Template/CodegenCppCommon.tpl
Expand Up @@ -1753,7 +1753,7 @@ template daeExpCall(Exp call, Context context, Text &preExp /*BUFP*/, Text &varD
case CALL(path=IDENT(name="integer"), expLst={inExp,index}) then
let exp = daeExp(inExp, context, &preExp, &varDecls, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
// let constIndex = daeExp(index, context, &preExp /*BUFC*/, &varDecls /*BUFD*/,simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace,useFlatArrayNotation)
'boost::numeric_cast<int>(<%exp%>)'
'integer(<%exp%>)'


case CALL(path=IDENT(name="floor"), expLst={inExp,index}, attr=CALL_ATTR(ty = ty)) then
Expand All @@ -1775,7 +1775,7 @@ template daeExpCall(Exp call, Context context, Text &preExp /*BUFP*/, Text &varD

case CALL(path=IDENT(name="integer"), expLst={inExp}) then
let exp = daeExp(inExp, context, &preExp /*BUFC*/, &varDecls /*BUFD*/,simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
'boost::numeric_cast<int>(<%exp%>)'
'integer(<%exp%>)'

case CALL(path=IDENT(name="modelica_mod_int"), expLst={e1,e2}) then
let var1 = daeExp(e1, context, &preExp, &varDecls,simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
Expand Down
12 changes: 11 additions & 1 deletion SimulationRuntime/cpp/Include/Core/Math/Functions.h
Expand Up @@ -138,6 +138,16 @@ inline static int round (const double &n)
return (fabs(n)-floor(fabs(n)) < 0.5) ? (int)(sgn(n)*floor(fabs(n))) : (int)(sgn(n)*ceil(fabs(n)));
}

/// Modelica integer function
inline static int integer (const double &n)
{
int castValue = boost::numeric_cast<int>(n);
if(n < castValue)
return castValue - 1;
else
return castValue;
}

/// Horner-Schema (William George Horner)
inline double Phorner(double &x, int degree_P, double* P)
{
Expand Down Expand Up @@ -258,4 +268,4 @@ struct floatCompare {
}

};
/** @} */ // end of math
/** @} */ // end of math

0 comments on commit a783b5e

Please sign in to comment.