mirror of
https://github.com/lua/lua
synced 2024-11-22 21:01:26 +03:00
a^b calls `pow´ (from math.h) directly
This commit is contained in:
parent
071b2ae0e1
commit
f61d435a7d
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lmathlib.c,v 1.60 2004/04/30 20:13:38 roberto Exp roberto $
|
||||
** $Id: lmathlib.c,v 1.61 2004/05/10 18:11:32 roberto Exp roberto $
|
||||
** Standard mathematical library
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -225,8 +225,6 @@ LUALIB_API int luaopen_math (lua_State *L) {
|
||||
luaL_openlib(L, LUA_MATHLIBNAME, mathlib, 0);
|
||||
lua_pushnumber(L, PI);
|
||||
lua_setfield(L, -2, "pi");
|
||||
lua_pushcfunction(L, math_pow);
|
||||
lua_setglobal(L, "__pow");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: luaconf.h,v 1.22 2004/12/27 15:58:15 roberto Exp roberto $
|
||||
** $Id: luaconf.h,v 1.23 2005/01/04 12:46:04 roberto Exp roberto $
|
||||
** Configuration file for Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -257,6 +257,11 @@ __inline int l_lrint (double flt)
|
||||
#define LUA_UACNUMBER double
|
||||
|
||||
|
||||
/* primitive `^' operator for numbers */
|
||||
#include <math.h>
|
||||
#define lua_pow(a,b) pow(a,b)
|
||||
|
||||
|
||||
|
||||
/* type to ensure maximum alignment */
|
||||
#define LUSER_ALIGNMENT_T union { double u; void *s; long l; }
|
||||
|
19
lvm.c
19
lvm.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lvm.c,v 2.19 2005/01/04 15:55:12 roberto Exp roberto $
|
||||
** $Id: lvm.c,v 2.20 2005/01/05 18:20:51 roberto Exp roberto $
|
||||
** Lua virtual machine
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -339,14 +339,7 @@ static StkId Arith (lua_State *L, StkId ra, const TValue *rb,
|
||||
case TM_SUB: setnvalue(ra, nvalue(b) - nvalue(c)); break;
|
||||
case TM_MUL: setnvalue(ra, nvalue(b) * nvalue(c)); break;
|
||||
case TM_DIV: setnvalue(ra, nvalue(b) / nvalue(c)); break;
|
||||
case TM_POW: {
|
||||
const TValue *f = luaH_getstr(hvalue(gt(L)), G(L)->tmname[TM_POW]);
|
||||
if (!ttisfunction(f))
|
||||
luaG_runerror(L, "`__pow' (`^' operator) is not a function");
|
||||
prepTMcall(L, f, b, c);
|
||||
callTMres(L, ra);
|
||||
break;
|
||||
}
|
||||
case TM_POW: setnvalue(ra, lua_pow(nvalue(b), nvalue(c))); break;
|
||||
default: lua_assert(0); break;
|
||||
}
|
||||
}
|
||||
@ -515,7 +508,13 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
|
||||
continue;
|
||||
}
|
||||
case OP_POW: {
|
||||
base = Arith(L, ra, RKB(i), RKC(i), TM_POW, pc); /***/
|
||||
TValue *rb = RKB(i);
|
||||
TValue *rc = RKC(i);
|
||||
if (ttisnumber(rb) && ttisnumber(rc)) {
|
||||
setnvalue(ra, lua_pow(nvalue(rb), nvalue(rc)));
|
||||
}
|
||||
else
|
||||
base = Arith(L, ra, rb, rc, TM_POW, pc); /***/
|
||||
continue;
|
||||
}
|
||||
case OP_UNM: {
|
||||
|
Loading…
Reference in New Issue
Block a user