| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 } | 182 } |
| 183 // float_comparison_ == APPROXIMATE covers two use cases. | 183 // float_comparison_ == APPROXIMATE covers two use cases. |
| 184 Tolerance* tolerance = FindOrNull(map_tolerance_, &field); | 184 Tolerance* tolerance = FindOrNull(map_tolerance_, &field); |
| 185 if (tolerance == NULL && has_default_tolerance_) { | 185 if (tolerance == NULL && has_default_tolerance_) { |
| 186 tolerance = &default_tolerance_; | 186 tolerance = &default_tolerance_; |
| 187 } | 187 } |
| 188 if (tolerance == NULL) { | 188 if (tolerance == NULL) { |
| 189 return MathUtil::AlmostEquals(value_1, value_2); | 189 return MathUtil::AlmostEquals(value_1, value_2); |
| 190 } else { | 190 } else { |
| 191 // Use user-provided fraction and margin. Since they are stored as | 191 // Use user-provided fraction and margin. Since they are stored as |
| 192 // doubles, we explicitely cast them to types of values provided. This | 192 // doubles, we explicitly cast them to types of values provided. This |
| 193 // is very likely to fail if provided values are not numeric. | 193 // is very likely to fail if provided values are not numeric. |
| 194 return MathUtil::WithinFractionOrMargin( | 194 return MathUtil::WithinFractionOrMargin( |
| 195 value_1, value_2, static_cast<T>(tolerance->fraction), | 195 value_1, value_2, static_cast<T>(tolerance->fraction), |
| 196 static_cast<T>(tolerance->margin)); | 196 static_cast<T>(tolerance->margin)); |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 | 200 |
| 201 FieldComparator::ComparisonResult DefaultFieldComparator::ResultFromBoolean( | 201 FieldComparator::ComparisonResult DefaultFieldComparator::ResultFromBoolean( |
| 202 bool boolean_result) const { | 202 bool boolean_result) const { |
| 203 return boolean_result ? FieldComparator::SAME : FieldComparator::DIFFERENT; | 203 return boolean_result ? FieldComparator::SAME : FieldComparator::DIFFERENT; |
| 204 } | 204 } |
| 205 | 205 |
| 206 } // namespace util | 206 } // namespace util |
| 207 } // namespace protobuf | 207 } // namespace protobuf |
| 208 } // namespace google | 208 } // namespace google |
| OLD | NEW |