Precedence of % - Mailing list pgsql-hackers

From Bruce Momjian
Subject Precedence of %
Date
Msg-id 200506040356.j543uki09397@candle.pha.pa.us
Whole thread Raw
Responses Re: Precedence of %
List pgsql-hackers
Does anyone understand why the precedence of % is strange:test=> select -25 % -10; ?column?----------      -35(1
row)test=>select -25 % (-10); ?column?----------       -5(1 row)
 

Is it treating the first as -25 - 10?  Why?  Why are parens necessary to
get the right answer?  I see this in gram.y:
%left       '+' '-'%left       '*' '/' '%'

Look at this:
test=> select -25 + -10; ?column?----------      -35(1 row)test=> select -25 * -10; ?column?----------      250(1
row)test=>select -25 / -10; ?column?----------        2(1 row)test=> select -25 % -10; ?column?----------      -35(1
row)

Only the '%' case looks wrong.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073
 


pgsql-hackers by date:

Previous
From: "John Hansen"
Date:
Subject: Re: executing OS programs from pg
Next
From: Neil Conway
Date:
Subject: Re: need help