@@ -53,7 +53,7 @@ constexpr Exponent ceilinged_log_(Base base, Value value) NOEXCEPT
5353 const auto factor = possible_narrow_and_sign_cast<Value>(base);
5454
5555 Exponent exponent = 0 ;
56- while (value > 0 ) { ++exponent; value /= factor; }
56+ while (value > 1 ) { ++exponent; value /= factor; }
5757 return exponent;
5858 }
5959}
@@ -125,7 +125,7 @@ constexpr Exponent ceilinged_log2(Value value) NOEXCEPT
125125
126126 // base2 integral optimization over normal form.
127127 return possible_narrow_and_sign_cast<Exponent>(
128- std::bit_width (to_unsigned (value)));
128+ std::bit_width (sub1 ( to_unsigned (value) )));
129129}
130130
131131// Called by bc::bit_width.
@@ -134,12 +134,12 @@ template <typename Exponent, typename Value,
134134 if_non_integral_integer<Value>>
135135constexpr Exponent ceilinged_log2 (Value value) NOEXCEPT
136136{
137- if (is_log_overflow<2 >(value))
137+ if (is_log_overflow<2 >(value) || is_one (value) )
138138 return 0 ;
139139
140140 // base2 uintx optimization over normal form.
141141 return possible_narrow_and_sign_cast<Exponent>(
142- add1 (mp::msb (value)));
142+ add1 (mp::msb (value - 1 )));
143143}
144144
145145// Called by bc::byte_width.
@@ -159,24 +159,24 @@ constexpr Exponent ceilinged_log256(Value value) NOEXCEPT
159159
160160 if constexpr (size == sizeof (uint64_t ))
161161 {
162- if (compare > 0x00ffffffffffffff_u64 ) return 8 ;
163- if (compare > 0x0000ffffffffffff_u64 ) return 7 ;
164- if (compare > 0x000000ffffffffff_u64 ) return 6 ;
165- if (compare > 0x00000000ffffffff_u64 ) return 5 ;
162+ if (compare > 0x0100000000000000_u64 ) return 8 ;
163+ if (compare > 0x0001000000000000_u64 ) return 7 ;
164+ if (compare > 0x0000010000000000_u64 ) return 6 ;
165+ if (compare > 0x0000000100000000_u64 ) return 5 ;
166166 }
167167
168168 if constexpr (size >= sizeof (uint32_t ))
169169 {
170- if (compare > 0x00ffffff_u32 ) return 4 ;
171- if (compare > 0x0000ffff_u32 ) return 3 ;
170+ if (compare > 0x01000000_u32 ) return 4 ;
171+ if (compare > 0x00010000_u32 ) return 3 ;
172172 }
173173
174174 if constexpr (size >= sizeof (uint16_t ))
175175 {
176- if (compare > 0x00ff_u16 ) return 2 ;
176+ if (compare > 0x0100_u16 ) return 2 ;
177177 }
178178
179- return (compare > 0x00_u8 ) ? 1 : 0 ;
179+ return (compare > 0x01_u8 ) ? 1 : 0 ;
180180}
181181
182182// Called by bc::byte_width.
0 commit comments