1 // Copyright 2017 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_NUMERICS_RANGES_H_ 6 #define BASE_NUMERICS_RANGES_H_ 7 8 #include <algorithm> 9 #include <cmath> 10 11 namespace base 12 { 13 14 template <typename T> IsApproximatelyEqual(T lhs,T rhs,T tolerance)15constexpr bool IsApproximatelyEqual(T lhs, T rhs, T tolerance) 16 { 17 static_assert(std::is_arithmetic<T>::value, "Argument must be arithmetic"); 18 return std::abs(rhs - lhs) <= tolerance; 19 } 20 21 } // namespace base 22 23 #endif // BASE_NUMERICS_RANGES_H_ 24