braindead f32FromString
This commit is contained in:
@@ -704,6 +704,7 @@ fn Vec2f32 vec2FromHexCube(Vec2 map_center, XYZ cube, f32 size, f32 border_thick
|
|||||||
fn i32 i32Middle(i32 x, i32 y);
|
fn i32 i32Middle(i32 x, i32 y);
|
||||||
fn u32 u32Middle(u32 x, u32 y);
|
fn u32 u32Middle(u32 x, u32 y);
|
||||||
fn u64 u64SafeMul(u64 x, u64 y);
|
fn u64 u64SafeMul(u64 x, u64 y);
|
||||||
|
fn f32 f32FromString(String s);
|
||||||
|
|
||||||
///// MEMORY (Arenas)
|
///// MEMORY (Arenas)
|
||||||
#define ARENA_MAX GB(1)
|
#define ARENA_MAX GB(1)
|
||||||
@@ -751,6 +752,7 @@ fn u8 lowerAscii(u8 c);
|
|||||||
fn u8 upperAscii(u8 c);
|
fn u8 upperAscii(u8 c);
|
||||||
fn StringUTF16Const str16FromStr8(Arena* a, String string);
|
fn StringUTF16Const str16FromStr8(Arena* a, String string);
|
||||||
fn bool isAlphaUnderscoreSpace(u8 c);
|
fn bool isAlphaUnderscoreSpace(u8 c);
|
||||||
|
fn bool isNumeric(char c);
|
||||||
fn bool isSimplePrintable(u8 c);
|
fn bool isSimplePrintable(u8 c);
|
||||||
fn bool codepointIsWordBreak(Codepoint c);
|
fn bool codepointIsWordBreak(Codepoint c);
|
||||||
fn bool codepointIsWhitespace(Codepoint c);
|
fn bool codepointIsWhitespace(Codepoint c);
|
||||||
|
|||||||
@@ -146,3 +146,20 @@ fn u64 u64SafeMul(u64 x, u64 y) {
|
|||||||
return x * 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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -96,6 +96,10 @@ fn bool isAlphaUnderscoreSpace(u8 c) {
|
|||||||
|| c == '_');
|
|| c == '_');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn bool isNumeric(char c) {
|
||||||
|
return (c >= '0' && c <= '9') || c == '.';
|
||||||
|
}
|
||||||
|
|
||||||
fn bool codepointIsWordBreak(Codepoint c) {
|
fn bool codepointIsWordBreak(Codepoint c) {
|
||||||
return codepointIsWhitespace(c) ||
|
return codepointIsWhitespace(c) ||
|
||||||
c.code == ';' || c.code == ':' ||
|
c.code == ';' || c.code == ':' ||
|
||||||
|
|||||||
Reference in New Issue
Block a user