Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
opt
build
coinutils
coinutils-2.6.4
CoinUtils
src
CoinFloatEqual.hpp
Go to the documentation of this file.
1
/* $Id: CoinFloatEqual.hpp 1215 2009-11-05 11:03:04Z forrest $ */
2
// Copyright (C) 2000, International Business Machines
3
// Corporation and others. All Rights Reserved.
4
#ifndef CoinFloatEqual_H
5
#define CoinFloatEqual_H
6
7
#include <algorithm>
8
#
9
#include <cmath>
10
11
#include "
CoinFinite.hpp
"
12
45
class
CoinAbsFltEq
46
{
47
public
:
48
50
51
inline
bool
operator()
(
const
double
f1,
const
double
f2)
const
52
53
{
if
(
CoinIsnan
(f1) ||
CoinIsnan
(f2))
return
false ;
54
if
(f1 == f2)
return
true ;
55
return
(fabs(f1-f2) <
epsilon_
) ; }
56
59
61
62
CoinAbsFltEq
() :
epsilon_
(1.e-10) {}
63
65
66
CoinAbsFltEq
(
const
double
epsilon) :
epsilon_
(epsilon) {}
67
69
70
virtual
~CoinAbsFltEq
() {}
71
73
74
CoinAbsFltEq
(
const
CoinAbsFltEq
& src) :
epsilon_
(src.
epsilon_
) {}
75
77
78
CoinAbsFltEq
&
operator=
(
const
CoinAbsFltEq
& rhs)
79
80
{
if
(
this
!= &rhs)
epsilon_
= rhs.
epsilon_
;
81
return
(*
this
) ; }
82
84
85
private
:
86
89
91
92
double
epsilon_
;
93
95
96
} ;
97
98
99
106
class
CoinRelFltEq
107
{
108
public
:
109
111
112
inline
bool
operator()
(
const
double
f1,
const
double
f2)
const
113
114
{
if
(
CoinIsnan
(f1) ||
CoinIsnan
(f2))
return
false ;
115
if
(f1 == f2)
return
true ;
116
if
(!
CoinFinite
(f1) || !
CoinFinite
(f2))
return
false ;
117
118
double
tol = (fabs(f1)>fabs(f2))?fabs(f1):fabs(f2) ;
119
120
return
(fabs(f1-f2) <=
epsilon_
*(1+tol)) ; }
121
124
126
127
#ifndef COIN_FLOAT
128
CoinRelFltEq
() :
epsilon_
(1.e-10) {}
129
#else
130
CoinRelFltEq
() :
epsilon_
(1.e-6) {} ;
// as float
131
#endif
132
134
135
CoinRelFltEq
(
const
double
epsilon) :
epsilon_
(epsilon) {}
136
138
139
virtual
~CoinRelFltEq
() {}
140
142
143
CoinRelFltEq
(
const
CoinRelFltEq
& src) :
epsilon_
(src.
epsilon_
) {}
144
146
147
CoinRelFltEq
&
operator=
(
const
CoinRelFltEq
& rhs)
148
149
{
if
(
this
!= &rhs)
epsilon_
= rhs.
epsilon_
;
150
return
(*
this
) ; }
151
153
154
private
:
155
158
160
161
double
epsilon_
;
162
164
165
} ;
166
167
#endif
Generated on Tue Mar 1 2016 22:31:56 by
1.8.4