mirror of https://github.com/rusefi/lua.git
new macro 'l_floor' (allows 'floorf' even when other math operations
do not have an 'f' variant)
This commit is contained in:
parent
55f566bd22
commit
453450d687
4
lapi.c
4
lapi.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lapi.c,v 2.181 2013/06/04 19:34:51 roberto Exp roberto $
|
** $Id: lapi.c,v 2.182 2013/06/14 18:32:45 roberto Exp roberto $
|
||||||
** Lua API
|
** Lua API
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -390,7 +390,7 @@ LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *pisnum) {
|
||||||
const lua_Number twop = (~(lua_Unsigned)0) + cast_num(1);
|
const lua_Number twop = (~(lua_Unsigned)0) + cast_num(1);
|
||||||
lua_Number n = fltvalue(o);
|
lua_Number n = fltvalue(o);
|
||||||
int neg = 0;
|
int neg = 0;
|
||||||
n = l_mathop(floor)(n);
|
n = l_floor(n);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
neg = 1;
|
neg = 1;
|
||||||
n = -n;
|
n = -n;
|
||||||
|
|
4
ltable.c
4
ltable.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: ltable.c,v 2.76 2013/05/27 12:43:37 roberto Exp roberto $
|
** $Id: ltable.c,v 2.77 2013/05/29 14:05:03 roberto Exp roberto $
|
||||||
** Lua tables (hash)
|
** Lua tables (hash)
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -70,7 +70,7 @@
|
||||||
/* checks whether a float has a value representable as a lua_Integer
|
/* checks whether a float has a value representable as a lua_Integer
|
||||||
(and does the conversion if so) */
|
(and does the conversion if so) */
|
||||||
#define numisinteger(x,i) \
|
#define numisinteger(x,i) \
|
||||||
(((x) == l_mathop(floor)(x)) && luaV_numtointeger(x, i))
|
(((x) == l_floor(x)) && luaV_numtointeger(x, i))
|
||||||
|
|
||||||
|
|
||||||
#define dummynode (&dummynode_)
|
#define dummynode (&dummynode_)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: luaconf.h,v 1.181 2013/05/26 13:35:52 roberto Exp roberto $
|
** $Id: luaconf.h,v 1.182 2013/06/13 19:35:08 roberto Exp roberto $
|
||||||
** Configuration file for Lua
|
** Configuration file for Lua
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -423,6 +423,7 @@
|
||||||
#define LUA_NUMBER_FMT "%.7g"
|
#define LUA_NUMBER_FMT "%.7g"
|
||||||
|
|
||||||
#define l_mathop(op) op##f
|
#define l_mathop(op) op##f
|
||||||
|
#define l_floor(x) (floorf(x))
|
||||||
|
|
||||||
#define lua_str2number(s,p) strtof((s), (p))
|
#define lua_str2number(s,p) strtof((s), (p))
|
||||||
|
|
||||||
|
@ -438,6 +439,7 @@
|
||||||
#define LUA_NUMBER_FMT "%.14g"
|
#define LUA_NUMBER_FMT "%.14g"
|
||||||
|
|
||||||
#define l_mathop(op) op
|
#define l_mathop(op) op
|
||||||
|
#define l_floor(x) (floor(x))
|
||||||
|
|
||||||
#define lua_str2number(s,p) strtod((s), (p))
|
#define lua_str2number(s,p) strtod((s), (p))
|
||||||
|
|
||||||
|
@ -452,7 +454,6 @@
|
||||||
#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
|
#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ The luai_num* macros define the primitive operations over numbers.
|
@@ The luai_num* macros define the primitive operations over numbers.
|
||||||
@* They should work for any size of floating numbers.
|
@* They should work for any size of floating numbers.
|
||||||
|
@ -461,7 +462,7 @@
|
||||||
/* the following operations need the math library */
|
/* the following operations need the math library */
|
||||||
#if defined(lobject_c) || defined(lvm_c)
|
#if defined(lobject_c) || defined(lvm_c)
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#define luai_nummod(L,a,b) ((a) - l_mathop(floor)((a)/(b))*(b))
|
#define luai_nummod(L,a,b) ((a) - l_floor((a)/(b))*(b))
|
||||||
#define luai_numpow(L,a,b) (l_mathop(pow)(a,b))
|
#define luai_numpow(L,a,b) (l_mathop(pow)(a,b))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
4
lvm.c
4
lvm.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lvm.c,v 2.173 2013/06/07 19:02:05 roberto Exp roberto $
|
** $Id: lvm.c,v 2.174 2013/06/19 14:27:00 roberto Exp roberto $
|
||||||
** Lua virtual machine
|
** Lua virtual machine
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -92,7 +92,7 @@ int luaV_tointeger_ (const TValue *obj, lua_Integer *p) {
|
||||||
lua_Number n;
|
lua_Number n;
|
||||||
lua_assert(!ttisinteger(obj));
|
lua_assert(!ttisinteger(obj));
|
||||||
if (tonumber(obj, &n)) {
|
if (tonumber(obj, &n)) {
|
||||||
n = l_mathop(floor)(n);
|
n = l_floor(n);
|
||||||
return luaV_numtointeger(n, p);
|
return luaV_numtointeger(n, p);
|
||||||
}
|
}
|
||||||
else return 0;
|
else return 0;
|
||||||
|
|
Loading…
Reference in New Issue