Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 587cac2

Browse files
niklworsOpenModelica-Hudson
authored andcommitted
fix for division by zero in cpp runtime
Belonging to [master]: - #2114
1 parent e43fc8a commit 587cac2

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

SimulationRuntime/cpp/Core/Math/Functions.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,17 @@ double division (const double &a,const double &b, bool throwEx,const char* text
3939
return a/b ;
4040
else
4141
{
42-
std::string error_msg = "Division by zero: ";
43-
if(throwEx)
44-
throw ModelicaSimulationError(UTILITY,error_msg+string(text));
42+
if(a==0)
43+
{
44+
//LOGGER_WRITE("Division by Zero: Solver will try to handle division by zero with minimu norm for" + string(text), LC_INIT, LL_DEBUG);
45+
return 0;
46+
}
47+
48+
if(throwEx)
49+
throw ModelicaSimulationError(UTILITY,"Division by zero: "+string(text));
4550
else
4651
{
47-
// LOGGER_WRITE("Division: Solver will try to handle division by zero for" + string(text), LC_INIT, LL_DEBUG);
52+
//LOGGER_WRITE("Division: Solver will try to handle division by zero for" + string(text), LC_INIT, LL_DEBUG);
4853
return a;
4954
}
5055
}

0 commit comments

Comments
 (0)