Skip to content

Commit

Permalink
Add fmiAbs() and fmiMax()
Browse files Browse the repository at this point in the history
  • Loading branch information
t-sommer committed Oct 7, 2024
1 parent 0506f86 commit 060ddfa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions src/cosimulation.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <stdlib.h> // for calloc(), free()
#include <float.h> // for DBL_EPSILON
#include <math.h> // for fabs()
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 060ddfa

Please sign in to comment.