HOG2
FPUtil.h
Go to the documentation of this file.
1 /*
2  * $Id: fpUtil.h
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 09/18/06.
6  * Modified by Nathan Sturtevant on 02/29/20.
7  *
8  * This file is part of HOG2. See https://github.com/nathansttt/hog2 for licensing information.
9  *
10  */
11 
12 #ifndef fpUtil_H
13 #define fpUtil_H
14 
15 #include "float.h"
16 #include <limits>
17 
18 // Somehow DBL_MAX is not defined under Linux?
19 //#ifndef OS_MAC
20 //#define DBL_MAX std::numeric_limits<double>::max()//1.79769313486231500e+308; // DBL_MAX for non Mac OS
21 //#define DBL_MIN std::numeric_limits<double>::min()// DBL_MIN for non Mac OS
22 //#define MAXFLOAT std::numeric_limits<float>::max()
23 //#endif
24 
25 // Floating point comparisons
26 static const double TOLERANCE = 0.000001; // floating point tolerance
27 
28 inline bool fless(double a, double b) { return (a < b - TOLERANCE); }
29 inline bool fgreater(double a, double b) { return (a > b + TOLERANCE); }
30 inline bool flesseq(double a, double b) { return !fgreater(a, b); }
31 inline bool fgreatereq(double a, double b) { return !fless(a, b); }
32 inline bool fequal(double a, double b, double tolerance=TOLERANCE)
33 { return (a >= b - tolerance) && (a <= b+tolerance); }
34 
35 inline double min(double a, double b) { return fless(a, b)?a:b; }
36 inline double max(double a, double b) { return fless(a, b)?b:a; }
37 
38 #endif
min
double min(double a, double b)
Definition: FPUtil.h:35
fgreatereq
bool fgreatereq(double a, double b)
Definition: FPUtil.h:31
max
double max(double a, double b)
Definition: FPUtil.h:36
TOLERANCE
static const double TOLERANCE
Definition: FPUtil.h:26
fless
bool fless(double a, double b)
Definition: FPUtil.h:28
fgreater
bool fgreater(double a, double b)
Definition: FPUtil.h:29
fequal
bool fequal(double a, double b, double tolerance=TOLERANCE)
Definition: FPUtil.h:32
flesseq
bool flesseq(double a, double b)
Definition: FPUtil.h:30