aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lmathlib.c4
-rw-r--r--luaconf.h7
-rw-r--r--lvm.c19
3 files changed, 16 insertions, 14 deletions
diff --git a/lmathlib.c b/lmathlib.c
index 9da84f3e..4609e3b2 100644
--- a/lmathlib.c
+++ b/lmathlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmathlib.c,v 1.60 2004/04/30 20:13:38 roberto Exp roberto $ 2** $Id: lmathlib.c,v 1.61 2004/05/10 18:11:32 roberto Exp roberto $
3** Standard mathematical library 3** Standard mathematical library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -225,8 +225,6 @@ LUALIB_API int luaopen_math (lua_State *L) {
225 luaL_openlib(L, LUA_MATHLIBNAME, mathlib, 0); 225 luaL_openlib(L, LUA_MATHLIBNAME, mathlib, 0);
226 lua_pushnumber(L, PI); 226 lua_pushnumber(L, PI);
227 lua_setfield(L, -2, "pi"); 227 lua_setfield(L, -2, "pi");
228 lua_pushcfunction(L, math_pow);
229 lua_setglobal(L, "__pow");
230 return 1; 228 return 1;
231} 229}
232 230
diff --git a/luaconf.h b/luaconf.h
index 905a00ca..6d3d34f8 100644
--- a/luaconf.h
+++ b/luaconf.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: luaconf.h,v 1.22 2004/12/27 15:58:15 roberto Exp roberto $ 2** $Id: luaconf.h,v 1.23 2005/01/04 12:46:04 roberto Exp roberto $
3** Configuration file for Lua 3** Configuration file for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -257,6 +257,11 @@ __inline int l_lrint (double flt)
257#define LUA_UACNUMBER double 257#define LUA_UACNUMBER double
258 258
259 259
260/* primitive `^' operator for numbers */
261#include <math.h>
262#define lua_pow(a,b) pow(a,b)
263
264
260 265
261/* type to ensure maximum alignment */ 266/* type to ensure maximum alignment */
262#define LUSER_ALIGNMENT_T union { double u; void *s; long l; } 267#define LUSER_ALIGNMENT_T union { double u; void *s; long l; }
diff --git a/lvm.c b/lvm.c
index 2f9612c4..d8e47233 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.19 2005/01/04 15:55:12 roberto Exp roberto $ 2** $Id: lvm.c,v 2.20 2005/01/05 18:20:51 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -339,14 +339,7 @@ static StkId Arith (lua_State *L, StkId ra, const TValue *rb,
339 case TM_SUB: setnvalue(ra, nvalue(b) - nvalue(c)); break; 339 case TM_SUB: setnvalue(ra, nvalue(b) - nvalue(c)); break;
340 case TM_MUL: setnvalue(ra, nvalue(b) * nvalue(c)); break; 340 case TM_MUL: setnvalue(ra, nvalue(b) * nvalue(c)); break;
341 case TM_DIV: setnvalue(ra, nvalue(b) / nvalue(c)); break; 341 case TM_DIV: setnvalue(ra, nvalue(b) / nvalue(c)); break;
342 case TM_POW: { 342 case TM_POW: setnvalue(ra, lua_pow(nvalue(b), nvalue(c))); break;
343 const TValue *f = luaH_getstr(hvalue(gt(L)), G(L)->tmname[TM_POW]);
344 if (!ttisfunction(f))
345 luaG_runerror(L, "`__pow' (`^' operator) is not a function");
346 prepTMcall(L, f, b, c);
347 callTMres(L, ra);
348 break;
349 }
350 default: lua_assert(0); break; 343 default: lua_assert(0); break;
351 } 344 }
352 } 345 }
@@ -515,7 +508,13 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
515 continue; 508 continue;
516 } 509 }
517 case OP_POW: { 510 case OP_POW: {
518 base = Arith(L, ra, RKB(i), RKC(i), TM_POW, pc); /***/ 511 TValue *rb = RKB(i);
512 TValue *rc = RKC(i);
513 if (ttisnumber(rb) && ttisnumber(rc)) {
514 setnvalue(ra, lua_pow(nvalue(rb), nvalue(rc)));
515 }
516 else
517 base = Arith(L, ra, rb, rc, TM_POW, pc); /***/
519 continue; 518 continue;
520 } 519 }
521 case OP_UNM: { 520 case OP_UNM: {