Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 66.7% 2 / 0 / 3
Functions: -% 0 / 1 / 1
Branches: 50.0% 1 / 0 / 2

OMCompiler/SimulationRuntime/c/util/division.h
Line Branch Exec Source
1 /*
2 * This file belongs to the OpenModelica Run-Time System
3 *
4 * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC), c/o Linköpings
5 * universitet, Department of Computer and Information Science, SE-58183 Linköping, Sweden. All rights
6 * reserved.
7 *
8 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THE BSD NEW LICENSE OR THE
9 * AGPL VERSION 3 LICENSE OR THE OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8. ANY
10 * USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S
11 * ACCEPTANCE OF THE BSD NEW LICENSE OR THE OSMC PUBLIC LICENSE OR THE AGPL
12 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
13 *
14 * The OpenModelica software and the OSMC (Open Source Modelica Consortium) Public License
15 * (OSMC-PL) are obtained from OSMC, either from the above address, from the URLs:
16 * http://www.openmodelica.org or https://github.com/OpenModelica/ or
17 * http://www.ida.liu.se/projects/OpenModelica, and in the OpenModelica distribution. GNU
18 * AGPL version 3 is obtained from: https://www.gnu.org/licenses/licenses.html#GPL. The BSD NEW
19 * License is obtained from: http://www.opensource.org/licenses/BSD-3-Clause.
20 *
21 * This program is distributed WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY
23 * SET FORTH IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF
24 * OSMC-PL.
25 *
26 */
27
28
29 #ifndef DIVISION_H
30 #define DIVISION_H
31
32 #include <math.h>
33 #include "../openmodelica.h"
34 #include "omc_error.h"
35
36 /* #define CHECK_NAN */
37 #ifdef CHECK_NAN
38 #define DIVISION(a,b,c) (((b) != 0) ? (isnan_error(((a) / (b)), c, __FILE__, __LINE__)) : ((a) / division_error(threadData, b, c, __FILE__, __LINE__)))
39 #else
40 #define DIVISION(a,b,c) (((b) != 0) ? ((a) / (b)) : ((a) / division_error_time(threadData, b, c, data->localData[0]->timeValue, __FILE__, __LINE__,data->simulationInfo->noThrowDivZero?1:0)))
41 #endif
42
43 #if defined(__GNUC__) || defined(__clang__)
44 /* The slow path's arguments are only loaded on it. */
45 #define DIVISION_SIM(a,b,msg,equation) ({ \
46 const modelica_real omc_div_a_ = (a), omc_div_b_ = (b), omc_div_r_ = omc_div_a_ / omc_div_b_; \
47 OMC_LIKELY(isfinite(omc_div_r_)) ? omc_div_r_ : __OMC_DIV_SIM_SLOW(threadData, omc_div_a_, omc_div_b_, msg, equationIndexes, \
48 data->simulationInfo->noThrowDivZero, data->localData[0]->timeValue, initial()); })
49 #else
50 #define DIVISION_SIM(a,b,msg,equation) (__OMC_DIV_SIM(threadData, a, b, msg, equationIndexes, data->simulationInfo->noThrowDivZero, data->localData[0]->timeValue, initial()))
51 #endif
52
53 #define DIVISIONNOTIME(a,b,c) (((b) != 0) ? ((a) / (b)) : ((a) / division_error(threadData, b, c, __FILE__, __LINE__)))
54
55 modelica_real division_error_equation_time(threadData_t*, modelica_real a, modelica_real b, const char *division_str, const int *indexes, modelica_real time, modelica_boolean noThrow);
56 modelica_real division_error_time(threadData_t*,modelica_real b, const char* division_str, modelica_real time, const char* file, long line, modelica_boolean noThrow);
57 modelica_real division_error(threadData_t*,modelica_real b, const char* division_str, const char* file, long line);
58 modelica_real isnan_error(threadData_t*,modelica_real b, const char* division_str, const char* file, long line);
59 int valid_number(double a);
60
61 modelica_real __OMC_DIV_SIM_SLOW(threadData_t *threadData, const modelica_real a, const modelica_real b, const char *msg, const int *equationIndexes, modelica_boolean noThrowDivZero, const modelica_real time_, const modelica_boolean initial_) OMC_COLD;
62
63 static inline modelica_real __OMC_DIV_SIM(threadData_t *threadData, const modelica_real a, const modelica_real b, const char *msg, const int *equationIndexes, modelica_boolean noThrowDivZero, const modelica_real time_, const modelica_boolean initial_)
64 {
65 162156 const modelica_real res = a/b;
66
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 162156 times.
162156 if(OMC_LIKELY(isfinite(res)))
67 return res;
68 ✗ return __OMC_DIV_SIM_SLOW(threadData, a, b, msg, equationIndexes, noThrowDivZero, time_, initial_);
69 }
70
71 #endif
72