diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2019-09-24 21:03:56 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2019-09-24 21:03:56 +0200 |
commit | 3a356f109f0804a0731da3546edaf20cca86e694 (patch) | |
tree | 86463259aece006680f0a68e47330dee995da79e /src | |
parent | 7d795c4d5301f265c077cad02f6803212a3db81b (diff) | |
download | weechat-3a356f109f0804a0731da3546edaf20cca86e694.zip |
core: add power operator "**" in calc expressions (issue #997)
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-calc.c | 19 | ||||
-rw-r--r-- | src/core/wee-command.c | 2 |
2 files changed, 13 insertions, 8 deletions
diff --git a/src/core/wee-calc.c b/src/core/wee-calc.c index b31b4e5f9..425f6e423 100644 --- a/src/core/wee-calc.c +++ b/src/core/wee-calc.c @@ -73,7 +73,8 @@ calc_operator_precedence (char *operator) if ((strcmp (operator, "*") == 0) || (strcmp (operator, "/") == 0) || (strcmp (operator, "//") == 0) - || (strcmp (operator, "%") == 0)) + || (strcmp (operator, "%") == 0) + || (strcmp (operator, "**") == 0)) { return 2; } @@ -135,6 +136,9 @@ calc_operation (char *operator, double value1, double value2) if (strcmp (operator, "%") == 0) return (value2 != 0) ? fmod (value1, value2) : 0; + if (strcmp (operator, "**") == 0) + return pow (value1, value2); + return 0; } @@ -217,12 +221,13 @@ calc_format_result (double value, char *result, int max_size) * Calculates an expression, which can contain: * - integer and decimal numbers (ie 2 or 2.5) * - operators: - * +: addition - * -: subtraction - * *: multiplication - * /: division - * \: division giving an integer as result - * %: remainder of division + * +: addition + * -: subtraction + * *: multiplication + * /: division + * \: division giving an integer as result + * %: remainder of division + * **: power * - parentheses: ( ) * * The value returned is a string representation of the result, which can be diff --git a/src/core/wee-command.c b/src/core/wee-command.c index d8a940fa1..c794bf8c6 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -7366,7 +7366,7 @@ command_init () " 12. a ternary operator (format: " "\"if:condition?value_if_true:value_if_false\")\n" " 13. result of an expression with parentheses and operators " - "+ - * / // % (format: \"calc:xxx\")\n" + "+ - * / // % ** (format: \"calc:xxx\")\n" " 14. an option (format: \"file.section.option\")\n" " 15. a local variable in buffer\n" " 16. a hdata name/variable (the value is automatically converted " |