From 99391e24ea25641b0cf419334229452cef9e8581 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 20 May 2015 14:39:23 -0300 Subject: new configuration macro 'l_mathlim' (simplifies some dependencies on float type) --- lstrlib.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'lstrlib.c') diff --git a/lstrlib.c b/lstrlib.c index fb6c54c2..ec9c7d20 100644 --- a/lstrlib.c +++ b/lstrlib.c @@ -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 ** See Copyright Notice in lua.h */ @@ -11,6 +11,7 @@ #include +#include #include #include #include @@ -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 ** between 1 and 4; the following definition tries to align the number -** to nibble boundaries. The default is 1 bit, that aligns double -** (1+52-bit mantissa) and quad precision (1+112-bit mantissa). For -** float (24-bit mantissa) and 80-bit long double (64-bit mantissa), 4 -** does the alignment. +** to nibble boundaries by making what is left after that first digit a +** multiple of 4. */ -#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 ** by format('%.99f', minfloat), and is equal to 99 + 2 ('-' and '.') + -** number of decimal digits to represent minfloat (which is ~308 for -** a double and ~4932 for long double). +** number of decimal digits to represent minfloat. */ -#define MAX_ITEM \ - (sizeof(lua_Number) <= 4 ? 150 : sizeof(lua_Number) <= 8 ? 450 : 5050) +#define MAX_ITEM (120 + l_mathlim(MAX_10_EXP)) /* valid flags in a format specification */ -- cgit v1.2.3-55-g6feb