diff -urN lua-5.1.4-orig/src/lmathlib.c lua-5.1.4/src/lmathlib.c --- lua-5.1.4-orig/src/lmathlib.c 2007-12-27 22:02:25 +0900 +++ lua-5.1.4/src/lmathlib.c 2010-06-09 10:57:16 +0900 @@ -17,10 +17,66 @@ #include "lualib.h" +#ifdef LUA_NUMBER_FLOAT + +#undef PI +#define PI (3.14159265f) +#define RADIANS_PER_DEGREE (PI/180.0f) + +#undef acos +#undef asin +#undef atan +#undef atan2 +#undef ceil +#undef cos +#undef cosh +#undef exp +#undef fabs +#undef floor +#undef fmod +#undef frexp +#undef ldexp +#undef log +#undef log10 +#undef modf +#undef pow +#undef sin +#undef sinh +#undef sqrt +#undef tan +#undef tanh + +#define acos acosf +#define asin asinf +#define atan atanf +#define atan2 atan2f +#define ceil ceilf +#define cos cosf +#define cosh coshf +#define exp expf +#define fabs fabsf +#define floor floorf +#define fmod fmodf +#define frexp frexpf +#define ldexp ldexpf +#define log logf +#define log10 log10f +#define modf modff +#define pow powf +#define sin sinf +#define sinh sinhf +#define sqrt sqrtf +#define tan tanf +#define tanh tanhf + +#else // !LUA_NUMBER_FLOAT + #undef PI #define PI (3.14159265358979323846) #define RADIANS_PER_DEGREE (PI/180.0) +#endif // LUA_NUMBER_FLOAT + static int math_abs (lua_State *L) { @@ -94,8 +150,13 @@ } static int math_modf (lua_State *L) { +#ifdef LUA_NUMBER_FLOAT + float ip; + float fp = modff(luaL_checknumber(L, 1), &ip); +#else double ip; double fp = modf(luaL_checknumber(L, 1), &ip); +#endif lua_pushnumber(L, ip); lua_pushnumber(L, fp); return 2; diff -urN lua-5.1.4-orig/src/luaconf.h lua-5.1.4/src/luaconf.h --- lua-5.1.4-orig/src/luaconf.h 2008-02-12 01:25:08 +0900 +++ lua-5.1.4/src/luaconf.h 2010-06-09 10:56:19 +0900 @@ -501,8 +501,9 @@ ** =================================================================== */ -#define LUA_NUMBER_DOUBLE -#define LUA_NUMBER double +/* #define LUA_NUMBER_DOUBLE */ +#define LUA_NUMBER_FLOAT +#define LUA_NUMBER float /* @@ LUAI_UACNUMBER is the result of an 'usual argument conversion' @@ -518,11 +519,11 @@ @@ LUAI_MAXNUMBER2STR is maximum size of previous conversion. @@ lua_str2number converts a string to a number. */ -#define LUA_NUMBER_SCAN "%lf" -#define LUA_NUMBER_FMT "%.14g" +#define LUA_NUMBER_SCAN "%f" +#define LUA_NUMBER_FMT "%g" #define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n)) #define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */ -#define lua_str2number(s,p) strtod((s), (p)) +#define lua_str2number(s,p) strtof((s), (p)) /* @@ -534,8 +535,8 @@ #define luai_numsub(a,b) ((a)-(b)) #define luai_nummul(a,b) ((a)*(b)) #define luai_numdiv(a,b) ((a)/(b)) -#define luai_nummod(a,b) ((a) - floor((a)/(b))*(b)) -#define luai_numpow(a,b) (pow(a,b)) +#define luai_nummod(a,b) ((a) - floorf((a)/(b))*(b)) +#define luai_numpow(a,b) (powf(a,b)) #define luai_numunm(a) (-(a)) #define luai_numeq(a,b) ((a)==(b)) #define luai_numlt(a,b) ((a)<(b))