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__
16 Float_t (float num = 0.0f) : f(num) {}
18 // Portable extraction of components.
19 bool negative() const { return (i >> 31) != 0; }
20 int32_t raw_mantissa() const { return i & ((1 << 23) - 1); }
21 int32_t raw_exponent() const { return (i >> 23) & 0xFF; }
27 /* Note: ULPS = Units in the Last Place */
29 static inline bool floateq (float a, float b, int max_ulps_diff)
38 // Different signs means they do not match.
39 if (ua.negative() != ub.negative()) {
43 // Find the difference in ULPs.
44 int ulps_diff = abs (ua.i - ub.i);
46 if (ulps_diff <= max_ulps_diff) {
55 #endif /* __libpbd__floating_h__ */