Skip to content

Commit

Permalink
Fix nasa#95, add local isnan, isfinite macros
Browse files Browse the repository at this point in the history
In case the system-provided math.h header does not provide an
implementation if isnan or isfinite, use a local workaround.
  • Loading branch information
jphickey committed Aug 16, 2023
1 parent feb5bf5 commit 6b78bdc
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions fsw/src/lc_watch.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,27 @@
#include "lc_perfids.h"
#include "lc_platform_cfg.h"

#include <float.h>
#include <math.h>

/*
* 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 */
Expand Down

0 comments on commit 6b78bdc

Please sign in to comment.