Flutter Engine
Loading...
Searching...
No Matches
ranges.h
Go to the documentation of this file.
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
// To be replaced with std::clamp() from C++17, someday.
14
template
<
class
T>
15
constexpr
const
T&
ClampToRange
(
const
T& value,
const
T& min,
const
T& max) {
16
return
std::min(std::max(
value
, min), max);
17
}
18
19
template
<
typename
T>
20
constexpr
bool
IsApproximatelyEqual
(T lhs, T rhs, T tolerance) {
21
static_assert
(std::is_arithmetic<T>::value,
"Argument must be arithmetic"
);
22
return
std::abs(rhs - lhs) <= tolerance;
23
}
24
25
}
// namespace base
26
27
#endif
// BASE_NUMERICS_RANGES_H_
value
int32_t value
Definition
dl_golden_unittests.cc:459
base
Definition
ax_tree_id_registry.h:17
base::ClampToRange
constexpr const T & ClampToRange(const T &value, const T &min, const T &max)
Definition
ranges.h:15
base::IsApproximatelyEqual
constexpr bool IsApproximatelyEqual(T lhs, T rhs, T tolerance)
Definition
ranges.h:20
third_party
accessibility
base
numerics
ranges.h
Generated on Wed Nov 5 2025 21:33:19 for Flutter Engine by
1.9.8