diff --git a/include/boost/lexical_cast.hpp b/include/boost/lexical_cast.hpp index d9b73af..044354f 100644 --- a/include/boost/lexical_cast.hpp +++ b/include/boost/lexical_cast.hpp @@ -798,12 +798,8 @@ namespace boost if (begin == end) return false; } - if ( *begin < czero || *begin >= czero + 10 ) { - return false; - } - - bool found_decimal = false; + bool found_number_before_exp = false; int pow_of_10 = 0; mantissa_type mantissa=0; bool is_mantissa_full = false; @@ -830,6 +826,8 @@ namespace boost -- pow_of_10; mantissa = tmp_mantissa; mantissa += *begin - zero; + + found_number_before_exp = true; } else { if (*begin >= czero && *begin < czero + 10) { @@ -851,6 +849,7 @@ namespace boost ++ pow_of_10; } + found_number_before_exp = true; ++ length_since_last_delim; } else if ( *begin == decimal_point || *begin == lowercase_e || *begin == capital_e) { #ifndef BOOST_LEXICAL_CAST_ASSUME_C_LOCALE @@ -874,7 +873,10 @@ namespace boost ++ begin; found_decimal = true; continue; - }else break; + }else { + if (!found_number_before_exp) return false; + break; + } } #ifndef BOOST_LEXICAL_CAST_ASSUME_C_LOCALE else if (grouping_size && *begin == thousands_sep){ diff --git a/lexical_cast.htm b/lexical_cast.htm index 7a1fee5..2079a0f 100644 --- a/lexical_cast.htm +++ b/lexical_cast.htm @@ -331,7 +331,7 @@ This table shows the execution time in milliseconds for 100000 calls of the foll string->int71152318 string->unsigned int71172217 string->bool<11041910 - string->float851726033 + string->float131726033 char->string71051612 int->string151312117 unsigned int->string141252117 diff --git a/test/lexical_cast_float_types_test.cpp b/test/lexical_cast_float_types_test.cpp index 442ed3b..66f6d67 100755 --- a/test/lexical_cast_float_types_test.cpp +++ b/test/lexical_cast_float_types_test.cpp @@ -194,7 +194,9 @@ void test_converion_to_float_types() CHECK_CLOSE_ABS_DIFF(0.0E-1, test_t); CHECK_CLOSE_ABS_DIFF(-1.0E-1, test_t); - + CHECK_CLOSE_ABS_DIFF(.0E-1, test_t); + CHECK_CLOSE_ABS_DIFF(.0E-1, test_t); + CHECK_CLOSE_ABS_DIFF(-.0E-1, test_t); CHECK_CLOSE_ABS_DIFF(10.0, test_t); CHECK_CLOSE_ABS_DIFF(00.0, test_t); @@ -235,6 +237,10 @@ void test_converion_to_float_types() CHECK_CLOSE_ABS_DIFF(-10101.0E-011, test_t); CHECK_CLOSE_ABS_DIFF(-10101093, test_t); CHECK_CLOSE_ABS_DIFF(10101093, test_t); + + CHECK_CLOSE_ABS_DIFF(-.34, test_t); + CHECK_CLOSE_ABS_DIFF(.34, test_t); + CHECK_CLOSE_ABS_DIFF(.34e10, test_t); // BOOST_CHECK(lexical_cast("-inf") == -std::numeric_limits::infinity() ); // BOOST_CHECK(lexical_cast("-INF") == -std::numeric_limits::infinity() );