diff --git a/CMakeLists.txt b/CMakeLists.txt index 689b42045..bb84331a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ cmake_minimum_required( VERSION 3.14 ) project( "daw-header-libraries" - VERSION "2.106.2" + VERSION "2.107.0" DESCRIPTION "Various headers" HOMEPAGE_URL "https://github.com/beached/header_libraries" LANGUAGES C CXX diff --git a/include/daw/daw_cxmath.h b/include/daw/daw_cxmath.h index bd94d4f59..5b96c2931 100644 --- a/include/daw/daw_cxmath.h +++ b/include/daw/daw_cxmath.h @@ -1340,4 +1340,33 @@ namespace daw::cxmath { DAW_ATTRIB_INLINE constexpr auto to_signed( Integer value ) { return static_cast>( value ); } + + inline constexpr std::uint64_t powers_of_ten[19] = { + 10ull, + 100ull, + 1'000ull, + 10'000ull, + 100'000ull, + 1'000'000ull, + 10'000'000ull, + 100'000'000ull, + 1'000'000'000ull, + 10'000'000'000ull, + 100'000'000'000ull, + 1'000'000'000'000ull, + 10'000'000'000'000ull, + 100'000'000'000'000ull, + 1'000'000'000'000'000ull, + 10'000'000'000'000'000ull, + 100'000'000'000'000'000ull, + 1'000'000'000'000'000'000ull, + 10'000'000'000'000'000'000ull }; + + constexpr int count_digits( std::uint64_t value ) { + auto b = -( value > 0 ) & ( 63 - count_leading_zeroes( value ) ); + auto a = ( b * 77 ) / 256; + return static_cast( 1 + a + ( value >= powers_of_ten[a] ) ); + } + static_assert( count_digits( 1'000'000ULL ) == 7 ); } // namespace daw::cxmath +