sscanf: Use strtof() instead of strtod() if a short floating point value was requested. The should help performance with MCUs with 32-bit FPU support
This commit is contained in:
parent
d08596a653
commit
177239feae
|
@ -511,7 +511,7 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
|
|||
else if (strchr("aAfFeEgG", *fmt) != NULL)
|
||||
{
|
||||
#ifdef CONFIG_HAVE_DOUBLE
|
||||
FAR double_t *pd = NULL;
|
||||
FAR double *pd = NULL;
|
||||
#endif
|
||||
FAR float *pf = NULL;
|
||||
|
||||
|
@ -531,7 +531,7 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
|
|||
#ifdef CONFIG_HAVE_DOUBLE
|
||||
if (lflag)
|
||||
{
|
||||
pd = va_arg(ap, FAR double_t *);
|
||||
pd = va_arg(ap, FAR double *);
|
||||
*pd = 0.0;
|
||||
}
|
||||
else
|
||||
|
@ -581,13 +581,22 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
|
|||
|
||||
FAR char *endptr;
|
||||
int errsave;
|
||||
double_t dvalue;
|
||||
|
||||
/* Preserve the errno value */
|
||||
|
||||
errsave = get_errno();
|
||||
set_errno(0);
|
||||
dvalue = strtod(tmp, &endptr);
|
||||
|
||||
/* We have to check whether we need to return a float
|
||||
* or a double.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_HAVE_DOUBLE
|
||||
if (lflag)
|
||||
{
|
||||
/* Get the converted double value */
|
||||
|
||||
double dvalue = strtod(tmp, &endptr);
|
||||
|
||||
/* Check if the number was successfully converted */
|
||||
|
||||
|
@ -598,21 +607,31 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
|
|||
|
||||
set_errno(errsave);
|
||||
|
||||
/* We have to check whether we need to return a float
|
||||
* or a double.
|
||||
*/
|
||||
/* Return the double value */
|
||||
|
||||
#ifdef CONFIG_HAVE_DOUBLE
|
||||
if (lflag)
|
||||
{
|
||||
linfo("vsscanf: Return %f to %p\n", dvalue, pd);
|
||||
*pd = dvalue;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
linfo("vsscanf: Return %f to %p\n", dvalue, pf);
|
||||
*pf = (float)dvalue;
|
||||
/* Get the converted float value */
|
||||
|
||||
float fvalue = strtof(tmp, &endptr);
|
||||
|
||||
/* Check if the number was successfully converted */
|
||||
|
||||
if (tmp == endptr || get_errno() == ERANGE)
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
set_errno(errsave);
|
||||
|
||||
/* Return the float value */
|
||||
|
||||
linfo("vsscanf: Return %f to %p\n", (double)fvalue, pf);
|
||||
*pf = fvalue;
|
||||
}
|
||||
|
||||
count++;
|
||||
|
|
Loading…
Reference in New Issue