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:
+12
-7
@@ -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
|
||||
|
||||
@@ -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 "
|
||||
|
||||
Reference in New Issue
Block a user