Talking' about precedence...

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Talking' about precedence...

Paul Vinkenoog
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

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785471&iu=/4140
_______________________________________________
Firebird-docs mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/firebird-docs