| 1 |
// Copyright 2017 The Chromium Authors |
| 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 <cmath> |
| 9 |
#include <type_traits> |
| 10 |
|
| 11 |
namespace chromium { |
| 12 |
namespace base { |
| 13 |
|
| 14 |
template <typename T> |
| 15 |
constexpr bool IsApproximatelyEqual(T lhs, T rhs, T tolerance) { |
| 16 |
static_assert(std::is_arithmetic<T>::value, "Argument must be arithmetic"); |
| 17 |
return std::abs(rhs - lhs) <= tolerance; |
| 18 |
} |
| 19 |
|
| 20 |
} // namespace base |
| 21 |
} // namespace chromium |
| 22 |
|
| 23 |
#endif // BASE_NUMERICS_RANGES_H_ |