MCPcopy Create free account
hub / github.com/apache/arrow / UlpDistance

Method UlpDistance

cpp/src/arrow/util/ulp_distance.cc:59–70  ·  view source on GitHub ↗

This implementation is inspired by: https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

swapFunction · 0.85

Tested by

no test coverage detected