Changeset 268

Show
Ignore:
Timestamp:
07/09/06 17:05:12 (2 years ago)
Author:
goodea
Message:

pseudo-official no float patch

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/lua51/linit.c

    r198 r268  
    2222  {LUA_OSLIBNAME, luaopen_os}, 
    2323  {LUA_STRLIBNAME, luaopen_string}, 
     24#if !defined LUA_NUMBER_INTEGRAL 
    2425  {LUA_MATHLIBNAME, luaopen_math}, 
     26#endif 
    2527  {LUA_DBLIBNAME, luaopen_debug}, 
    2628  {NULL, NULL} 
  • trunk/lib/lua51/lmathlib.c

    r198 r268  
    253253  lua_pushnumber(L, PI); 
    254254  lua_setfield(L, -2, "pi"); 
     255#if !defined LUA_NUMBER_INTEGRAL 
    255256  lua_pushnumber(L, HUGE_VAL); 
    256257  lua_setfield(L, -2, "huge"); 
     258#endif 
    257259#if defined(LUA_COMPAT_MOD) 
    258260  lua_getfield(L, -1, "fmod"); 
  • trunk/lib/lua51/loslib.c

    r266 r268  
    182182 
    183183 
     184#if !defined LUA_NUMBER_INTEGRAL 
    184185static int os_difftime (lua_State *L) { 
    185186  lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)), 
     
    187188  return 1; 
    188189} 
     190#endif 
    189191 
    190192/* }====================================================== */ 
     
    211213  {"clock",     os_clock}, 
    212214  {"date",      os_date}, 
     215#if !defined LUA_NUMBER_INTEGRAL 
    213216  {"difftime",  os_difftime}, 
     217#endif 
    214218  {"execute",   os_execute}, 
    215219  {"exit",      os_exit}, 
  • trunk/lib/lua51/lstrlib.c

    r266 r268  
    785785          break; 
    786786        } 
     787#if !defined LUA_NUMBER_INTEGRAL 
    787788        case 'e':  case 'E': case 'f': 
    788789        case 'g': case 'G': { 
     
    790791          break; 
    791792        } 
     793#endif 
    792794        case 'q': { 
    793795          addquoted(L, &b, arg); 
  • trunk/lib/lua51/luaconf.h

    r266 r268  
    141141** machines, ptrdiff_t gives a good choice between int or long.) 
    142142*/ 
    143 #define LUA_INTEGER     ptrdiff_t 
    144  
     143 
     144/* Changed to long for use with integral Lua numbers. */ 
     145#define LUA_INTEGER     long 
    145146 
    146147/* 
     
    501502*/ 
    502503 
     504/* Define LUA_NUMBER_INTEGRAL to produce a system that uses no 
     505   floating point operations by changing the type of Lua numbers from 
     506   double to long.  It implements division and modulus so that  
     507 
     508   x == (x / y) * y + x % y.   
     509    
     510   The exponentiation function returns zero for negative exponents. 
     511   Defining LUA_NUMBER_INTEGRAL also removes the difftime function, 
     512   and the math module should not be used.  The string.format function 
     513   no longer handles the floating point directives %e, %E, %f, %g, and 
     514   %G. */ 
     515 
     516#define LUA_NUMBER_INTEGRAL 
     517#if defined LUA_NUMBER_INTEGRAL 
     518#define LUA_NUMBER      long 
     519#else 
    503520#define LUA_NUMBER_DOUBLE 
    504521#define LUA_NUMBER      double 
     522#endif 
    505523 
    506524/* 
     
    508526@* over a number. 
    509527*/ 
    510 #define LUAI_UACNUMBER  double 
     528#define LUAI_UACNUMBER  LUA_NUMBER 
    511529 
    512530 
     
    518536@@ lua_str2number converts a string to a number. 
    519537*/ 
     538#if defined LUA_NUMBER_INTEGRAL 
     539#define LUA_NUMBER_SCAN         "%ld" 
     540#define LUA_NUMBER_FMT          "%ld" 
     541#else 
    520542#define LUA_NUMBER_SCAN         "%lf" 
    521543#define LUA_NUMBER_FMT          "%.14g" 
     544#endif 
    522545#define lua_number2str(s,n)     sprintf((s), LUA_NUMBER_FMT, (n)) 
    523546#define LUAI_MAXNUMBER2STR      32 /* 16 digits, sign, point, and \0 */ 
     547#if defined LUA_NUMBER_INTEGRAL 
     548#define lua_str2number(s,p)     strtol((s), (p), 10) 
     549#else 
    524550#define lua_str2number(s,p)     strtod((s), (p)) 
     551#endif 
    525552 
    526553 
     
    533560#define luai_numsub(a,b)        ((a)-(b)) 
    534561#define luai_nummul(a,b)        ((a)*(b)) 
     562#if defined LUA_NUMBER_INTEGRAL 
     563#define luai_numdiv(a,b)        \ 
     564  (-1/2?                        \ 
     565   (a)/(b):                     \ 
     566   ((a)<0==(b)<0||(a)%(b)==0?   \ 
     567    (a)/(b):                    \ 
     568    (a)/(b)-1)) 
     569#define luai_nummod(a,b)        \ 
     570  (-1/2?                        \ 
     571   (a)%(b):                     \ 
     572   ((a)<0==(b)<0||(a)%(b)==0?   \ 
     573    (a)%(b):                    \ 
     574    (a)%(b)+(b))) 
     575#define luai_lnumdiv(a,b)       \ 
     576  ((b)==0?                      \ 
     577   (luaG_runerror(L,"divide by zero"),0): \ 
     578   luai_numdiv(a,b)) 
     579#define luai_lnummod(a,b)       \ 
     580  ((b)==0?                      \ 
     581   (luaG_runerror(L,"modulo by zero"),0): \ 
     582   luai_nummod(a,b)) 
     583LUA_NUMBER luai_ipow(LUA_NUMBER, LUA_NUMBER); 
     584#define luai_numpow(a,b)        (luai_ipow(a,b)) 
     585#else 
    535586#define luai_numdiv(a,b)        ((a)/(b)) 
    536587#define luai_nummod(a,b)        ((a) - floor((a)/(b))*(b)) 
     588#define luai_lnumdiv(a,b)       (luai_numdiv(a,b)) 
     589#define luai_lnummod(a,b)       (luai_nummod(a,b)) 
    537590#define luai_numpow(a,b)        (pow(a,b)) 
     591#endif 
    538592#define luai_numunm(a)          (-(a)) 
    539593#define luai_numeq(a,b)         ((a)==(b)) 
  • trunk/lib/lua51/lvm.c

    r266 r268  
    2828 
    2929 
     30#if defined LUA_NUMBER_INTEGRAL 
     31LUA_NUMBER luai_ipow(LUA_NUMBER a, LUA_NUMBER b) { 
     32  if (b < 0) 
     33    return 0; 
     34  else if (b == 0) 
     35    return 1; 
     36  else { 
     37    LUA_NUMBER c = 1; 
     38    for (;;) { 
     39      if (b & 1) 
     40        c *= a; 
     41      b = b >> 1; 
     42      if (b == 0) 
     43        return c; 
     44      a *= a; 
     45    } 
     46  } 
     47} 
     48#endif 
    3049 
    3150/* limit for table tag-method chains (to avoid loops) */ 
     
    322341      case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break; 
    323342      case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break; 
    324       case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break; 
    325       case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break; 
     343      case TM_DIV: setnvalue(ra, luai_lnumdiv(nb, nc)); break; 
     344      case TM_MOD: setnvalue(ra, luai_lnummod(nb, nc)); break; 
    326345      case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break; 
    327346      case TM_UNM: setnvalue(ra, luai_numunm(nb)); break; 
     
    481500      } 
    482501      case OP_DIV: { 
    483         arith_op(luai_numdiv, TM_DIV); 
     502        arith_op(luai_lnumdiv, TM_DIV); 
    484503        continue; 
    485504      } 
    486505      case OP_MOD: { 
    487         arith_op(luai_nummod, TM_MOD); 
     506        arith_op(luai_lnummod, TM_MOD); 
    488507        continue; 
    489508      }