feat(str): add SStrToDouble

This commit is contained in:
Adam Heinermann 2025-08-31 16:40:16 -07:00 committed by fallenoak
parent 2408166d5d
commit 75dc4e57a6
3 changed files with 189 additions and 0 deletions

View file

@ -553,6 +553,105 @@ void SStrTokenize(const char** string, char* buffer, size_t bufferchars, const c
}
}
double SStrToDouble(const char* string) {
STORM_VALIDATE_BEGIN;
STORM_VALIDATE(string);
STORM_VALIDATE_END;
SStrInitialize();
double result;
bool negative = false;
if (*string == '-') {
negative = true;
string++;
}
double v16 = 10.0;
double v4 = 0.0;
uint32_t v5 = *string - '0';
const char* v6 = string;
if (v5 >= 10) {
v5 = 0;
result = static_cast<double>(v5);
} else {
string++;
uint32_t v8 = *string - '0';
if (v8 >= 10) {
result = static_cast<double>(v5);
} else {
do {
v5 = v8 + 10 * v5;
string++;
if (v5 >= 0x19999999) {
v4 = v4 * pow(10.0, string - v6) + static_cast<double>(v5);
v5 = 0;
v6 = string;
}
v8 = *string - '0';
} while (v8 < 10);
if (v4 == 0.0) {
result = static_cast<double>(v5);
} else {
result = pow(10.0, string - v6) * v4 + static_cast<double>(v5);
}
}
}
if (*string == '.') {
string++;
uint32_t v23 = *string - '0';
int32_t v24 = 0;
if (v23 < 10) {
int32_t v25 = 0;
int32_t v26 = -1;
double v31;
do {
string++;
if (v24 < 20) {
v31 = s_realDigit[0][v25 + v23];
} else {
v31 = pow(v16, v26) * v23;
}
result += v31;
v23 = *string - '0';
v24++;
v26--;
v25 += 10;
} while (v23 < 10);
}
}
if (*string == 'e' || *string == 'E') {
const char* v32 = string + 1;
if (*v32 == '+') {
v32++;
}
result *= pow(10.0, SStrToInt(v32));
}
if (negative) {
result = -result;
}
return result;
}
float SStrToFloat(const char* string) {
STORM_VALIDATE_BEGIN;
STORM_VALIDATE(string);

View file

@ -37,6 +37,8 @@ const char* SStrStr(const char* string, const char* search);
void SStrTokenize(const char** string, char* buffer, size_t bufferchars, const char* whitespace, int32_t* quoted);
double SStrToDouble(const char* string);
float SStrToFloat(const char* string);
int32_t SStrToInt(const char* string);