mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Add is_power_of_2 helper
This commit is contained in:
parent
3b27e28e67
commit
61027e5303
Notes:
sideshowbarker
2024-07-17 20:02:08 +09:00
Author: https://github.com/Panky-codes Commit: https://github.com/SerenityOS/serenity/commit/61027e53037 Pull-request: https://github.com/SerenityOS/serenity/pull/12198 Reviewed-by: https://github.com/IdanHo
1 changed files with 6 additions and 0 deletions
|
@ -16,6 +16,12 @@ constexpr auto round_up_to_power_of_two(T value, U power_of_two) requires(IsInte
|
||||||
return ((value - 1) & ~(power_of_two - 1)) + power_of_two;
|
return ((value - 1) & ~(power_of_two - 1)) + power_of_two;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
constexpr bool is_power_of_two(T value) requires(IsIntegral<T>)
|
||||||
|
{
|
||||||
|
return value && !((value) & (value - 1));
|
||||||
|
}
|
||||||
|
|
||||||
// HACK: clang-format does not format this correctly because of the requires clause above.
|
// HACK: clang-format does not format this correctly because of the requires clause above.
|
||||||
// Disabling formatting for that doesn't help either.
|
// Disabling formatting for that doesn't help either.
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue