Paul Vinkenoog
2016-03-28 14:14:01 UTC
Hi all (especially Helen),
I got suspicious when I saw the precedence of arithmetic operators listed like this:
1: *
2: /
3: +
4: -
So I tested it:
SQL> select 1 - 3 + 3 from rdb$database;
ADD
=====================
1
-- so + doesn't have higher precedence than - (otherwise result would be -5)
SQL> select 2.0 / 8.0 * 10.0 from rdb$database;
MULTIPLY
=====================
2.500
-- so * doesn't have higher precedence than / (otherwise result would be 0.025)
SQL> select 4 + 5 * 10 from rdb$database;
ADD
=====================
54
-- as expected, * has higher precedence than + (otherwise result would be 90)
SQL> select 5.0 + 5.0 / 5.0 from rdb$database;
ADD
=====================
6.00
-- as expected, / has higher precedence than + (otherwise result would be 2.00)
So the correct order is:
1: *, /
2: +, -
Operators of the same precedence are evaluated LTR.
Cheers,
Paul
I got suspicious when I saw the precedence of arithmetic operators listed like this:
1: *
2: /
3: +
4: -
So I tested it:
SQL> select 1 - 3 + 3 from rdb$database;
ADD
=====================
1
-- so + doesn't have higher precedence than - (otherwise result would be -5)
SQL> select 2.0 / 8.0 * 10.0 from rdb$database;
MULTIPLY
=====================
2.500
-- so * doesn't have higher precedence than / (otherwise result would be 0.025)
SQL> select 4 + 5 * 10 from rdb$database;
ADD
=====================
54
-- as expected, * has higher precedence than + (otherwise result would be 90)
SQL> select 5.0 + 5.0 / 5.0 from rdb$database;
ADD
=====================
6.00
-- as expected, / has higher precedence than + (otherwise result would be 2.00)
So the correct order is:
1: *, /
2: +, -
Operators of the same precedence are evaluated LTR.
Cheers,
Paul