Osi 0.107.7

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CoinFloatEqual.hpp
Go to the documentation of this file.
1 /* $Id: CoinFloatEqual.hpp 1416 2011-04-17 09:57:29Z stefan $ */
2 // Copyright (C) 2000, International Business Machines
3 // Corporation and others. All Rights Reserved.
4 // This code is licensed under the terms of the Eclipse Public License (EPL).
5
6 #ifndef CoinFloatEqual_H
7 #define CoinFloatEqual_H
8
9 #include <algorithm>
10 #include <cmath>
11
12 #include "CoinFinite.hpp"
13
46 class CoinAbsFltEq
47 {
48 public:
49
51
52 inline bool operator() (const double f1, const double f2) const
53
54 { if (CoinIsnan(f1) || CoinIsnan(f2)) return false ;
55 if (f1 == f2) return true ;
56 return (fabs(f1-f2) < epsilon_) ; }
57
60
66 CoinAbsFltEq () : epsilon_(1.e-10) {}
67
69
70 CoinAbsFltEq (const double epsilon) : epsilon_(epsilon) {}
71
73
74 virtual ~CoinAbsFltEq () {}
75
77
78 CoinAbsFltEq (const CoinAbsFltEq& src) : epsilon_(src.epsilon_) {}
79
81
82 CoinAbsFltEq& operator= (const CoinAbsFltEq& rhs)
83
84 { if (this != &rhs) epsilon_ = rhs.epsilon_ ;
85 return (*this) ; }
86
88
89 private:
90
93
95
96 double epsilon_ ;
97
99
100 } ;
101
102
103
110 class CoinRelFltEq
111 {
112 public:
113
115
116 inline bool operator() (const double f1, const double f2) const
117
118 { if (CoinIsnan(f1) || CoinIsnan(f2)) return false ;
119 if (f1 == f2) return true ;
120 if (!CoinFinite(f1) || !CoinFinite(f2)) return false ;
121
122 double tol = (fabs(f1)>fabs(f2))?fabs(f1):fabs(f2) ;
123
124 return (fabs(f1-f2) <= epsilon_*(1+tol)) ; }
125
128
129 #ifndef COIN_FLOAT
130
134 CoinRelFltEq () : epsilon_(1.e-10) {}
135 #else
136
140 CoinRelFltEq () : epsilon_(1.e-6) {} ; // as float
141 #endif
142
144
145 CoinRelFltEq (const double epsilon) : epsilon_(epsilon) {}
146
148
149 virtual ~CoinRelFltEq () {}
150
152
153 CoinRelFltEq (const CoinRelFltEq & src) : epsilon_(src.epsilon_) {}
154
156
157 CoinRelFltEq& operator= (const CoinRelFltEq& rhs)
158
159 { if (this != &rhs) epsilon_ = rhs.epsilon_ ;
160 return (*this) ; }
161
163
164 private:
165
168
170
171 double epsilon_ ;
172
174
175 } ;
176
177 #endif
CoinIsnan
bool CoinIsnan(double val)
checks if a double value is not a number
CoinRelFltEq::epsilon_
double epsilon_
Base equality tolerance.
Definition: CoinFloatEqual.hpp:171
CoinFinite.hpp
CoinRelFltEq::CoinRelFltEq
CoinRelFltEq(const double epsilon)
Alternate constructor with epsilon as a parameter.
Definition: CoinFloatEqual.hpp:145
CoinRelFltEq::operator()
bool operator()(const double f1, const double f2) const
Compare function.
Definition: CoinFloatEqual.hpp:116
CoinAbsFltEq::CoinAbsFltEq
CoinAbsFltEq(const double epsilon)
Alternate constructor with epsilon as a parameter.
Definition: CoinFloatEqual.hpp:70
CoinRelFltEq
Equality to a scaled tolerance.
Definition: CoinFloatEqual.hpp:110
CoinAbsFltEq::CoinAbsFltEq
CoinAbsFltEq()
Default constructor.
Definition: CoinFloatEqual.hpp:66
CoinAbsFltEq::epsilon_
double epsilon_
Equality tolerance.
Definition: CoinFloatEqual.hpp:96
CoinRelFltEq::CoinRelFltEq
CoinRelFltEq()
Default constructor.
Definition: CoinFloatEqual.hpp:134
CoinRelFltEq::operator=
CoinRelFltEq & operator=(const CoinRelFltEq &rhs)
Assignment.
Definition: CoinFloatEqual.hpp:157
CoinAbsFltEq
Equality to an absolute tolerance.
Definition: CoinFloatEqual.hpp:46
CoinRelFltEq::CoinRelFltEq
CoinRelFltEq(const CoinRelFltEq &src)
Copy constructor.
Definition: CoinFloatEqual.hpp:153
CoinAbsFltEq::~CoinAbsFltEq
virtual ~CoinAbsFltEq()
Destructor.
Definition: CoinFloatEqual.hpp:74
CoinAbsFltEq::operator=
CoinAbsFltEq & operator=(const CoinAbsFltEq &rhs)
Assignment.
Definition: CoinFloatEqual.hpp:82
CoinAbsFltEq::operator()
bool operator()(const double f1, const double f2) const
Compare function.
Definition: CoinFloatEqual.hpp:52
CoinFinite
bool CoinFinite(double val)
checks if a double value is finite (not infinity and not NaN)
CoinRelFltEq::~CoinRelFltEq
virtual ~CoinRelFltEq()
Destructor.
Definition: CoinFloatEqual.hpp:149
CoinAbsFltEq::CoinAbsFltEq
CoinAbsFltEq(const CoinAbsFltEq &src)
Copy constructor.
Definition: CoinFloatEqual.hpp:78