From 3e9fab3bfc6f869c0d7be02e50ebe27818784707 Mon Sep 17 00:00:00 2001 From: Tyson Grant Nottingham Date: Mon, 21 Jul 2014 22:43:13 -0700 Subject: [PATCH] Allow numbers starting with decimal in fast_atof. --- code/fast_atof.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/code/fast_atof.h b/code/fast_atof.h index ddda1f29e..a7f0cb23f 100644 --- a/code/fast_atof.h +++ b/code/fast_atof.h @@ -229,14 +229,25 @@ inline uint64_t strtoul10_64( const char* in, const char** out=0, unsigned int* template inline const char* fast_atoreal_move( const char* c, Real& out, bool check_comma = true) { - Real f; + Real f = 0; bool inv = (*c == '-'); if (inv || *c == '+') { ++c; } - f = static_cast( strtoul10_64 ( c, &c) ); + if (!isdigit(*c) && !(*c == '.' && isdigit(c[1]))) + { + throw std::invalid_argument("Cannot parse string " + "as real number: does not start with digit " + "or decimal point followed by digit."); + } + + if (*c != '.') + { + f = static_cast( strtoul10_64 ( c, &c) ); + } + if ((*c == '.' || (check_comma && c[0] == ',')) && c[1] >= '0' && c[1] <= '9') { ++c;