From 060ddfa60ce3379cd1d9785559e57449ae25f333 Mon Sep 17 00:00:00 2001 From: Torsten Sommer Date: Mon, 7 Oct 2024 13:31:23 +0200 Subject: [PATCH] Add fmiAbs() and fmiMax() --- CMakeLists.txt | 4 ---- src/cosimulation.c | 13 ++++++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 35ebcd03..6db01f90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -198,10 +198,6 @@ set_target_properties(${TARGET_NAME} PROPERTIES set_target_properties(${TARGET_NAME} PROPERTIES PREFIX "") set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME ${MODEL_NAME}) -if (UNIX) - target_link_libraries(${TARGET_NAME} m) -endif () - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib) # modelDescription.xml diff --git a/src/cosimulation.c b/src/cosimulation.c index 66703227..5d1f7d71 100644 --- a/src/cosimulation.c +++ b/src/cosimulation.c @@ -1,6 +1,5 @@ #include // for calloc(), free() #include // for DBL_EPSILON -#include // for fabs() #include #include #include @@ -192,17 +191,25 @@ Status reset(ModelInstance* comp) { #define EPSILON (1.0e-5) +static bool fmiAbs(double v) { + return v >= 0 ? v : -v; +} + +static bool fmiMax(double a, double b) { + return (a < b) ? b : a; +} + bool isClose(double a, double b) { if (!isfinite(a) || !isfinite(b)) { return false; } - if (fabs(a - b) <= EPSILON) { + if (fmiAbs(a - b) <= EPSILON) { return true; } - return fabs(a - b) <= EPSILON * fmax(fabs(a), fabs(b)); + return fmiAbs(a - b) <= EPSILON * fmiMax(fmiAbs(a), fmiAbs(b)); } bool invalidNumber(ModelInstance *comp, const char *f, const char *arg, size_t actual, size_t expected) {