Last active
October 2, 2018 16:47
-
-
Save bgarcial/5f8c64ed091f0ea7e5fa1361efddcc99 to your computer and use it in GitHub Desktop.
Turn char to float with overrided stof function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void SerialDriver::draw(const core::visual::VisualParams* vparam) | |
{ | |
vparam = NULL; | |
draw(); | |
} | |
float stof(const char* s){ | |
float rez = 0, fact = 1; | |
if (*s == '-'){ | |
s++; | |
fact = -1; | |
} | |
for (int point_seen = 0; *s; s++){ | |
if (*s == '.'){ | |
point_seen = 1; | |
continue; | |
} | |
int d = *s - '0'; | |
if (d >= 0 && d <= 9){ | |
if (point_seen) fact /= 10.0f; | |
rez = rez * 10.0f + (float)d; | |
} | |
} | |
return rez * fact; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment