new configuration macro 'l_mathlim' (simplifies some dependencies

on float type)
This commit is contained in:
Roberto Ierusalimschy
2015-05-20 14:39:23 -03:00
parent 0ec12c1bd1
commit 99391e24ea
2 changed files with 17 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lstrlib.c,v 1.227 2015/03/28 19:14:47 roberto Exp roberto $ ** $Id: lstrlib.c,v 1.228 2015/04/03 18:41:57 roberto Exp roberto $
** Standard library for string operations and pattern-matching ** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -11,6 +11,7 @@
#include <ctype.h> #include <ctype.h>
#include <float.h>
#include <limits.h> #include <limits.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
@@ -812,12 +813,10 @@ static int str_gsub (lua_State *L) {
/* /*
** Number of bits that goes into the first digit. It can be any value ** Number of bits that goes into the first digit. It can be any value
** between 1 and 4; the following definition tries to align the number ** between 1 and 4; the following definition tries to align the number
** to nibble boundaries. The default is 1 bit, that aligns double ** to nibble boundaries by making what is left after that first digit a
** (1+52-bit mantissa) and quad precision (1+112-bit mantissa). For ** multiple of 4.
** float (24-bit mantissa) and 80-bit long double (64-bit mantissa), 4
** does the alignment.
*/ */
#define L_NBFD ((sizeof(lua_Number) == 4 || sizeof(lua_Number) == 12) ? 4 : 1) #define L_NBFD ((l_mathlim(MANT_DIG) - 1)%4 + 1)
/* /*
@@ -881,11 +880,9 @@ static int lua_number2strx (lua_State *L, char *buff, const char *fmt,
/* /*
** Maximum size of each formatted item. This maximum size is produced ** Maximum size of each formatted item. This maximum size is produced
** by format('%.99f', minfloat), and is equal to 99 + 2 ('-' and '.') + ** by format('%.99f', minfloat), and is equal to 99 + 2 ('-' and '.') +
** number of decimal digits to represent minfloat (which is ~308 for ** number of decimal digits to represent minfloat.
** a double and ~4932 for long double).
*/ */
#define MAX_ITEM \ #define MAX_ITEM (120 + l_mathlim(MAX_10_EXP))
(sizeof(lua_Number) <= 4 ? 150 : sizeof(lua_Number) <= 8 ? 450 : 5050)
/* valid flags in a format specification */ /* valid flags in a format specification */

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: luaconf.h,v 1.249 2015/03/31 12:00:07 roberto Exp roberto $ ** $Id: luaconf.h,v 1.250 2015/04/03 18:41:57 roberto Exp roberto $
** Configuration file for Lua ** Configuration file for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -404,16 +404,14 @@
/* /*
@@ LUA_NUMBER is the floating-point type used by Lua. @@ LUA_NUMBER is the floating-point type used by Lua.
**
@@ LUAI_UACNUMBER is the result of an 'usual argument conversion' @@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
@@ over a floating number. @@ over a floating number.
** @@ l_mathlim(x) corrects limit name 'x' to the proper float type
** by prefixing it with one of FLT/DBL/LDBL.
@@ LUA_NUMBER_FRMLEN is the length modifier for writing floats. @@ LUA_NUMBER_FRMLEN is the length modifier for writing floats.
@@ LUA_NUMBER_FMT is the format for writing floats. @@ LUA_NUMBER_FMT is the format for writing floats.
@@ lua_number2str converts a float to a string. @@ lua_number2str converts a float to a string.
**
@@ l_mathop allows the addition of an 'l' or 'f' to all math operations. @@ l_mathop allows the addition of an 'l' or 'f' to all math operations.
**
@@ lua_str2number converts a decimal numeric string to a number. @@ lua_str2number converts a decimal numeric string to a number.
*/ */
@@ -421,6 +419,8 @@
#define LUA_NUMBER float #define LUA_NUMBER float
#define l_mathlim(n) (FLT_##n)
#define LUAI_UACNUMBER double #define LUAI_UACNUMBER double
#define LUA_NUMBER_FRMLEN "" #define LUA_NUMBER_FRMLEN ""
@@ -435,6 +435,8 @@
#define LUA_NUMBER long double #define LUA_NUMBER long double
#define l_mathlim(n) (LDBL_##n)
#define LUAI_UACNUMBER long double #define LUAI_UACNUMBER long double
#define LUA_NUMBER_FRMLEN "L" #define LUA_NUMBER_FRMLEN "L"
@@ -448,6 +450,8 @@
#define LUA_NUMBER double #define LUA_NUMBER double
#define l_mathlim(n) (DBL_##n)
#define LUAI_UACNUMBER double #define LUAI_UACNUMBER double
#define LUA_NUMBER_FRMLEN "" #define LUA_NUMBER_FRMLEN ""
@@ -620,7 +624,7 @@
#if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \ #if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \
__STDC_VERSION__ >= 199901L __STDC_VERSION__ >= 199901L
#include <stdint.h> #include <stdint.h>
#if defined (INTPTR_MAX) /* even in C99 this type is optional */ #if defined(INTPTR_MAX) /* even in C99 this type is optional */
#undef LUA_KCONTEXT #undef LUA_KCONTEXT
#define LUA_KCONTEXT intptr_t #define LUA_KCONTEXT intptr_t
#endif #endif