Skip to content

Instantly share code, notes, and snippets.

@bgarcial
Last active October 2, 2018 16:47
Show Gist options
  • Save bgarcial/5f8c64ed091f0ea7e5fa1361efddcc99 to your computer and use it in GitHub Desktop.
Save bgarcial/5f8c64ed091f0ea7e5fa1361efddcc99 to your computer and use it in GitHub Desktop.
Turn char to float with overrided stof function
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