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

Function WithinUlpGeneric

cpp/src/arrow/testing/math.cc:85–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83
84template <typename Float>
85bool WithinUlpGeneric(Float left, Float right, int n_ulps) {
86 if constexpr (std::is_same_v<Float, util::Float16>) {
87 if (left.is_nan() || right.is_nan()) {
88 return left.is_nan() == right.is_nan();
89 } else if (left.is_infinity() || right.is_infinity()) {
90 return left == right;
91 }
92 } else {
93 if (std::isnan(left) || std::isnan(right)) {
94 return std::isnan(left) == std::isnan(right);
95 }
96 if (!std::isfinite(left) || !std::isfinite(right)) {
97 return left == right;
98 }
99 }
100
101 if (n_ulps == 0) {
102 return left == right;
103 }
104
105 DCHECK_GE(n_ulps, 1);
106 return UlpDistanceUtil<Float>::UlpDistance(left, right) <=
107 static_cast<uint64_t>(n_ulps);
108}
109
110template <typename Float>
111void AssertWithinUlpGeneric(Float left, Float right, int n_ulps) {

Callers 2

AssertWithinUlpGenericFunction · 0.85
WithinUlpFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected