MCPcopy Create free account
hub / github.com/a2flo/floor / next_pot

Function next_pot

constexpr/const_math.hpp:1011–1018  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1009 //! returns the nearest power of two value of num (only numerical upwards)
1010 template <typename int_type> requires(ext::is_integral_v<int_type>)
1011 constexpr int_type next_pot(const int_type num) {
1012 int_type tmp = 2;
1013 for(size_t i = 0; i < ((sizeof(int_type) * 8) - 1); ++i) {
1014 if(tmp >= num) return tmp;
1015 tmp <<= 1;
1016 }
1017 return 0;
1018 }
1019
1020 //! computes the width of an integer value (e.g. 7 = 1, 42 = 2, 987654 = 6)
1021 template <typename int_type> requires(ext::is_integral_v<int_type>)

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected