From f32cb2f6965071ff1e9ee4977234674af2727dc7 Mon Sep 17 00:00:00 2001 From: Abhay Kumar Date: Fri, 6 Jun 2025 14:23:26 +0530 Subject: [PATCH] :bug: Fix bit_ceil() to return 1 for input 0 as per specification --- include/boost/core/bit.hpp | 4 ++-- test/bit_ceil_test.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/boost/core/bit.hpp b/include/boost/core/bit.hpp index 7520abf..dfc2ab2 100644 --- a/include/boost/core/bit.hpp +++ b/include/boost/core/bit.hpp @@ -703,7 +703,7 @@ BOOST_CXX14_CONSTEXPR inline boost::uint32_t bit_ceil_impl( boost::uint32_t x ) { if( x == 0 ) { - return 0; + return 1; } --x; @@ -723,7 +723,7 @@ BOOST_CXX14_CONSTEXPR inline boost::uint64_t bit_ceil_impl( boost::uint64_t x ) { if( x == 0 ) { - return 0; + return 1; } --x; diff --git a/test/bit_ceil_test.cpp b/test/bit_ceil_test.cpp index fbb81d4..1b6af0d 100644 --- a/test/bit_ceil_test.cpp +++ b/test/bit_ceil_test.cpp @@ -21,7 +21,7 @@ template void test_bit_ceil( T x ) if( x == 0 ) { - BOOST_TEST_EQ( y, 0 ); + BOOST_TEST_EQ( y, 1 ); } else {