Re: Is PG built on any C compilers where int division floors? - Mailing list pgsql-hackers

From Chapman Flack
Subject Re: Is PG built on any C compilers where int division floors?
Date
Msg-id 5B33046F.3090701@anastigmatix.net
Whole thread Raw
In response to Re: Is PG built on any C compilers where int division floors?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Is PG built on any C compilers where int division floors?
List pgsql-hackers
On 06/24/18 23:38, Tom Lane wrote:
> Chapman Flack <chap@anastigmatix.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


pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: Speedup of relation deletes during recovery
Next
From: Tom Lane
Date:
Subject: Re: Is PG built on any C compilers where int division floors?