Changeset 268
- Timestamp:
- 07/09/06 17:05:12 (2 years ago)
- Files:
-
- trunk/lib/lua51/linit.c (modified) (1 diff)
- trunk/lib/lua51/lmathlib.c (modified) (1 diff)
- trunk/lib/lua51/loslib.c (modified) (3 diffs)
- trunk/lib/lua51/lstrlib.c (modified) (2 diffs)
- trunk/lib/lua51/luaconf.h (modified) (5 diffs)
- trunk/lib/lua51/lvm.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/lua51/linit.c
r198 r268 22 22 {LUA_OSLIBNAME, luaopen_os}, 23 23 {LUA_STRLIBNAME, luaopen_string}, 24 #if !defined LUA_NUMBER_INTEGRAL 24 25 {LUA_MATHLIBNAME, luaopen_math}, 26 #endif 25 27 {LUA_DBLIBNAME, luaopen_debug}, 26 28 {NULL, NULL} trunk/lib/lua51/lmathlib.c
r198 r268 253 253 lua_pushnumber(L, PI); 254 254 lua_setfield(L, -2, "pi"); 255 #if !defined LUA_NUMBER_INTEGRAL 255 256 lua_pushnumber(L, HUGE_VAL); 256 257 lua_setfield(L, -2, "huge"); 258 #endif 257 259 #if defined(LUA_COMPAT_MOD) 258 260 lua_getfield(L, -1, "fmod"); trunk/lib/lua51/loslib.c
r266 r268 182 182 183 183 184 #if !defined LUA_NUMBER_INTEGRAL 184 185 static int os_difftime (lua_State *L) { 185 186 lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)), … … 187 188 return 1; 188 189 } 190 #endif 189 191 190 192 /* }====================================================== */ … … 211 213 {"clock", os_clock}, 212 214 {"date", os_date}, 215 #if !defined LUA_NUMBER_INTEGRAL 213 216 {"difftime", os_difftime}, 217 #endif 214 218 {"execute", os_execute}, 215 219 {"exit", os_exit}, trunk/lib/lua51/lstrlib.c
r266 r268 785 785 break; 786 786 } 787 #if !defined LUA_NUMBER_INTEGRAL 787 788 case 'e': case 'E': case 'f': 788 789 case 'g': case 'G': { … … 790 791 break; 791 792 } 793 #endif 792 794 case 'q': { 793 795 addquoted(L, &b, arg); trunk/lib/lua51/luaconf.h
r266 r268 141 141 ** machines, ptrdiff_t gives a good choice between int or long.) 142 142 */ 143 #define LUA_INTEGER ptrdiff_t 144 143 144 /* Changed to long for use with integral Lua numbers. */ 145 #define LUA_INTEGER long 145 146 146 147 /* … … 501 502 */ 502 503 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 503 520 #define LUA_NUMBER_DOUBLE 504 521 #define LUA_NUMBER double 522 #endif 505 523 506 524 /* … … 508 526 @* over a number. 509 527 */ 510 #define LUAI_UACNUMBER double528 #define LUAI_UACNUMBER LUA_NUMBER 511 529 512 530 … … 518 536 @@ lua_str2number converts a string to a number. 519 537 */ 538 #if defined LUA_NUMBER_INTEGRAL 539 #define LUA_NUMBER_SCAN "%ld" 540 #define LUA_NUMBER_FMT "%ld" 541 #else 520 542 #define LUA_NUMBER_SCAN "%lf" 521 543 #define LUA_NUMBER_FMT "%.14g" 544 #endif 522 545 #define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n)) 523 546 #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 524 550 #define lua_str2number(s,p) strtod((s), (p)) 551 #endif 525 552 526 553 … … 533 560 #define luai_numsub(a,b) ((a)-(b)) 534 561 #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)) 583 LUA_NUMBER luai_ipow(LUA_NUMBER, LUA_NUMBER); 584 #define luai_numpow(a,b) (luai_ipow(a,b)) 585 #else 535 586 #define luai_numdiv(a,b) ((a)/(b)) 536 587 #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)) 537 590 #define luai_numpow(a,b) (pow(a,b)) 591 #endif 538 592 #define luai_numunm(a) (-(a)) 539 593 #define luai_numeq(a,b) ((a)==(b)) trunk/lib/lua51/lvm.c
r266 r268 28 28 29 29 30 #if defined LUA_NUMBER_INTEGRAL 31 LUA_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 30 49 31 50 /* limit for table tag-method chains (to avoid loops) */ … … 322 341 case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break; 323 342 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; 326 345 case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break; 327 346 case TM_UNM: setnvalue(ra, luai_numunm(nb)); break; … … 481 500 } 482 501 case OP_DIV: { 483 arith_op(luai_ numdiv, TM_DIV);502 arith_op(luai_lnumdiv, TM_DIV); 484 503 continue; 485 504 } 486 505 case OP_MOD: { 487 arith_op(luai_ nummod, TM_MOD);506 arith_op(luai_lnummod, TM_MOD); 488 507 continue; 489 508 }
