mirror of
https://github.com/lua/lua
synced 2024-11-22 21:01:26 +03:00
new configuration macro 'l_mathlim' (simplifies some dependencies
on float type)
This commit is contained in:
parent
0ec12c1bd1
commit
99391e24ea
17
lstrlib.c
17
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 <ctype.h>
|
||||
#include <float.h>
|
||||
#include <limits.h>
|
||||
#include <stddef.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
|
||||
** 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 */
|
||||
|
16
luaconf.h
16
luaconf.h
@ -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
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -404,16 +404,14 @@
|
||||
|
||||
/*
|
||||
@@ LUA_NUMBER is the floating-point type used by Lua.
|
||||
**
|
||||
@@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
|
||||
@@ 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_FMT is the format for writing floats.
|
||||
@@ lua_number2str converts a float to a string.
|
||||
**
|
||||
@@ l_mathop allows the addition of an 'l' or 'f' to all math operations.
|
||||
**
|
||||
@@ lua_str2number converts a decimal numeric string to a number.
|
||||
*/
|
||||
|
||||
@ -421,6 +419,8 @@
|
||||
|
||||
#define LUA_NUMBER float
|
||||
|
||||
#define l_mathlim(n) (FLT_##n)
|
||||
|
||||
#define LUAI_UACNUMBER double
|
||||
|
||||
#define LUA_NUMBER_FRMLEN ""
|
||||
@ -435,6 +435,8 @@
|
||||
|
||||
#define LUA_NUMBER long double
|
||||
|
||||
#define l_mathlim(n) (LDBL_##n)
|
||||
|
||||
#define LUAI_UACNUMBER long double
|
||||
|
||||
#define LUA_NUMBER_FRMLEN "L"
|
||||
@ -448,6 +450,8 @@
|
||||
|
||||
#define LUA_NUMBER double
|
||||
|
||||
#define l_mathlim(n) (DBL_##n)
|
||||
|
||||
#define LUAI_UACNUMBER double
|
||||
|
||||
#define LUA_NUMBER_FRMLEN ""
|
||||
@ -620,7 +624,7 @@
|
||||
#if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \
|
||||
__STDC_VERSION__ >= 199901L
|
||||
#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
|
||||
#define LUA_KCONTEXT intptr_t
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user