Implement generic numeric comparison against double value.
| 94 | |
| 95 | // Implement generic numeric comparison against double value. |
| 96 | struct DoubleCompareVisitor { |
| 97 | constexpr explicit DoubleCompareVisitor(double v) : v(v) {} |
| 98 | |
| 99 | constexpr ComparisonResult operator()(double other) const { |
| 100 | return DoubleCompare(v, other); |
| 101 | } |
| 102 | |
| 103 | constexpr ComparisonResult operator()(uint64_t other) const { |
| 104 | if (v > kDoubleToUintMax) { |
| 105 | return ComparisonResult::kGreater; |
| 106 | } else if (v < 0) { |
| 107 | return ComparisonResult::kLesser; |
| 108 | } else { |
| 109 | return DoubleCompare(v, static_cast<double>(other)); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | constexpr ComparisonResult operator()(int64_t other) const { |
| 114 | if (v > kDoubleToIntMax) { |
| 115 | return ComparisonResult::kGreater; |
| 116 | } else if (v < kDoubleToIntMin) { |
| 117 | return ComparisonResult::kLesser; |
| 118 | } else { |
| 119 | return DoubleCompare(v, static_cast<double>(other)); |
| 120 | } |
| 121 | } |
| 122 | double v; |
| 123 | }; |
| 124 | |
| 125 | // Implement generic numeric comparison against uint value. |
| 126 | // Delegates to double comparison if either variable is double. |
no outgoing calls
no test coverage detected