From cb594e2deb23c810ea64f97f0513af5fc356bd38 Mon Sep 17 00:00:00 2001 From: gumi Date: Wed, 17 May 2017 14:01:20 -0400 Subject: add exponentiation operator --- src/map/script.c | 6 ++++++ src/map/script.h | 1 + 2 files changed, 7 insertions(+) (limited to 'src') diff --git a/src/map/script.c b/src/map/script.c index 75f747fb6..364509096 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -136,6 +136,7 @@ const char* script_op2name(int op) { RETURN_OP_NAME(C_ADD); RETURN_OP_NAME(C_SUB); RETURN_OP_NAME(C_MUL); + RETURN_OP_NAME(C_POW); RETURN_OP_NAME(C_DIV); RETURN_OP_NAME(C_MOD); RETURN_OP_NAME(C_NEG); @@ -1035,6 +1036,7 @@ const char* parse_variable(const char* p) || ( p[0] == '|' && p[1] == '=' && (type = C_OR, true) ) // |= || ( p[0] == '&' && p[1] == '=' && (type = C_AND, true) ) // &= || ( p[0] == '*' && p[1] == '=' && (type = C_MUL, true) ) // *= + || ( p[0] == '*' && p[1] == '*' && p[2] == '=' && (type = C_POW, true) ) // **= || ( p[0] == '/' && p[1] == '=' && (type = C_DIV, true) ) // /= || ( p[0] == '%' && p[1] == '=' && (type = C_MOD, true) ) // %= || ( p[0] == '+' && p[1] == '+' && (type = C_ADD_POST, true) ) // post ++ @@ -1058,6 +1060,7 @@ const char* parse_variable(const char* p) case C_L_SHIFT: // <<= case C_R_SHIFT: // >>= + case C_POW: // **= p = script->skip_space( &p[3] ); break; @@ -1424,6 +1427,7 @@ const char* script_parse_subexpr(const char* p,int limit) (op=C_OP3, opl=0, len=1,*p=='?') // ?: || (op=C_ADD, opl=9, len=1,*p=='+') // + || (op=C_SUB, opl=9, len=1,*p=='-') // - + || (op=C_POW, opl=11,len=2,*p=='*' && p[1]=='*') // ** || (op=C_MUL, opl=10,len=1,*p=='*') // * || (op=C_DIV, opl=10,len=1,*p=='/') // / || (op=C_MOD, opl=10,len=1,*p=='%') // % @@ -4146,6 +4150,7 @@ void op_2num(struct script_state* st, int op, int i1, int i2) case C_ADD: ret = i1 + i2; ret64 = (int64)i1 + i2; break; case C_SUB: ret = i1 - i2; ret64 = (int64)i1 - i2; break; case C_MUL: ret = i1 * i2; ret64 = (int64)i1 * i2; break; + case C_POW: ret = (int)pow((double)i1, (double)i2); ret64 = (int64)pow((double)i1, (double)i2); break; default: ShowError("script:op_2num: unexpected number operator %s i1=%d i2=%d\n", script->op2name(op), i1, i2); script->reportsrc(st); @@ -4683,6 +4688,7 @@ void run_script_main(struct script_state *st) { case C_ADD: case C_SUB: case C_MUL: + case C_POW: case C_DIV: case C_MOD: case C_EQ: diff --git a/src/map/script.h b/src/map/script.h index 8caec961a..fddcf4908 100644 --- a/src/map/script.h +++ b/src/map/script.h @@ -235,6 +235,7 @@ typedef enum c_op { C_SUB_PRE, // --a C_RE_EQ, // ~= C_RE_NE, // ~! + C_POW, // ** } c_op; /// Script queue options -- cgit v1.2.3-60-g2f50 From 919a95860a57a19903dc900900477062a8be193e Mon Sep 17 00:00:00 2001 From: gumi Date: Sat, 27 May 2017 13:03:11 -0400 Subject: flag the pow() buildin as deprecated --- doc/script_commands.txt | 8 ++++++++ src/map/script.c | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 2ceb8696b..70306ba96 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -8032,11 +8032,19 @@ instead if they want it so much. *pow(, ) + @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + @ /!\ This command is deprecated @ + @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + Returns the result of the calculation. Example: .@i = pow(2, 3); // .@i will be 8 +This command is deprecated and it should not be used in new scripts, as it is +likely to be removed at a later time. Please use the exponentiation operator, +ie: (2 ** 3) instead of pow(2, 3) + --------------------------------------- *log10() diff --git a/src/map/script.c b/src/map/script.c index 364509096..b2a707bb0 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -23565,7 +23565,7 @@ void script_parse_builtin(void) { // List of mathematics commands ---> BUILDIN_DEF(log10,"i"), BUILDIN_DEF(sqrt,"i"), //[zBuffer] - BUILDIN_DEF(pow,"ii"), //[zBuffer] + BUILDIN_DEF_DEPRECATED(pow,"ii"), //[zBuffer] BUILDIN_DEF(distance,"iiii"), //[zBuffer] // <--- List of mathematics commands BUILDIN_DEF(min, "i*"), -- cgit v1.2.3-60-g2f50