CoinUtils
2.9.0
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
CoinUtils
src
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
Generated by
1.8.3.1