This implementation is inspired by: https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
| 59 | // This implementation is inspired by: |
| 60 | // https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ |
| 61 | static UIntType UlpDistance(Float left, Float right) { |
| 62 | auto unsigned_left = util::SafeCopy<UIntType>(left); |
| 63 | auto unsigned_right = util::SafeCopy<UIntType>(right); |
| 64 | auto biased_left = ConvertSignAndMagnitudeToBiased(unsigned_left); |
| 65 | auto biased_right = ConvertSignAndMagnitudeToBiased(unsigned_right); |
| 66 | if (biased_left > biased_right) { |
| 67 | std::swap(biased_left, biased_right); |
| 68 | } |
| 69 | return biased_right - biased_left; |
| 70 | } |
| 71 | |
| 72 | private: |
| 73 | // Source reference (GoogleTest): |