From: | Chapman Flack <chap(at)anastigmatix(dot)net> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Is PG built on any C compilers where int division floors? |
Date: | 2018-06-27 03:28:47 |
Message-ID: | 5B33046F.3090701@anastigmatix.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 06/24/18 23:38, Tom Lane wrote:
> Chapman Flack <chap(at)anastigmatix(dot)net> writes:
>> C99 finally pinned down what / does on signed ints, truncating toward zero.
>> Before that, it could truncate toward zero, or floor toward -inf.
>> Is PostgreSQL built on any compilers/platforms that have the floor
>> behavior?
>
> I'm not sure if we still have any buildfarm animals that act that way[1],
> but the project policy is that we target C90 not C99. So wiring in any
On a related note, does PG itself specify the behavior of its own signed int
/ and % (and div() and mod() functions)? Should it? I've been looking at
https://www.postgresql.org/docs/11/static/functions-math.html
and that doesn't specify. (There's a column of examples for the operators,
where the operands are positive. Changing nothing else, it might be more
revealing to toss in a negative-operand example: do we have div(-9,4) = -2
with mod(-9,4) = -1, or div(-9,4) = -3 with mod(-9,4) = +3 ?)
I don't see it specified in the standard either (2006 draft) - doesn't even
pay the issue enough notice to say it's implementation-defined.
Do PG's operators just do what the underlying C compiler generates?
Also, the PG manual doesn't seem to say whether >> is arithmetic or logical.
(I just tried it here and it was arithmetic; I assume it's consistent, but
would it be worth saying?)
-Chap
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2018-06-27 03:33:22 | Re: Is PG built on any C compilers where int division floors? |
Previous Message | Andres Freund | 2018-06-27 01:46:55 | Re: Speedup of relation deletes during recovery |