1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-06 01:33:12 +02:00

core: add power operator "**" in calc expressions (issue #997)

This commit is contained in:
Sébastien Helleu
2019-09-24 21:03:56 +02:00
parent 7d795c4d53
commit 3a356f109f
26 changed files with 166 additions and 136 deletions
+12 -7
View File
@@ -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
+1 -1
View File
@@ -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 "