Is PG built on any C compilers where int division floors?
Is PG built on any C compilers where int division floors?
От:
Chapman Flack <chap@anastigmatix.net>
Дата:
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? -Chap
Re: Is PG built on any C compilers where int division floors?
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Chapman Flack 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 assumptions about this would seem to be contrary to policy. regards, tom lane [1] gaur/pademelon might, but it's turned off and 300 miles away, so I can't check right now.
Re: Is PG built on any C compilers where int division floors?
От:
Chapman Flack <chap@anastigmatix.net>
Дата:
On 06/24/18 23:38, Tom Lane wrote: > Chapman Flack 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