xiaoxiang781216 commented on code in PR #7724: URL: https://github.com/apache/nuttx/pull/7724#discussion_r1033750289
########## libs/libc/stdlib/lib_strtof.c: ########## @@ -47,7 +47,7 @@ #include <stdlib.h> #include <ctype.h> #include <errno.h> - +#include <stdio.h> Review Comment: add one blank line after ########## libs/libc/stdlib/lib_strtof.c: ########## @@ -113,6 +114,8 @@ float strtof(FAR const char *str, FAR char **endptr) * zero literal, but allows it through non-const variable set to zero */ + int flag_sixt = 0; /* the flag for hexadecimal support */ Review Comment: why not check num_hexed == 16 ########## libs/libc/stdlib/lib_strtof.c: ########## @@ -149,26 +152,87 @@ float strtof(FAR const char *str, FAR char **endptr) /* Process string of digits */ - while (isdigit(*p)) + if (!isspace(*p) && *p == '0') { - number = number * 10.0F + (float)(*p - '0'); - p++; - num_digits++; + if (!isspace(*(p + 1)) && *(p + 1) == 'x') + { + p += 2; + flag_sixt = 1; + num_hexad = 16.0f; + } } - /* Process decimal part */ - - if (*p == '.') + if (flag_sixt == 1) { - p++; + while (isdigit(*p) || (*p >= 'A' && *p <= 'F') Review Comment: let's add a new function bool chtof(char c, float base, FAR float *number); to avoid the code dup ########## libs/libc/stdlib/lib_strtof.c: ########## @@ -149,26 +152,87 @@ float strtof(FAR const char *str, FAR char **endptr) /* Process string of digits */ - while (isdigit(*p)) + if (!isspace(*p) && *p == '0') Review Comment: ``` if (*p == '0' && tolower*(p+1) == 'x') { p += 2; ... } ``` ########## libs/libc/stdlib/lib_strtof.c: ########## @@ -113,6 +114,8 @@ float strtof(FAR const char *str, FAR char **endptr) * zero literal, but allows it through non-const variable set to zero */ + int flag_sixt = 0; /* the flag for hexadecimal support */ + float num_hexad = 10.0f; Review Comment: why not reuse p10? you can change to base if need. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org