diff options
-rw-r--r-- | lstrlib.c | 17 | ||||
-rw-r--r-- | luaconf.h | 16 |
2 files changed, 17 insertions, 16 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstrlib.c,v 1.227 2015/03/28 19:14:47 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.228 2015/04/03 18:41:57 roberto Exp roberto $ |
3 | ** Standard library for string operations and pattern-matching | 3 | ** Standard library for string operations and pattern-matching |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -11,6 +11,7 @@ | |||
11 | 11 | ||
12 | 12 | ||
13 | #include <ctype.h> | 13 | #include <ctype.h> |
14 | #include <float.h> | ||
14 | #include <limits.h> | 15 | #include <limits.h> |
15 | #include <stddef.h> | 16 | #include <stddef.h> |
16 | #include <stdio.h> | 17 | #include <stdio.h> |
@@ -812,12 +813,10 @@ static int str_gsub (lua_State *L) { | |||
812 | /* | 813 | /* |
813 | ** Number of bits that goes into the first digit. It can be any value | 814 | ** Number of bits that goes into the first digit. It can be any value |
814 | ** between 1 and 4; the following definition tries to align the number | 815 | ** between 1 and 4; the following definition tries to align the number |
815 | ** to nibble boundaries. The default is 1 bit, that aligns double | 816 | ** to nibble boundaries by making what is left after that first digit a |
816 | ** (1+52-bit mantissa) and quad precision (1+112-bit mantissa). For | 817 | ** multiple of 4. |
817 | ** float (24-bit mantissa) and 80-bit long double (64-bit mantissa), 4 | ||
818 | ** does the alignment. | ||
819 | */ | 818 | */ |
820 | #define L_NBFD ((sizeof(lua_Number) == 4 || sizeof(lua_Number) == 12) ? 4 : 1) | 819 | #define L_NBFD ((l_mathlim(MANT_DIG) - 1)%4 + 1) |
821 | 820 | ||
822 | 821 | ||
823 | /* | 822 | /* |
@@ -881,11 +880,9 @@ static int lua_number2strx (lua_State *L, char *buff, const char *fmt, | |||
881 | /* | 880 | /* |
882 | ** Maximum size of each formatted item. This maximum size is produced | 881 | ** Maximum size of each formatted item. This maximum size is produced |
883 | ** by format('%.99f', minfloat), and is equal to 99 + 2 ('-' and '.') + | 882 | ** by format('%.99f', minfloat), and is equal to 99 + 2 ('-' and '.') + |
884 | ** number of decimal digits to represent minfloat (which is ~308 for | 883 | ** number of decimal digits to represent minfloat. |
885 | ** a double and ~4932 for long double). | ||
886 | */ | 884 | */ |
887 | #define MAX_ITEM \ | 885 | #define MAX_ITEM (120 + l_mathlim(MAX_10_EXP)) |
888 | (sizeof(lua_Number) <= 4 ? 150 : sizeof(lua_Number) <= 8 ? 450 : 5050) | ||
889 | 886 | ||
890 | 887 | ||
891 | /* valid flags in a format specification */ | 888 | /* valid flags in a format specification */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: luaconf.h,v 1.249 2015/03/31 12:00:07 roberto Exp roberto $ | 2 | ** $Id: luaconf.h,v 1.250 2015/04/03 18:41:57 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 | */ |
@@ -404,16 +404,14 @@ | |||
404 | 404 | ||
405 | /* | 405 | /* |
406 | @@ LUA_NUMBER is the floating-point type used by Lua. | 406 | @@ LUA_NUMBER is the floating-point type used by Lua. |
407 | ** | ||
408 | @@ LUAI_UACNUMBER is the result of an 'usual argument conversion' | 407 | @@ LUAI_UACNUMBER is the result of an 'usual argument conversion' |
409 | @@ over a floating number. | 408 | @@ over a floating number. |
410 | ** | 409 | @@ l_mathlim(x) corrects limit name 'x' to the proper float type |
410 | ** by prefixing it with one of FLT/DBL/LDBL. | ||
411 | @@ LUA_NUMBER_FRMLEN is the length modifier for writing floats. | 411 | @@ LUA_NUMBER_FRMLEN is the length modifier for writing floats. |
412 | @@ LUA_NUMBER_FMT is the format for writing floats. | 412 | @@ LUA_NUMBER_FMT is the format for writing floats. |
413 | @@ lua_number2str converts a float to a string. | 413 | @@ lua_number2str converts a float to a string. |
414 | ** | ||
415 | @@ l_mathop allows the addition of an 'l' or 'f' to all math operations. | 414 | @@ l_mathop allows the addition of an 'l' or 'f' to all math operations. |
416 | ** | ||
417 | @@ lua_str2number converts a decimal numeric string to a number. | 415 | @@ lua_str2number converts a decimal numeric string to a number. |
418 | */ | 416 | */ |
419 | 417 | ||
@@ -421,6 +419,8 @@ | |||
421 | 419 | ||
422 | #define LUA_NUMBER float | 420 | #define LUA_NUMBER float |
423 | 421 | ||
422 | #define l_mathlim(n) (FLT_##n) | ||
423 | |||
424 | #define LUAI_UACNUMBER double | 424 | #define LUAI_UACNUMBER double |
425 | 425 | ||
426 | #define LUA_NUMBER_FRMLEN "" | 426 | #define LUA_NUMBER_FRMLEN "" |
@@ -435,6 +435,8 @@ | |||
435 | 435 | ||
436 | #define LUA_NUMBER long double | 436 | #define LUA_NUMBER long double |
437 | 437 | ||
438 | #define l_mathlim(n) (LDBL_##n) | ||
439 | |||
438 | #define LUAI_UACNUMBER long double | 440 | #define LUAI_UACNUMBER long double |
439 | 441 | ||
440 | #define LUA_NUMBER_FRMLEN "L" | 442 | #define LUA_NUMBER_FRMLEN "L" |
@@ -448,6 +450,8 @@ | |||
448 | 450 | ||
449 | #define LUA_NUMBER double | 451 | #define LUA_NUMBER double |
450 | 452 | ||
453 | #define l_mathlim(n) (DBL_##n) | ||
454 | |||
451 | #define LUAI_UACNUMBER double | 455 | #define LUAI_UACNUMBER double |
452 | 456 | ||
453 | #define LUA_NUMBER_FRMLEN "" | 457 | #define LUA_NUMBER_FRMLEN "" |
@@ -620,7 +624,7 @@ | |||
620 | #if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \ | 624 | #if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \ |
621 | __STDC_VERSION__ >= 199901L | 625 | __STDC_VERSION__ >= 199901L |
622 | #include <stdint.h> | 626 | #include <stdint.h> |
623 | #if defined (INTPTR_MAX) /* even in C99 this type is optional */ | 627 | #if defined(INTPTR_MAX) /* even in C99 this type is optional */ |
624 | #undef LUA_KCONTEXT | 628 | #undef LUA_KCONTEXT |
625 | #define LUA_KCONTEXT intptr_t | 629 | #define LUA_KCONTEXT intptr_t |
626 | #endif | 630 | #endif |