From 6b78bdc18b54face06c1be633e6b9daf75a4de73 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Wed, 16 Aug 2023 08:35:57 -0400 Subject: [PATCH] Fix #95, add local isnan, isfinite macros In case the system-provided math.h header does not provide an implementation if isnan or isfinite, use a local workaround. --- fsw/src/lc_watch.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/fsw/src/lc_watch.c b/fsw/src/lc_watch.c index a8b0027..b5245ec 100644 --- a/fsw/src/lc_watch.c +++ b/fsw/src/lc_watch.c @@ -32,8 +32,27 @@ #include "lc_perfids.h" #include "lc_platform_cfg.h" +#include #include +/* + * An ISO-compliant math.h header should provide "isnan" and "isfinite" macros + * as they are dicatated by C99. However some C libraries still in use are not + * fully compliant. If these macros are not defined, define a substitute here. + * + * Note these are not ideal/complete implementations of these macros, but they + * are OK based on the way they are used inside this source file. Use caution if + * changing the code using these, notably: + * - isfinite assumes float type + * - both macros evaluate the argument twice - use only with a simple variable + */ +#ifndef isnan +#define isnan(x) ((x) != (x)) +#endif +#ifndef isfinite +#define isfinite(x) ((x) > -FLT_MAX && (x) < FLT_MAX) +#endif + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ /* LC_GetHashTableIndex() - convert messageID to hash table index */