braindead f32FromString
This commit is contained in:
1 parent
59d4f44ea8
commit
1c8a0c27b2
3 files changed
+23
No files matched your search
@@ -146,3 +146,20 @@ fn u64 u64SafeMul(u64 x, u64 y) {
|
||||
return x * y;
|
||||
}
|
||||
|
||||
fn f32 f32FromString(String s) {
|
||||
f32 result = 0.0f;
|
||||
if (s.length == 0) { return result; }
|
||||
ptr c = s.bytes;
|
||||
while (*c >= '0' && *c <= '9') {
|
||||
result = result * 10.0f + (*c++ - '0');
|
||||
}
|
||||
if (*c == '.') {
|
||||
c++;
|
||||
f32 frac = 0.1f;
|
||||
while (*c >= '0' && *c <= '9') {
|
||||
result += (*c++ - '0') * frac;
|
||||
frac *= 0.1f;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Reference in new issue
Block a user