mirror of
https://github.com/apache/nuttx.git
synced 2026-06-01 16:59:28 +08:00
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
c83985c5ce) and add same note as above to docstring.
* libs/libc/stdlib/lib_strtold.c:
(strtold): Same changes as strtof.
This commit is contained in:
committed by
Xiang Xiao
parent
c83985c5ce
commit
a0ee5d3747
@@ -79,12 +79,16 @@ static inline int is_real(double x)
|
|||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/***************************************************(************************
|
/****************************************************************************
|
||||||
* Name: strtod
|
* Name: strtod
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Convert a string to a double value
|
* 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)
|
double strtod(FAR const char *str, FAR char **endptr)
|
||||||
|
|||||||
@@ -86,12 +86,16 @@ static inline int is_real(float x)
|
|||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/***************************************************(************************
|
/****************************************************************************
|
||||||
* Name: strtof
|
* Name: strtof
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Convert a string to a float value
|
* 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)
|
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);
|
set_errno(ERANGE);
|
||||||
number = 0.0F;
|
number = 0.0F;
|
||||||
|
p = (FAR char *)str;
|
||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,6 +213,14 @@ float strtof(FAR const char *str, FAR char **endptr)
|
|||||||
|
|
||||||
/* Process string of digits */
|
/* Process string of digits */
|
||||||
|
|
||||||
|
if (!isdigit(*p))
|
||||||
|
{
|
||||||
|
set_errno(ERANGE);
|
||||||
|
number = 0.0F;
|
||||||
|
p = (FAR char *)str;
|
||||||
|
goto errout;
|
||||||
|
}
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
while (isdigit(*p))
|
while (isdigit(*p))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -79,12 +79,16 @@ static inline int is_real(long double x)
|
|||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/***************************************************(************************
|
/****************************************************************************
|
||||||
* Name: strtold
|
* Name: strtold
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Convert a string to a long double value
|
* 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)
|
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);
|
set_errno(ERANGE);
|
||||||
number = 0.0L;
|
number = 0.0L;
|
||||||
|
p = (FAR char *)str;
|
||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,6 +200,14 @@ long double strtold(FAR const char *str, FAR char **endptr)
|
|||||||
|
|
||||||
/* Process string of digits */
|
/* Process string of digits */
|
||||||
|
|
||||||
|
if (!isdigit(*p))
|
||||||
|
{
|
||||||
|
set_errno(ERANGE);
|
||||||
|
number = 0.0L;
|
||||||
|
p = (FAR char *)str;
|
||||||
|
goto errout;
|
||||||
|
}
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
while (isdigit(*p))
|
while (isdigit(*p))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user