lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Jose Marin wrote:

I'm compiling Lua to use floats, altering the file
luser_number.h .

The macro lua_str2number uses strtod (returns a

I could cast to (float)strtod, but I'm worried abou

Is there some fast way of convert a string to a float?


strtod() works just fine; no cast is required:

#include <stdio.h>
#include <stdlib.h>

int main(void)
  float x = strtod("3.2", NULL);
  printf("%f\n", x);
  return 0;

You probably won't find anything faster, as your implementation's strtod() is probably written in nice fast assembly.

If you have a C99 conforming system, you can use strtof() instead. I don't know that you'll notice a performance difference between strtod() and strtof().