mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: replace IS_FP_SAME macro by inline function
No reason to keep this as a macro - a function is easier to read, type safe and easier to debug. Moreover, give it the more appropriate name "nearly_equal()". After all, it precisely does NOT check floating points for equality. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
5db4a95a26
commit
61701509b0
9 changed files with 28 additions and 25 deletions
|
@ -5,6 +5,7 @@
|
|||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
|
||||
// shared generic definitions and macros
|
||||
// mostly about strings, but a couple of math macros are here as well
|
||||
|
@ -22,13 +23,15 @@
|
|||
(void) (&_max1 == &_max2); \
|
||||
_max1 > _max2 ? _max1 : _max2; })
|
||||
|
||||
#define IS_FP_SAME(_a, _b) (fabs((_a) - (_b)) <= 0.000001 * MAX(fabs(_a), fabs(_b)))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static inline bool nearly_equal(double a, double b)
|
||||
{
|
||||
return fabs(a - b) <= 1e-6 * fmax(fabs(a), fabs(b));
|
||||
}
|
||||
|
||||
static inline bool nearly_0(double fp)
|
||||
{
|
||||
return fabs(fp) <= 1e-6;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue