浏览代码

macros 'luai_num*' (for float arithmetic operations) moved to
llimits.h.

Roberto Ierusalimschy 10 年之前
父节点
当前提交
c8d6cb0136
共有 4 个文件被更改,包括 53 次插入46 次删除
  1. 48 1
      llimits.h
  2. 2 3
      lobject.c
  3. 1 41
      luaconf.h
  4. 2 1
      lvm.c

+ 48 - 1
llimits.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: llimits.h,v 1.128 2015/01/16 15:41:03 roberto Exp roberto $
+** $Id: llimits.h,v 1.129 2015/01/16 17:15:52 roberto Exp roberto $
 ** Limits, basic types, and some other 'installation-dependent' definitions
 ** Limits, basic types, and some other 'installation-dependent' definitions
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -242,6 +242,53 @@ typedef unsigned long Instruction;
 
 
 
 
 
 
+/*
+** The luai_num* macros define the primitive operations over numbers.
+*/
+
+/* floor division (defined as 'floor(a/b)') */
+#if !defined(luai_numidiv)
+#define luai_numidiv(L,a,b)     ((void)L, l_mathop(floor)(luai_numdiv(L,a,b)))
+#endif
+
+/* float division */
+#if !defined(luai_numdiv)
+#define luai_numdiv(L,a,b)      ((a)/(b))
+#endif
+
+/*
+** module: defined as 'a - floor(a/b)*b'; the previous definition gives
+** NaN when 'b' is huge, but the result should be 'a'. 'fmod' gives the
+** result of 'a - trunc(a/b)*b', and therefore must be corrected when
+** 'trunc(a/b) ~= floor(a/b)'. That happens when the division has a
+** non-integer negative result, which is equivalent to the test below
+*/
+#if !defined(luai_nummod)
+#define luai_nummod(L,a,b,m)  \
+  { (m) = l_mathop(fmod)(a,b); if ((m)*(b) < 0) (m) += (b); }
+#endif
+
+/* exponentiation */
+#if !defined(luai_numpow)
+#define luai_numpow(L,a,b)      ((void)L, l_mathop(pow)(a,b))
+#endif
+
+/* the others are quite standard operations */
+#if !defined(luai_numadd)
+#define luai_numadd(L,a,b)      ((a)+(b))
+#define luai_numsub(L,a,b)      ((a)-(b))
+#define luai_nummul(L,a,b)      ((a)*(b))
+#define luai_numunm(L,a)        (-(a))
+#define luai_numeq(a,b)         ((a)==(b))
+#define luai_numlt(a,b)         ((a)<(b))
+#define luai_numle(a,b)         ((a)<=(b))
+#define luai_numisnan(a)        (!luai_numeq((a), (a)))
+#endif
+
+
+
+
+
 /*
 /*
 ** macro to control inclusion of some hard tests on stack reallocation
 ** macro to control inclusion of some hard tests on stack reallocation
 */
 */

+ 2 - 3
lobject.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lobject.c,v 2.100 2014/11/21 12:15:57 roberto Exp roberto $
+** $Id: lobject.c,v 2.101 2014/12/26 14:43:45 roberto Exp roberto $
 ** Some generic functions over Lua objects
 ** Some generic functions over Lua objects
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -10,6 +10,7 @@
 #include "lprefix.h"
 #include "lprefix.h"
 
 
 
 
+#include <math.h>
 #include <stdarg.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
@@ -174,8 +175,6 @@ static int isneg (const char **s) {
 */
 */
 #if !defined(lua_strx2number)
 #if !defined(lua_strx2number)
 
 
-#include <math.h>
-
 /* maximum number of significant digits to read (to avoid overflows
 /* maximum number of significant digits to read (to avoid overflows
    even with single floats) */
    even with single floats) */
 #define MAXSIGDIG	30
 #define MAXSIGDIG	30

+ 1 - 41
luaconf.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: luaconf.h,v 1.243 2015/02/04 12:52:57 roberto Exp roberto $
+** $Id: luaconf.h,v 1.244 2015/02/05 16:53:34 roberto Exp roberto $
 ** Configuration file for Lua
 ** Configuration file for Lua
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -466,46 +466,6 @@
       (*(p) = (LUA_INTEGER)(n), 1))
       (*(p) = (LUA_INTEGER)(n), 1))
 
 
 
 
-/*
-@@ The luai_num* macros define the primitive operations over numbers.
-** They should work for any size of floating numbers.
-*/
-
-/* the following operations need the math library */
-#if defined(lobject_c) || defined(lvm_c)
-#include <math.h>
-
-/* floor division (defined as 'floor(a/b)') */
-#define luai_numidiv(L,a,b)	((void)L, l_mathop(floor)(luai_numdiv(L,a,b)))
-
-/*
-** module: defined as 'a - floor(a/b)*b'; the previous definition gives
-** NaN when 'b' is huge, but the result should be 'a'. 'fmod' gives the
-** result of 'a - trunc(a/b)*b', and therefore must be corrected when
-** 'trunc(a/b) ~= floor(a/b)'. That happens when the division has a
-** non-integer negative result, which is equivalent to the test below
-*/
-#define luai_nummod(L,a,b,m)  \
-  { (m) = l_mathop(fmod)(a,b); if ((m)*(b) < 0) (m) += (b); }
-
-/* exponentiation */
-#define luai_numpow(L,a,b)	((void)L, l_mathop(pow)(a,b))
-
-#endif
-
-/* these are quite standard operations */
-#if defined(LUA_CORE)
-#define luai_numadd(L,a,b)	((a)+(b))
-#define luai_numsub(L,a,b)	((a)-(b))
-#define luai_nummul(L,a,b)	((a)*(b))
-#define luai_numdiv(L,a,b)	((a)/(b))
-#define luai_numunm(L,a)	(-(a))
-#define luai_numeq(a,b)		((a)==(b))
-#define luai_numlt(a,b)		((a)<(b))
-#define luai_numle(a,b)		((a)<=(b))
-#define luai_numisnan(a)	(!luai_numeq((a), (a)))
-#endif
-
 
 
 /*
 /*
 @@ LUA_INTEGER is the integer type used by Lua.
 @@ LUA_INTEGER is the integer type used by Lua.

+ 2 - 1
lvm.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lvm.c,v 2.232 2014/12/27 20:30:38 roberto Exp roberto $
+** $Id: lvm.c,v 2.233 2015/01/16 16:54:37 roberto Exp roberto $
 ** Lua virtual machine
 ** Lua virtual machine
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -11,6 +11,7 @@
 
 
 
 
 #include <limits.h>
 #include <limits.h>
+#include <math.h>
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>