diff -urN lua-5.3.3/src/linit.c NoFlua-5.3.3/src/linit.c --- lua-5.3.3/src/linit.c +++ NoFlua-5.3.3/src/linit.c @@ -47,7 +47,9 @@ {LUA_IOLIBNAME, luaopen_io}, {LUA_OSLIBNAME, luaopen_os}, {LUA_STRLIBNAME, luaopen_string}, +#if !defined(LUA_NUMBER_INTEGRAL) {LUA_MATHLIBNAME, luaopen_math}, +#endif {LUA_UTF8LIBNAME, luaopen_utf8}, {LUA_DBLIBNAME, luaopen_debug}, #if defined(LUA_COMPAT_BITLIB) diff -urN lua-5.3.3/src/llimits.h NoFlua-5.3.3/src/llimits.h --- lua-5.3.3/src/llimits.h +++ NoFlua-5.3.3/src/llimits.h @@ -261,13 +261,21 @@ /* floor division (defined as 'floor(a/b)') */ #if !defined(luai_numidiv) +#if defined(LUA_NUMBER_INTEGRAL) +#define luai_numidiv luaV_div +#else #define luai_numidiv(L,a,b) ((void)L, l_floor(luai_numdiv(L,a,b))) #endif +#endif /* float division */ #if !defined(luai_numdiv) +#if defined(LUA_NUMBER_INTEGRAL) +#define luai_numdiv luaV_div +#else #define luai_numdiv(L,a,b) ((a)/(b)) #endif +#endif /* ** modulo: defined as 'a - floor(a/b)*b'; this definition gives NaN when @@ -277,14 +285,22 @@ ** negative result, which is equivalent to the test below. */ #if !defined(luai_nummod) +#if defined(LUA_NUMBER_INTEGRAL) +#define luai_nummod(L,a,b,m) { (m) = luaV_mod(L,a,b); } +#else #define luai_nummod(L,a,b,m) \ { (m) = l_mathop(fmod)(a,b); if ((m)*(b) < 0) (m) += (b); } #endif +#endif /* exponentiation */ #if !defined(luai_numpow) +#if defined(LUA_NUMBER_INTEGRAL) +#define luai_numpow luaV_pow +#else #define luai_numpow(L,a,b) ((void)L, l_mathop(pow)(a,b)) #endif +#endif /* the others are quite standard operations */ #if !defined(luai_numadd) diff -urN lua-5.3.3/src/lobject.c NoFlua-5.3.3/src/lobject.c --- lua-5.3.3/src/lobject.c +++ NoFlua-5.3.3/src/lobject.c @@ -174,6 +174,7 @@ +#if !defined(LUA_NUMBER_INTEGRAL) /* { */ /* ** {================================================================== ** Lua's implementation for 'lua_strx2number' @@ -291,6 +292,7 @@ } return endptr; } +#endif /* } */ #define MAXBY10 cast(lua_Unsigned, LUA_MAXINTEGER / 10) @@ -329,14 +331,16 @@ size_t luaO_str2num (const char *s, TValue *o) { - lua_Integer i; lua_Number n; + union { lua_Integer i; lua_Number n; } u; const char *e; - if ((e = l_str2int(s, &i)) != NULL) { /* try as an integer */ - setivalue(o, i); + if ((e = l_str2int(s, &u.i)) != NULL) { /* try as an integer */ + setivalue(o, u.i); } - else if ((e = l_str2d(s, &n)) != NULL) { /* else try as a float */ - setfltvalue(o, n); +#if !defined(LUA_NUMBER_INTEGRAL) + else if ((e = l_str2d(s, &u.n)) != NULL) { /* else try as a float */ + setfltvalue(o, u.n); } +#endif else return 0; /* conversion failed */ return (e - s) + 1; /* success; return string size */ @@ -376,7 +380,7 @@ len = lua_integer2str(buff, sizeof(buff), ivalue(obj)); else { len = lua_number2str(buff, sizeof(buff), fltvalue(obj)); -#if !defined(LUA_COMPAT_FLOATSTRING) +#if !defined(LUA_COMPAT_FLOATSTRING) && !defined(LUA_NUMBER_INTEGRAL) if (buff[strspn(buff, "-0123456789")] == '0円') { /* looks like an int? */ buff[len++] = lua_getlocaledecpoint(); buff[len++] = '0'; /* adds '.0' to result */ diff -urN lua-5.3.3/src/lobject.h NoFlua-5.3.3/src/lobject.h --- lua-5.3.3/src/lobject.h +++ NoFlua-5.3.3/src/lobject.h @@ -140,7 +140,11 @@ #define checktag(o,t) (rttype(o) == (t)) #define checktype(o,t) (ttnov(o) == (t)) #define ttisnumber(o) checktype((o), LUA_TNUMBER) +#if defined(LUA_NUMBER_INTEGRAL) +#define ttisfloat(o) 0 +#else #define ttisfloat(o) checktag((o), LUA_TNUMFLT) +#endif #define ttisinteger(o) checktag((o), LUA_TNUMINT) #define ttisnil(o) checktag((o), LUA_TNIL) #define ttisboolean(o) checktag((o), LUA_TBOOLEAN) @@ -195,8 +199,12 @@ /* Macros to set values */ #define settt_(o,t) ((o)->tt_=(t)) +#if defined(LUA_NUMBER_INTEGRAL) +#define setfltvalue setivalue +#else #define setfltvalue(obj,x) \ { TValue *io=(obj); val_(io).n=(x); settt_(io, LUA_TNUMFLT); } +#endif #define chgfltvalue(obj,x) \ { TValue *io=(obj); lua_assert(ttisfloat(io)); val_(io).n=(x); } diff -urN lua-5.3.3/src/lstrlib.c NoFlua-5.3.3/src/lstrlib.c --- lua-5.3.3/src/lstrlib.c +++ NoFlua-5.3.3/src/lstrlib.c @@ -807,7 +807,7 @@ ** ======================================================= */ -#if !defined(lua_number2strx) /* { */ +#if !defined(lua_number2strx) && !defined(LUA_NUMBER_INTEGRAL) /* { */ /* ** Hexadecimal floating-point formatter @@ -885,6 +885,9 @@ #endif /* } */ +#if defined(LUA_NUMBER_INTEGRAL) +#define MAX_ITEM 32 +#else /* ** Maximum size of each formatted item. This maximum size is produced ** by format('%.99f', -maxfloat), and is equal to 99 + 3 ('-', '.', @@ -894,6 +897,7 @@ */ #define MAX_ITEM (120 + l_mathlim(MAX_10_EXP)) +#endif /* valid flags in a format specification */ #define FLAGS "-+ #0" @@ -927,6 +931,7 @@ } +#if !defined(LUA_NUMBER_INTEGRAL) /* ** Ensures the 'buff' string uses a dot as the radix character. */ @@ -937,6 +942,7 @@ if (ppoint) *ppoint = '.'; /* change it to a dot */ } } +#endif static void addliteral (lua_State *L, luaL_Buffer *b, int arg) { @@ -950,12 +956,15 @@ case LUA_TNUMBER: { char *buff = luaL_prepbuffsize(b, MAX_ITEM); int nb; +#if !defined(LUA_NUMBER_INTEGRAL) if (!lua_isinteger(L, arg)) { /* float? */ lua_Number n = lua_tonumber(L, arg); /* write as hexa ('%a') */ nb = lua_number2strx(L, buff, MAX_ITEM, "%" LUA_NUMBER_FRMLEN "a", n); checkdp(buff, nb); /* ensure it uses a dot */ } - else { /* integers */ + else /* integers */ +#endif + { lua_Integer n = lua_tointeger(L, arg); const char *format = (n == LUA_MININTEGER) /* corner case? */ ? "0x%" LUA_INTEGER_FRMLEN "x" /* use hexa */ @@ -1044,6 +1053,7 @@ nb = l_sprintf(buff, MAX_ITEM, form, n); break; } +#if !defined(LUA_NUMBER_INTEGRAL) case 'a': case 'A': addlenmod(form, LUA_NUMBER_FRMLEN); nb = lua_number2strx(L, buff, MAX_ITEM, form, @@ -1055,6 +1065,7 @@ nb = l_sprintf(buff, MAX_ITEM, form, luaL_checknumber(L, arg)); break; } +#endif case 'q': { addliteral(L, &b, arg); break; diff -urN lua-5.3.3/src/ltable.c NoFlua-5.3.3/src/ltable.c --- lua-5.3.3/src/ltable.c +++ NoFlua-5.3.3/src/ltable.c @@ -95,7 +95,7 @@ ** adding 'i'; the use of '~u' (instead of '-u') avoids problems with ** INT_MIN. */ -#if !defined(l_hashfloat) +#if !defined(l_hashfloat) && !defined(LUA_NUMBER_INTEGRAL) static int l_hashfloat (lua_Number n) { int i; lua_Integer ni; @@ -118,10 +118,12 @@ */ static Node *mainposition (const Table *t, const TValue *key) { switch (ttype(key)) { - case LUA_TNUMINT: - return hashint(t, ivalue(key)); case LUA_TNUMFLT: +#if !defined(LUA_NUMBER_INTEGRAL) return hashmod(t, l_hashfloat(fltvalue(key))); +#endif + case LUA_TNUMINT: + return hashint(t, ivalue(key)); case LUA_TSHRSTR: return hashstr(t, tsvalue(key)); case LUA_TLNGSTR: diff -urN lua-5.3.3/src/luac.c NoFlua-5.3.3/src/luac.c --- lua-5.3.3/src/luac.c +++ NoFlua-5.3.3/src/luac.c @@ -267,7 +267,9 @@ char buff[100]; sprintf(buff,LUA_NUMBER_FMT,fltvalue(o)); printf("%s",buff); +#if !defined(LUA_NUMBER_INTEGRAL) if (buff[strspn(buff,"-0123456789")]=='0円') printf(".0"); +#endif break; } case LUA_TNUMINT: diff -urN lua-5.3.3/src/luaconf.h NoFlua-5.3.3/src/luaconf.h --- lua-5.3.3/src/luaconf.h +++ NoFlua-5.3.3/src/luaconf.h @@ -37,6 +37,12 @@ /* +@@ LUA_NUMBER_INTEGRAL disables use of floating point. +*/ +/* #define LUA_NUMBER_INTEGRAL */ + + +/* @@ LUA_USE_C89 controls the use of non-ISO-C89 features. ** Define it if you want Lua to avoid the use of a few C99 features ** or Windows-specific features on Windows. @@ -111,6 +117,7 @@ #define LUA_INT_LONGLONG 3 /* predefined options for LUA_FLOAT_TYPE */ +#define LUA_FLOAT_NONE 0 #define LUA_FLOAT_FLOAT 1 #define LUA_FLOAT_DOUBLE 2 #define LUA_FLOAT_LONGDOUBLE 3 @@ -147,6 +154,10 @@ #define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE #endif +#if defined(LUA_NUMBER_INTEGRAL) +#undef LUA_FLOAT_TYPE +#define LUA_FLOAT_TYPE LUA_FLOAT_NONE +#endif /* }================================================================== */ @@ -419,7 +430,11 @@ /* The following definitions are good for most cases here */ +#if defined(LUA_NUMBER_INTEGRAL) +#define l_floor(x) (x) +#else #define l_floor(x) (l_mathop(floor)(x)) +#endif #define lua_number2str(s,sz,n) l_sprintf((s), sz, LUA_NUMBER_FMT, (n)) @@ -431,10 +446,14 @@ ** has an exact representation as a float; MAXINTEGER may not have one, ** and therefore its conversion to float may have an ill-defined value.) */ +#if defined(LUA_NUMBER_INTEGRAL) +#define lua_numbertointeger(n,p) (*(p) = (n), 1) +#else #define lua_numbertointeger(n,p) \ ((n)>= (LUA_NUMBER)(LUA_MININTEGER) && \ (n) < -(LUA_NUMBER)(LUA_MININTEGER) && \ (*(p) = (LUA_INTEGER)(n), 1)) +#endif /* now the variable definitions */ @@ -485,6 +504,19 @@ #define lua_str2number(s,p) strtod((s), (p)) +#elif LUA_FLOAT_TYPE == LUA_FLOAT_NONE /* }{ no float */ + +#define LUA_NUMBER LUA_INTEGER + +#define LUAI_UACNUMBER LUAI_UACINT + +#define LUA_NUMBER_FRMLEN LUA_INTEGER_FRMLEN +#define LUA_NUMBER_FMT LUA_INTEGER_FMT + +#define l_mathop(op) op +/* l_mathop is dummy */ +/* l_mathlim and lua_str2number not used */ + #else /* }{ */ #error "numeric float type not defined" @@ -623,11 +655,13 @@ ** all files that use these macros.) */ #if defined(LUA_USE_C89) || (defined(HUGE_VAL) && !defined(HUGE_VALF)) +#if !defined(LUA_NUMBER_INTEGRAL) #undef l_mathop /* variants not available */ #undef lua_str2number #define l_mathop(op) (lua_Number)op /* no variant */ #define lua_str2number(s,p) ((lua_Number)strtod((s), (p))) #endif +#endif /* diff -urN lua-5.3.3/src/lvm.c NoFlua-5.3.3/src/lvm.c --- lua-5.3.3/src/lvm.c +++ NoFlua-5.3.3/src/lvm.c @@ -41,7 +41,7 @@ ** float without rounding. Used in comparisons. Left undefined if ** all integers fit in a float precisely. */ -#if !defined(l_intfitsf) +#if !defined(l_intfitsf) && !defined(LUA_NUMBER_INTEGRAL) /* number of bits in the mantissa of a float */ #define NBM (l_mathlim(MANT_DIG)) @@ -583,6 +583,40 @@ } } + +/* +** Integer power; return 'x ^ y'. +*/ +lua_Integer luaV_pow (lua_State *L, lua_Integer x, lua_Integer y) { + if (y == 0 || x == 1) + return 1; + else if (x == -1) { + if (y & 1) + return -1; + else + return 1; + } + else if (y < 0) { + if (x == 0) + luaG_runerror(L, "attempt to invert zero"); + if (x < 0 && (y & 1)) + return -1; /* floor rounding */ + else + return 0; + } + else { + lua_Integer p = 1; + for (;;) { + if (y & 1) + p *= x; + y>>= 1; + if (y == 0) + return p; + x *= x; + } + } +} + /* number of bits in an integer */ #define NBITS cast_int(sizeof(lua_Integer) * CHAR_BIT) diff -urN lua-5.3.3/src/lvm.h NoFlua-5.3.3/src/lvm.h --- lua-5.3.3/src/lvm.h +++ NoFlua-5.3.3/src/lvm.h @@ -107,6 +107,7 @@ LUAI_FUNC void luaV_concat (lua_State *L, int total); LUAI_FUNC lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y); LUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y); +LUAI_FUNC lua_Integer luaV_pow (lua_State *L, lua_Integer x, lua_Integer y); LUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y); LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb);
AltStyle
によって変換されたページ
(->オリジナル)
/
アドレス:
モード:
デフォルト
音声ブラウザ
ルビ付き
配色反転
文字拡大
モバイル