tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
ilog2.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_MATH_ILOG2_HPP
4#define TETL_MATH_ILOG2_HPP
5
7
8namespace etl {
9
10template <integral Int>
11[[nodiscard]] constexpr auto ilog2(Int x) noexcept -> Int
12{
13 auto result = Int(0);
14 for (; x > Int(1); x >>= Int(1)) {
15 ++result;
16 }
17 return result;
18}
19
20} // namespace etl
21
22#endif // TETL_MATH_ILOG2_HPP
Definition adjacent_find.hpp:8
constexpr auto ilog2(Int x) noexcept -> Int
Definition ilog2.hpp:11