mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: don't use relative precision when comparing to 0
The FP_IS_SAME macro uses a relative precision to compare floating points. This fails when comparing to 0. Therefore, use an absolute precision in this case. Implement as an inline function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
2ae7f3cf6c
commit
5db4a95a26
3 changed files with 11 additions and 5 deletions
|
@ -24,12 +24,18 @@
|
|||
|
||||
#define IS_FP_SAME(_a, _b) (fabs((_a) - (_b)) <= 0.000001 * MAX(fabs(_a), fabs(_b)))
|
||||
|
||||
// string handling
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static inline bool nearly_0(double fp)
|
||||
{
|
||||
return fabs(fp) <= 1e-6;
|
||||
}
|
||||
|
||||
// string handling
|
||||
|
||||
static inline bool same_string(const char *a, const char *b)
|
||||
{
|
||||
return !strcmp(a ?: "", b ?: "");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue