summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2017-10-17 20:43:40 +0200
committerSébastien Helleu <flashcode@flashtux.org>2017-10-17 20:43:40 +0200
commit1d56e17b2f0e8f8ce71651729aeb2cab3340a0ad (patch)
tree62d0d41a52b19c35776b91877adbdf0993e72659 /src
parent5233160d823a10e1a9b2c852a1f68844fa4711d3 (diff)
downloadweechat-1d56e17b2f0e8f8ce71651729aeb2cab3340a0ad.zip
core: allow floating point and hexadecimal numbers in comparison of evaluated values
Diffstat (limited to 'src')
-rw-r--r--src/core/wee-command.c11
-rw-r--r--src/core/wee-eval.c8
2 files changed, 12 insertions, 7 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c
index e4983cad7..7ddb0f3b3 100644
--- a/src/core/wee-command.c
+++ b/src/core/wee-command.c
@@ -7251,10 +7251,13 @@ command_init ()
"\n"
"An expression is considered as \"true\" if it is not NULL, not "
"empty, and different from \"0\".\n"
- "The comparison is made using integers if the two expressions are "
- "valid integers.\n"
- "To force a string comparison, add double quotes around each "
- "expression, for example:\n"
+ "The comparison is made using floating point numbers if the two "
+ "expressions are valid numbers, with one of the following formats:\n"
+ " - integer (examples: 5, -7)\n"
+ " - floating point number (examples: 5.2, -7.5, 2.83e-2)\n"
+ " - hexadecimal number (examples: 0xA3, -0xA3)\n"
+ "To force a string comparison, you can add double quotes around "
+ "each expression, for example:\n"
" 50 > 100 ==> 0\n"
" \"50\" > \"100\" ==> 1\n"
"\n"
diff --git a/src/core/wee-eval.c b/src/core/wee-eval.c
index e65fac78a..3c1952782 100644
--- a/src/core/wee-eval.c
+++ b/src/core/wee-eval.c
@@ -769,7 +769,7 @@ eval_compare (const char *expr1, int comparison, const char *expr2)
{
int rc, string_compare, length1, length2;
regex_t regex;
- long value1, value2;
+ double value1, value2;
char *error;
rc = 0;
@@ -816,12 +816,14 @@ eval_compare (const char *expr1, int comparison, const char *expr2)
if (!string_compare)
{
- value1 = strtol (expr1, &error, 10);
+ value1 = strtod (expr1, &error);
if (!error || error[0])
+ {
string_compare = 1;
+ }
else
{
- value2 = strtol (expr2, &error, 10);
+ value2 = strtod (expr2, &error);
if (!error || error[0])
string_compare = 1;
}