rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions
luaconf.h File Reference

Functions

float strtof_rusefi (const char *, char **)
 

Function Documentation

◆ strtof_rusefi()

float strtof_rusefi ( const char str,
char **  endPtr 
)

Definition at line 412 of file lua.cpp.

412 {
413 bool afterDecimalPoint = false;
414 float div = 1; // Divider to place digits after the decimal point
415
416 if (endPtr) {
417 *endPtr = const_cast<char*>(str);
418 }
419
420 float integerPart = 0;
421 float fractionalPart = 0;
422
423 while (*str != '\0') {
424 char c = *str;
425 int digitVal = c - '0';
426
427 if (c >= '0' && c <= '9') {
428 if (!afterDecimalPoint) {
429 // Integer part
430 integerPart = 10 * integerPart + digitVal;
431 } else {
432 // Fractional part
433 fractionalPart = 10 * fractionalPart + digitVal;
434 div *= 10;
435 }
436 } else if (c == '.') {
437 afterDecimalPoint = true;
438 } else {
439 break;
440 }
441
442 str++;
443
444 if (endPtr) {
445 *endPtr = const_cast<char*>(str);
446 }
447 }
448
449 return integerPart + fractionalPart / div;
450}

Go to the source code of this file.