Opened 7 years ago
Last modified 7 years ago
#4890 new defect
strange power — at Initial Version
Reported by: | Vitalij Ruge | Owned by: | somebody |
---|---|---|---|
Priority: | high | Milestone: | Future |
Component: | Backend | Version: | |
Keywords: | Cc: | Francesco Casella, Willi Braun |
Description
the following simple model create for simple power operation
model pow_test Real x = time^p; parameter Real p = 1; end pow_test;
about 60 lines C-Code:
/* equation index: 2 type: SIMPLE_ASSIGN x = time ^ p */ void pow_test_eqFunction_2(DATA *data, threadData_t *threadData) { TRACE_PUSH const int equationIndexes[2] = {1,2}; modelica_real tmp0; modelica_real tmp1; modelica_real tmp2; modelica_real tmp3; modelica_real tmp4; modelica_real tmp5; modelica_real tmp6; tmp0 = data->localData[0]->timeValue; tmp1 = data->simulationInfo->realParameter[0]; if(tmp0 < 0.0 && tmp1 != 0.0) { tmp3 = modf(tmp1, &tmp4); if(tmp3 > 0.5) { tmp3 -= 1.0; tmp4 += 1.0; } else if(tmp3 < -0.5) { tmp3 += 1.0; tmp4 -= 1.0; } if(fabs(tmp3) < 1e-10) tmp2 = pow(tmp0, tmp4); else { tmp6 = modf(1.0/tmp1, &tmp5); if(tmp6 > 0.5) { tmp6 -= 1.0; tmp5 += 1.0; } else if(tmp6 < -0.5) { tmp6 += 1.0; tmp5 -= 1.0; } if(fabs(tmp6) < 1e-10 && ((unsigned long)tmp5 & 1)) { tmp2 = -pow(-tmp0, tmp3)*pow(tmp0, tmp4); } else { throwStreamPrint(threadData, "%s:%d: Invalid root: (%g)^(%g)", __FILE__, __LINE__, tmp0, tmp1); } } } else { tmp2 = pow(tmp0, tmp1); } if(isnan(tmp2) || isinf(tmp2)) { throwStreamPrint(threadData, "%s:%d: Invalid root: (%g)^(%g)", __FILE__, __LINE__, tmp0, tmp1); } data->localData[0]->realVars[0] /* x variable */ = tmp2; TRACE_POP }
related commits:
https://github.com/OpenModelica/OMCompiler/commit/63d57dd2ca84c3e72641edba77fde0494bc56b73
https://github.com/OpenModelica/OMCompiler/commit/cb732fc280ac2d8940713d8a104c18952a0634da
Note:
See TracTickets
for help on using tickets.