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
3#ifndef TETL_BIT_BIT_FLOOR_HPP
4#define TETL_BIT_BIT_FLOOR_HPP
5
9
10namespace etl {
11
23template <etl::builtin_unsigned_integer UInt>
24[[nodiscard]] constexpr auto bit_floor(UInt x) noexcept -> UInt
25{
26 if (x != 0) {
27 return UInt(1) << static_cast<UInt>(static_cast<UInt>(etl::bit_width(x)) - UInt(1));
28 }
29 return 0;
30}
31} // namespace etl
32
33#endif // TETL_BIT_BIT_FLOOR_HPP
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:24
constexpr auto bit_width(UInt x) noexcept -> int
If x is not zero, calculates the number of bits needed to store the value x, that is,...
Definition bit_width.hpp:21
Definition adjacent_find.hpp:8