isle-portable/ISLE/xbox/atof.c
VoxelTek f30144c239 More bad ""fixes"" to get it compiling
At least it now compiles...???

This definitely needs to be fixed up later.
2025-08-07 14:44:37 +10:00

41 lines
770 B
C

// atof.c
#include <ctype.h>
// A lightweight atof alternative
double atof(const char *s) {
double result = 0.0;
int sign = 1;
double fraction = 0.0;
int divisor = 1;
// Skip whitespace
while (*s == ' ' || *s == '\t') s++;
// Handle sign
if (*s == '-') {
sign = -1;
s++;
} else if (*s == '+') {
s++;
}
// Integer part
while (*s >= '0' && *s <= '9') {
result = result * 10.0 + (*s - '0');
s++;
}
// Fractional part
if (*s == '.') {
s++;
while (*s >= '0' && *s <= '9') {
fraction = fraction * 10.0 + (*s - '0');
divisor *= 10;
s++;
}
result += fraction / divisor;
}
return sign * result;
}