@@ -289,32 +289,32 @@ int bit_width(_Tp __t) noexcept;
289289
290290template <> _EZCXX_NODISCARD _EZCXX_INLINE constexpr
291291int bit_width (unsigned char __t ) noexcept {
292- return 8 - __ez80_clzc (__t );
292+ return std::numeric_limits< unsigned char >::digits - __ez80_clzc (__t );
293293}
294294
295295template <> _EZCXX_NODISCARD _EZCXX_INLINE constexpr
296296int bit_width (unsigned short __t ) noexcept {
297- return 16 - __builtin_clzs (__t );
297+ return std::numeric_limits< unsigned short >::digits - __builtin_clzs (__t );
298298}
299299
300300template <> _EZCXX_NODISCARD _EZCXX_INLINE constexpr
301301int bit_width (unsigned int __t ) noexcept {
302- return 24 - __builtin_clz (__t );
302+ return std::numeric_limits< unsigned int >::digits - __builtin_clz (__t );
303303}
304304
305305template <> _EZCXX_NODISCARD _EZCXX_INLINE constexpr
306306int bit_width (unsigned long __t ) noexcept {
307- return 32 - __builtin_clzl (__t );
307+ return std::numeric_limits< unsigned long >::digits - __builtin_clzl (__t );
308308}
309309
310310template <> _EZCXX_NODISCARD _EZCXX_INLINE constexpr
311311int bit_width (unsigned __int48 __t ) noexcept {
312- return 48 - __ez80_clzi48 (__t );
312+ return std::numeric_limits< unsigned __int48>::digits - __ez80_clzi48 (__t );
313313}
314314
315315template <> _EZCXX_NODISCARD _EZCXX_INLINE constexpr
316316int bit_width (unsigned long long __t ) noexcept {
317- return 64 - __builtin_clzll (__t );
317+ return std::numeric_limits< unsigned long long >::digits - __builtin_clzll (__t );
318318}
319319
320320// ------------------------------------------------------------------------------
@@ -327,49 +327,43 @@ _Tp bit_ceil(_Tp __t) noexcept;
327327template <> _EZCXX_NODISCARD _EZCXX_INLINE constexpr
328328unsigned char bit_ceil (unsigned char __t ) noexcept {
329329 return
330- (static_cast <signed char >(__t ) > 0 )
331- ? (static_cast <unsigned char >(1 ) << bit_width<unsigned char >(__t - 1 ))
332- : ((__t == 0 ) ? 1 : 0 );
330+ (__t <= static_cast <unsigned char >(std::numeric_limits<signed char >::min ()))
331+ ? ((__t != 0 ) ? (static_cast <unsigned char >(1 ) << bit_width<unsigned char >(__t - 1 )) : 1 ) : 0 ;
333332}
334333
335334template <> _EZCXX_NODISCARD _EZCXX_INLINE constexpr
336335unsigned short bit_ceil (unsigned short __t ) noexcept {
337336 return
338- (static_cast <signed short >(__t ) > 0 )
339- ? (static_cast <unsigned short >(1 ) << bit_width<unsigned short >(__t - 1 ))
340- : ((__t == 0 ) ? 1 : 0 );
337+ (__t <= static_cast <unsigned short >(std::numeric_limits<signed short >::min ()))
338+ ? ((__t != 0 ) ? (static_cast <unsigned short >(1 ) << bit_width<unsigned short >(__t - 1 )) : 1 ) : 0 ;
341339}
342340
343341template <> _EZCXX_NODISCARD _EZCXX_INLINE constexpr
344342unsigned int bit_ceil (unsigned int __t ) noexcept {
345343 return
346- (static_cast <signed int >(__t ) > 0 )
347- ? (static_cast <unsigned int >(1 ) << bit_width<unsigned int >(__t - 1 ))
348- : ((__t == 0 ) ? 1 : 0 );
344+ (__t <= static_cast <unsigned int >(std::numeric_limits<signed int >::min ()))
345+ ? ((__t != 0 ) ? (static_cast <unsigned int >(1 ) << bit_width<unsigned int >(__t - 1 )) : 1 ) : 0 ;
349346}
350347
351348template <> _EZCXX_NODISCARD _EZCXX_INLINE constexpr
352349unsigned long bit_ceil (unsigned long __t ) noexcept {
353350 return
354- (static_cast <signed long >(__t ) > 0 )
355- ? (static_cast <unsigned long >(1 ) << bit_width<unsigned long >(__t - 1 ))
356- : ((__t == 0 ) ? 1 : 0 );
351+ (__t <= static_cast <unsigned long >(std::numeric_limits<signed long >::min ()))
352+ ? ((__t != 0 ) ? (static_cast <unsigned long >(1 ) << bit_width<unsigned long >(__t - 1 )) : 1 ) : 0 ;
357353}
358354
359355template <> _EZCXX_NODISCARD _EZCXX_INLINE constexpr
360356unsigned __int48 bit_ceil (unsigned __int48 __t ) noexcept {
361357 return
362- (static_cast <signed __int48>(__t ) > 0 )
363- ? (static_cast <unsigned __int48>(1 ) << bit_width<unsigned __int48>(__t - 1 ))
364- : ((__t == 0 ) ? 1 : 0 );
358+ (__t <= static_cast <unsigned __int48>(std::numeric_limits<signed __int48>::min ()))
359+ ? ((__t != 0 ) ? (static_cast <unsigned __int48>(1 ) << bit_width<unsigned __int48>(__t - 1 )) : 1 ) : 0 ;
365360}
366361
367362template <> _EZCXX_NODISCARD _EZCXX_INLINE constexpr
368363unsigned long long bit_ceil (unsigned long long __t ) noexcept {
369364 return
370- (static_cast <signed long long >(__t ) > 0 )
371- ? (static_cast <unsigned long long >(1 ) << bit_width<unsigned long long >(__t - 1 ))
372- : ((__t == 0 ) ? 1 : 0 );
365+ (__t <= static_cast <unsigned long long >(std::numeric_limits<signed long long >::min ()))
366+ ? ((__t != 0 ) ? (static_cast <unsigned long long >(1 ) << bit_width<unsigned long long >(__t - 1 )) : 1 ) : 0 ;
373367}
374368
375369// ------------------------------------------------------------------------------
0 commit comments