libc: Port strtod fixes to strtof, strtold and improve comments
* libs/libc/stdlib/lib_strtod.c: (strtod): Add a note about limitations of this implementation as compared to POSIX in the function's docstring. Also fix a typo. * libs/libc/stdlib/lib_strtof.c: (strtof): Port the changes made to strtod in PR-6952 (commit c83985c5ce7) and add same note as above to docstring. * libs/libc/stdlib/lib_strtold.c: (strtold): Same changes as strtof.
This commit is contained in:
parent
c83985c5ce
commit
a0ee5d3747
@ -79,12 +79,16 @@ static inline int is_real(double x)
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/***************************************************(************************
|
||||
/****************************************************************************
|
||||
* Name: strtod
|
||||
*
|
||||
* Description:
|
||||
* Convert a string to a double value
|
||||
*
|
||||
* NOTE: This implementation is limited as compared to POSIX:
|
||||
* - Hexadecimal input is not supported
|
||||
* - INF, INFINITY, NAN, and NAN(...) are not supported
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
double strtod(FAR const char *str, FAR char **endptr)
|
||||
|
@ -86,12 +86,16 @@ static inline int is_real(float x)
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/***************************************************(************************
|
||||
/****************************************************************************
|
||||
* Name: strtof
|
||||
*
|
||||
* Description:
|
||||
* Convert a string to a float value
|
||||
*
|
||||
* NOTE: This implementation is limited as compared to POSIX:
|
||||
* - Hexadecimal input is not supported
|
||||
* - INF, INFINITY, NAN, and NAN(...) are not supported
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
float strtof(FAR const char *str, FAR char **endptr)
|
||||
@ -173,6 +177,7 @@ float strtof(FAR const char *str, FAR char **endptr)
|
||||
{
|
||||
set_errno(ERANGE);
|
||||
number = 0.0F;
|
||||
p = (FAR char *)str;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
@ -208,6 +213,14 @@ float strtof(FAR const char *str, FAR char **endptr)
|
||||
|
||||
/* Process string of digits */
|
||||
|
||||
if (!isdigit(*p))
|
||||
{
|
||||
set_errno(ERANGE);
|
||||
number = 0.0F;
|
||||
p = (FAR char *)str;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
n = 0;
|
||||
while (isdigit(*p))
|
||||
{
|
||||
|
@ -79,12 +79,16 @@ static inline int is_real(long double x)
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/***************************************************(************************
|
||||
/****************************************************************************
|
||||
* Name: strtold
|
||||
*
|
||||
* Description:
|
||||
* Convert a string to a long double value
|
||||
*
|
||||
* NOTE: This implementation is limited as compared to POSIX:
|
||||
* - Hexadecimal input is not supported
|
||||
* - INF, INFINITY, NAN, and NAN(...) are not supported
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
long double strtold(FAR const char *str, FAR char **endptr)
|
||||
@ -160,6 +164,7 @@ long double strtold(FAR const char *str, FAR char **endptr)
|
||||
{
|
||||
set_errno(ERANGE);
|
||||
number = 0.0L;
|
||||
p = (FAR char *)str;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
@ -195,6 +200,14 @@ long double strtold(FAR const char *str, FAR char **endptr)
|
||||
|
||||
/* Process string of digits */
|
||||
|
||||
if (!isdigit(*p))
|
||||
{
|
||||
set_errno(ERANGE);
|
||||
number = 0.0L;
|
||||
p = (FAR char *)str;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
n = 0;
|
||||
while (isdigit(*p))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user