gmio_core: simplify strtof10()
This commit is contained in:
parent
516242b9ba
commit
2db6415405
@ -22,8 +22,7 @@ GMIO_INLINE gmio_bool_t is_local_decimal_point(char in)
|
|||||||
* TODO: This should probably also be used in irr::core::string, but
|
* TODO: This should probably also be used in irr::core::string, but
|
||||||
* the float-to-string code used there has to be rewritten first.
|
* the float-to-string code used there has to be rewritten first.
|
||||||
*/
|
*/
|
||||||
static const char LOCALE_DECIMAL_POINTS[] = { '.' };
|
return in == '.';
|
||||||
return in == LOCALE_DECIMAL_POINTS[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we write [17] here instead of [] to work around a swig bug */
|
/* we write [17] here instead of [] to work around a swig bug */
|
||||||
@ -242,25 +241,13 @@ GMIO_INLINE gmio_float32_t strtof10(const char* in, const char** out)
|
|||||||
|
|
||||||
/* Use integer arithmetic for as long as possible, for speed
|
/* Use integer arithmetic for as long as possible, for speed
|
||||||
* and precision. */
|
* and precision. */
|
||||||
while ( gmio_ascii_isdigit(*in) )
|
for (; gmio_ascii_isdigit(*in) && intValue < MAX_SAFE_U32_VALUE; ++in)
|
||||||
{
|
|
||||||
/* If it looks like we're going to overflow, bail out
|
|
||||||
now and start using floating point. */
|
|
||||||
if (intValue >= MAX_SAFE_U32_VALUE)
|
|
||||||
break;
|
|
||||||
intValue = (intValue * 10) + (*in - '0');
|
intValue = (intValue * 10) + (*in - '0');
|
||||||
++in;
|
|
||||||
}
|
|
||||||
floatValue = (gmio_float32_t)intValue;
|
floatValue = (gmio_float32_t)intValue;
|
||||||
/* If there are any digits left to parse, then we need to use
|
/* If there are any digits left to parse, then we need to use
|
||||||
* floating point arithmetic from here. */
|
* floating point arithmetic from here. */
|
||||||
while ( gmio_ascii_isdigit(*in) )
|
for (; gmio_ascii_isdigit(*in) && floatValue <= FLT_MAX; ++in)
|
||||||
{
|
floatValue = (floatValue * 10) + (*in - '0');
|
||||||
floatValue = (floatValue * 10.f) + (gmio_float32_t)(*in - '0');
|
|
||||||
++in;
|
|
||||||
if (floatValue > FLT_MAX) /* Just give up. */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (out)
|
if (out)
|
||||||
*out = in;
|
*out = in;
|
||||||
return floatValue;
|
return floatValue;
|
||||||
|
Loading…
Reference in New Issue
Block a user