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// SPDX-FileCopyrightText: Copyright (C) 2023 Tobias Hienzsch
3
4#ifndef TETL_MATH_ILOG2_HPP
5#define TETL_MATH_ILOG2_HPP
6
7#include <etl/_concepts/integral.hpp>
8
9namespace etl {
10
11template <integral Int>
12[[nodiscard]] constexpr auto ilog2(Int x) noexcept -> Int
13{
14 auto result = Int(0);
15 for (; x > Int(1); x >>= Int(1)) {
16 ++result;
17 }
18 return result;
19}
20
21} // namespace etl
22
23#endif // TETL_MATH_ILOG2_HPP
Definition adjacent_find.hpp:9
constexpr auto ilog2(Int x) noexcept -> Int
Definition ilog2.hpp:12