-
Notifications
You must be signed in to change notification settings - Fork 2
/
fpUtil.h
39 lines (30 loc) · 1.14 KB
/
fpUtil.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// $Id: fpUtil.h 522 2009-09-22 22:48:07Z nathanst $
#include <stdint.h>
#include <assert.h>
#include <string.h>
#ifndef UINT32_MAX
#define UINT32_MAX (4294967295U)
#endif
#ifndef UINT_MAX
#define UINT_MAX (4294967295U)
#endif
#ifndef fpUtil_H
#define fpUtil_H
namespace hearts {
//// Somehow DBL_MAX is not defined under Linux?
//#ifndef OS_MAC
//static const double DBL_MAX = 1.79769313486231500e+308; // DBL_MAX for non Mac OS
//#endif
// Floating point comparisons
static const double TOLERANCE_D = 0.000001; // floating point tolerance
static const float TOLERANCE_F = 0.00005; // floating point tolerance
inline bool fless(double a, double b) { return (a < b - TOLERANCE_D); }
inline bool fgreater(double a, double b) { return (a > b + TOLERANCE_D); }
inline bool fequal(double a, double b)
{ return (a > b - TOLERANCE_D) && (a < b+TOLERANCE_D); }
inline bool fless(float a, float b) { return (a < b - TOLERANCE_F); }
inline bool fgreater(float a, float b) { return (a > b + TOLERANCE_F); }
inline bool fequal(float a, float b)
{ return (a > b - TOLERANCE_F) && (a < b+TOLERANCE_F); }
} // namespace hearts
#endif