meta: move photon/libc to root
This commit is contained in:
33
libc/stdlib/strtof.c
Normal file
33
libc/stdlib/strtof.c
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <ctype.h>
|
||||
|
||||
float strtof(const char *str, char **endptr)
|
||||
{
|
||||
float res = 0.0F;
|
||||
char *ptr = (char*)str;
|
||||
int after_dot = 0;
|
||||
float div = 1;
|
||||
|
||||
while (*ptr != '\0') {
|
||||
if (isdigit(*ptr)) {
|
||||
if (!after_dot) {
|
||||
res *= 10;
|
||||
res += *ptr - '0';
|
||||
} else {
|
||||
div *= 10;
|
||||
res += (float)(*ptr - '0') / div;
|
||||
}
|
||||
} else if (*ptr == '.') {
|
||||
after_dot = 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
ptr++;
|
||||
}
|
||||
|
||||
if (endptr) {
|
||||
*endptr = ptr;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
Reference in New Issue
Block a user