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

Function prev_pot

include/floor/constexpr/const_math.hpp:1118–1132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1116 //! returns the nearest (less or equal) power of two value of num (only numerical downwards)
1117 template <typename int_type> requires(ext::is_integral_v<int_type>)
1118 constexpr int_type prev_pot(const int_type num) {
1119 if (num <= 1) {
1120 return num;
1121 }
1122
1123 int_type tmp = 1;
1124 for (size_t i = 0; i < (sizeof(int_type) * 8u); ++i) {
1125 auto next = tmp << 1;
1126 if (next > num) {
1127 return tmp;
1128 }
1129 tmp = next;
1130 }
1131 return 0;
1132 }
1133
1134 //! computes the width of an integer value (e.g. 7 = 1, 42 = 2, 987654 = 6)
1135 template <typename int_type> requires(ext::is_integral_v<int_type>)

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected