lua-users home
lua-l archive

Re: Using numbers as float

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


Jose Marin wrote:
Hi.
I'm compiling Lua to use floats, altering the file
luser_number.h .
The macro lua_str2number uses strtod (returns a
double).
I could cast to (float)strtod, but I'm worried abou
performance.
Is there some fast way of convert a string to a float?
Thanks!
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().
					-Mark

AltStyle によって変換されたページ (->オリジナル) /