xref: /aosp_15_r20/external/cronet/base/numerics/ranges.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 base {
12 
13 template <typename T>
IsApproximatelyEqual(T lhs,T rhs,T tolerance)14 constexpr bool IsApproximatelyEqual(T lhs, T rhs, T tolerance) {
15   static_assert(std::is_arithmetic_v<T>, "Argument must be arithmetic");
16   return std::abs(rhs - lhs) <= tolerance;
17 }
18 
19 }  // namespace base
20 
21 #endif  // BASE_NUMERICS_RANGES_H_
22