diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-06-24 14:02:00 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-06-24 14:02:00 -0300 |
| commit | 54ac5960a800c32d7d9824d15b14a31131301678 (patch) | |
| tree | 5f073d72060f1018b043941c42c34143e2358b4c | |
| parent | 0e6229a95333fe33858580a7d4094c841b52a611 (diff) | |
| download | lua-54ac5960a800c32d7d9824d15b14a31131301678.tar.gz lua-54ac5960a800c32d7d9824d15b14a31131301678.tar.bz2 lua-54ac5960a800c32d7d9824d15b14a31131301678.zip | |
LUA_MAXUNSIGNED was only used to define 2.0^intnumbits (and that
definition was not strictly portable), so it was removed and
replaced by a more correct and direct definition for 2.0^intnumbits
(only where it was needed)
| -rw-r--r-- | lapi.c | 9 | ||||
| -rw-r--r-- | luaconf.h | 8 |
2 files changed, 8 insertions, 9 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.218 2014/06/12 19:07:30 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.219 2014/06/19 18:27:20 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -372,6 +372,11 @@ LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) { | |||
| 372 | } | 372 | } |
| 373 | 373 | ||
| 374 | 374 | ||
| 375 | #if !defined(LUAI_FTWO2N) | ||
| 376 | /* 2.0^(numbits in an integer), computed without roundings */ | ||
| 377 | #define LUAI_FTWO2N (cast_num(LUA_MININTEGER) * cast_num(-2)) | ||
| 378 | #endif | ||
| 379 | |||
| 375 | LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *pisnum) { | 380 | LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *pisnum) { |
| 376 | lua_Unsigned res = 0; | 381 | lua_Unsigned res = 0; |
| 377 | const TValue *o = index2addr(L, idx); | 382 | const TValue *o = index2addr(L, idx); |
| @@ -383,7 +388,7 @@ LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *pisnum) { | |||
| 383 | break; | 388 | break; |
| 384 | } | 389 | } |
| 385 | case LUA_TNUMFLT: { /* compute floor(n) % 2^(numbits in an integer) */ | 390 | case LUA_TNUMFLT: { /* compute floor(n) % 2^(numbits in an integer) */ |
| 386 | const lua_Number two2n = cast_num(LUA_MAXUNSIGNED) + cast_num(1); | 391 | const lua_Number two2n = LUAI_FTWO2N; |
| 387 | lua_Number n = fltvalue(o); /* get value */ | 392 | lua_Number n = fltvalue(o); /* get value */ |
| 388 | int neg = 0; | 393 | int neg = 0; |
| 389 | n = l_floor(n); /* get its floor */ | 394 | n = l_floor(n); /* get its floor */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: luaconf.h,v 1.206 2014/06/02 00:03:16 roberto Exp roberto $ | 2 | ** $Id: luaconf.h,v 1.207 2014/06/10 19:21:20 roberto Exp roberto $ |
| 3 | ** Configuration file for Lua | 3 | ** Configuration file for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -569,7 +569,6 @@ | |||
| 569 | @@ LUA_INTEGER_FMT is the format for writing integers. | 569 | @@ LUA_INTEGER_FMT is the format for writing integers. |
| 570 | @@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER. | 570 | @@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER. |
| 571 | @@ LUA_MININTEGER is the minimum value for a LUA_INTEGER. | 571 | @@ LUA_MININTEGER is the minimum value for a LUA_INTEGER. |
| 572 | @@ LUA_MAXUNSIGNED is the maximum value for a LUA_UNSIGNED. | ||
| 573 | @@ lua_integer2str converts an integer to a string. | 572 | @@ lua_integer2str converts an integer to a string. |
| 574 | */ | 573 | */ |
| 575 | 574 | ||
| @@ -595,7 +594,6 @@ | |||
| 595 | #define LUA_INTEGER int | 594 | #define LUA_INTEGER int |
| 596 | #define LUA_INTEGER_FRMLEN "" | 595 | #define LUA_INTEGER_FRMLEN "" |
| 597 | 596 | ||
| 598 | #define LUA_MAXUNSIGNED UINT_MAX | ||
| 599 | #define LUA_MAXINTEGER INT_MAX | 597 | #define LUA_MAXINTEGER INT_MAX |
| 600 | #define LUA_MININTEGER INT_MIN | 598 | #define LUA_MININTEGER INT_MIN |
| 601 | 599 | ||
| @@ -604,7 +602,6 @@ | |||
| 604 | #define LUA_INTEGER long | 602 | #define LUA_INTEGER long |
| 605 | #define LUA_INTEGER_FRMLEN "l" | 603 | #define LUA_INTEGER_FRMLEN "l" |
| 606 | 604 | ||
| 607 | #define LUA_MAXUNSIGNED ULONG_MAX | ||
| 608 | #define LUA_MAXINTEGER LONG_MAX | 605 | #define LUA_MAXINTEGER LONG_MAX |
| 609 | #define LUA_MININTEGER LONG_MIN | 606 | #define LUA_MININTEGER LONG_MIN |
| 610 | 607 | ||
| @@ -615,7 +612,6 @@ | |||
| 615 | #define LUA_INTEGER __int64 | 612 | #define LUA_INTEGER __int64 |
| 616 | #define LUA_INTEGER_FRMLEN "I64" | 613 | #define LUA_INTEGER_FRMLEN "I64" |
| 617 | 614 | ||
| 618 | #define LUA_MAXUNSIGNED _UI64_MAX | ||
| 619 | #define LUA_MAXINTEGER _I64_MAX | 615 | #define LUA_MAXINTEGER _I64_MAX |
| 620 | #define LUA_MININTEGER _I64_MIN | 616 | #define LUA_MININTEGER _I64_MIN |
| 621 | 617 | ||
| @@ -624,7 +620,6 @@ | |||
| 624 | #define LUA_INTEGER long long | 620 | #define LUA_INTEGER long long |
| 625 | #define LUA_INTEGER_FRMLEN "ll" | 621 | #define LUA_INTEGER_FRMLEN "ll" |
| 626 | 622 | ||
| 627 | #define LUA_MAXUNSIGNED ULLONG_MAX | ||
| 628 | #define LUA_MAXINTEGER LLONG_MAX | 623 | #define LUA_MAXINTEGER LLONG_MAX |
| 629 | #define LUA_MININTEGER LLONG_MIN | 624 | #define LUA_MININTEGER LLONG_MIN |
| 630 | 625 | ||
| @@ -639,7 +634,6 @@ | |||
| 639 | #define LUA_INTEGER short int | 634 | #define LUA_INTEGER short int |
| 640 | #define LUA_INTEGER_FRMLEN "" | 635 | #define LUA_INTEGER_FRMLEN "" |
| 641 | 636 | ||
| 642 | #define LUA_MAXUNSIGNED ((LUA_UNSIGNED)USHRT_MAX) | ||
| 643 | #define LUA_MAXINTEGER SHRT_MAX | 637 | #define LUA_MAXINTEGER SHRT_MAX |
| 644 | #define LUA_MININTEGER SHRT_MIN | 638 | #define LUA_MININTEGER SHRT_MIN |
| 645 | 639 | ||
