19 #include "boost/static_assert.hpp"
20 #include "boost/integer_traits.hpp"
25 BOOST_STATIC_ASSERT( std::numeric_limits<float> ::is_specialized &&
26 boost::integer_traits<int> ::is_specialized &&
27 boost::integer_traits<unsigned int> ::is_specialized &&
28 sizeof(
float)==
sizeof(
int) &&
29 sizeof(
float)==
sizeof(
unsigned int) &&
30 32 == boost::integer_traits<unsigned int>::digits ) ;
37 typedef __int64 Long ;
38 typedef unsigned __int64 ULong ;
47 typedef unsigned long ULong ;
52 typedef long long Long ;
53 typedef unsigned long long ULong ;
55 struct _Longs :
public __Longs<sizeof(double)==sizeof(long)>{};
59 typedef _Longs::Long Long ;
60 typedef _Longs::ULong ULong ;
63 BOOST_STATIC_ASSERT( std::numeric_limits<double> ::is_specialized &&
64 std::numeric_limits<Long> ::is_specialized &&
65 std::numeric_limits<ULong> ::is_specialized &&
66 boost::integer_traits<ULong> ::is_specialized &&
67 boost::integer_traits<Long> ::is_specialized &&
68 sizeof(
double)==
sizeof(Long) &&
69 sizeof(
double)==
sizeof(ULong) &&
70 64 == std::numeric_limits<ULong>::digits ) ;
84 BOOST_STATIC_ASSERT( std::numeric_limits<float> ::is_specialized &&
85 boost::integer_traits<int> ::is_specialized &&
86 boost::integer_traits<unsigned int> ::is_specialized &&
87 sizeof(
float)==
sizeof(
int) &&
88 32 == boost::integer_traits<unsigned int>::digits ) ;
93 float i2f (
const int i ) { m_f.i =
i ;
return m_f.f ; }
95 int f2i (
const float f ) { m_f.f = f ;
return m_f.i ; }
122 BOOST_STATIC_ASSERT( std::numeric_limits<double> ::is_specialized &&
123 std::numeric_limits<Long> ::is_specialized &&
124 std::numeric_limits<ULong> ::is_specialized &&
125 boost::integer_traits<ULong> ::is_specialized &&
126 boost::integer_traits<Long> ::is_specialized &&
127 sizeof(
double)==
sizeof(Long) &&
128 sizeof(
double)==
sizeof(ULong) &&
129 64 == std::numeric_limits<ULong>::digits ) ;
134 double l2d (
const Long
l ) { m_d.l =
l ;
return m_d.d ; }
136 Long d2l (
const double d ) { m_d.d = d ;
return m_d.l ; }
197 const unsigned short maxULPs )
201 BOOST_STATIC_ASSERT( std::numeric_limits<float> ::is_specialized &&
202 boost::integer_traits<int> ::is_specialized &&
203 boost::integer_traits<unsigned int> ::is_specialized &&
204 sizeof(
float)==
sizeof(
int) &&
205 sizeof(
float)==
sizeof(
unsigned int) &&
206 32 == boost::integer_traits<unsigned int>::digits ) ;
213 int ai = caster.f2i ( af ) ;
214 int bi = caster.f2i ( bf ) ;
216 int test = (((
unsigned int)(ai^bi))>>31)-1;
220 int diff = ((( boost::integer_traits<int>::const_min - ai ) & (~test)) | ( ai& test )) - bi ;
222 int maxDiff_ = maxULPs ;
224 int v1 = maxDiff_ + diff ;
225 int v2 = maxDiff_ - diff ;
250 BOOST_STATIC_ASSERT( std::numeric_limits<float> ::is_specialized &&
251 std::numeric_limits<int> ::is_specialized &&
252 sizeof(
float)==
sizeof(
int) ) ;
257 int ai = caster.f2i ( af ) ;
260 return caster.i2f ( ai ) ;
293 const unsigned int maxULPs )
297 BOOST_STATIC_ASSERT( std::numeric_limits<double> ::is_specialized &&
298 std::numeric_limits<Long> ::is_specialized &&
299 std::numeric_limits<ULong> ::is_specialized &&
300 boost::integer_traits<ULong> ::is_specialized &&
301 boost::integer_traits<Long> ::is_specialized &&
302 sizeof(
double)==
sizeof(Long) &&
303 sizeof(
double)==
sizeof(ULong) &&
304 64 == std::numeric_limits<ULong>::digits ) ;
310 Long ai = caster.d2l ( af ) ;
311 Long bi = caster.d2l ( bf ) ;
313 Long
test = (((ULong)(ai^bi))>>63)-1;
317 Long diff = ((( boost::integer_traits<Long>::const_min - ai ) & (~test)) | ( ai& test )) - bi ;
319 Long maxDiff_ = maxULPs ;
321 Long v1 = maxDiff_ + diff ;
322 Long v2 = maxDiff_ - diff ;
348 BOOST_STATIC_ASSERT( std::numeric_limits<double> ::is_specialized &&
349 std::numeric_limits<Long> ::is_specialized &&
350 sizeof(
double)==
sizeof(Long) ) ;
355 Long al = caster.d2l ( ad ) ;
358 return caster.l2d ( al ) ;
GAUDI_API bool lomont_compare_float(const float af, const float bf, const unsigned short maxULPs)
equality comparison of float numbers using as the metric the maximal number of Units in the Last Plac...
GAUDI_API float next_float(const float af, const short ulps)
Get the floating number that representation is different with respect to the argument for the certain...
GAUDI_API bool lomont_compare_double(const double af, const double bf, const unsigned int maxULPs)
equality comparison of double numbers using as the metric the maximal number of Units in the Last Pla...
GAUDI_API double next_double(const double af, const short ulps)
Get the floating number that representation is different with respect to the argument for the certain...