2 * http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
4 * Code assumed to be in the public domain.
7 #ifndef __libpbd__floating_h__
8 #define __libpbd__floating_h__
14 Float_t (float num = 0.0f) : f(num) {}
16 // Portable extraction of components.
17 bool negative() const { return (i >> 31) != 0; }
18 int32_t raw_mantissa() const { return i & ((1 << 23) - 1); }
19 int32_t raw_exponent() const { return (i >> 23) & 0xFF; }
25 /* Note: ULPS = Units in the Last Place */
27 static inline bool floateq (float a, float b, int max_ulps_diff)
32 // Different signs means they do not match.
33 if (ua.negative() != ub.negative()) {
34 // Check for equality to make sure +0==-0
41 // Find the difference in ULPs.
42 int ulps_diff = abs (ua.i - ub.i);
44 if (ulps_diff <= max_ulps_diff) {
53 #endif /* __libpbd__floating_h__ */