tetl
0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
bit_floor.hpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: BSL-1.0
2
// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4
#
ifndef
TETL_BIT_BIT_FLOOR_HPP
5
#
define
TETL_BIT_BIT_FLOOR_HPP
6
7
#
include
<
etl
/
_bit
/
bit_width
.
hpp
>
8
#
include
<
etl
/
_concepts
/
builtin_unsigned_integer
.
hpp
>
9
#
include
<
etl
/
_limits
/
numeric_limits
.
hpp
>
10
11
namespace
etl
{
12
13
/// \brief If x is not zero, calculates the largest integral power of two that
14
/// is not greater than x. If x is zero, returns zero.
15
///
16
/// \details This overload only participates in overload resolution if UInt is an
17
/// unsigned integer type (that is, unsigned char, unsigned short, unsigned int,
18
/// unsigned long, unsigned long long, or an extended unsigned integer type).
19
///
20
/// \returns Zero if x is zero; otherwise, the largest integral power of two
21
/// that is not greater than x.
22
///
23
/// \ingroup bit
24
template
<
etl
::builtin_unsigned_integer UInt>
25
[[nodiscard]]
constexpr
auto
bit_floor
(UInt x)
noexcept
-> UInt
26
{
27
if
(x != 0) {
28
return
UInt(1) <<
static_cast
<UInt>(
static_cast
<UInt>(
etl
::bit_width(x)) - UInt(1));
29
}
30
return
0;
31
}
32
}
// namespace etl
33
34
#
endif
// TETL_BIT_BIT_FLOOR_HPP
etl::bit_floor
constexpr auto bit_floor(UInt x) noexcept -> UInt
If x is not zero, calculates the largest integral power of two that is not greater than x....
Definition
bit_floor.hpp:25
etl
Definition
adjacent_find.hpp:9
include
etl
_bit
bit_floor.hpp
Generated on Sun Sep 7 2025 19:14:48 for tetl by
1.9.8