Allow numbers starting with decimal in fast_atof.

pull/316/head
Tyson Grant Nottingham 2014-07-21 22:43:13 -07:00
parent d655199043
commit 3e9fab3bfc
1 changed files with 13 additions and 2 deletions

View File

@ -229,14 +229,25 @@ inline uint64_t strtoul10_64( const char* in, const char** out=0, unsigned int*
template <typename Real>
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<Real>( 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<Real>( strtoul10_64 ( c, &c) );
}
if ((*c == '.' || (check_comma && c[0] == ',')) && c[1] >= '0' && c[1] <= '9')
{
++c;