From 2c5030f929ccef38706b188a17dcac5d439be3fd Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Wed, 15 Jun 2016 17:27:32 +0100 Subject: [PATCH] Add dedicated tests for lexical_cast and fix failures I found. --- include/helpers/lexical_cast.hpp | 87 ++++++++++++++++++------------ test/unit/CMakeLists.txt | 1 + test/unit/test_lexical_cast.cpp | 92 ++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+), 33 deletions(-) create mode 100644 test/unit/test_lexical_cast.cpp diff --git a/include/helpers/lexical_cast.hpp b/include/helpers/lexical_cast.hpp index 1055933..01d3b0b 100644 --- a/include/helpers/lexical_cast.hpp +++ b/include/helpers/lexical_cast.hpp @@ -20,11 +20,11 @@ #include "compatibility.h" #include "helpers/sequence_bt.hpp" +#include "helpers/MaxSizedArray.hpp" #include #include #include #include -#include #include #include #include @@ -42,10 +42,10 @@ namespace dinhelp { } //namespace customize namespace implem { - template - inline constexpr std::size_t max_digits() { - return static_cast(::log(std::numeric_limits::max())); - } + int count_leading_zeroes ( uint8_t parValue ) a_always_inline; + int count_leading_zeroes ( uint16_t parValue ) a_always_inline; + int count_leading_zeroes ( uint32_t parValue ) a_always_inline; + int count_leading_zeroes ( uint64_t parValue ) a_always_inline; template struct power { @@ -56,26 +56,17 @@ namespace dinhelp { enum { value = 1 }; }; - constexpr std::size_t count_digits_10_compiletime (std::size_t parNum) { - return (parNum == 0 ? 0 : static_cast(::log10(parNum))) + 1; - } - - template - struct maxdigits { - enum { value = count_digits_10_compiletime(static_cast(::pow(2.0, static_cast(N)))) }; - }; - template