Robert Haas <robertmh...@gmail.com> writes:
> It occurs to me belatedly that there might be a better way to do this.
>  Instead of flipping value from negative to positive, with a special
> case for the smallest possible integer, we could do it the other
> round.  And actually, I think we can rid of neg, too.

The trouble with that approach is that you have to depend on the
direction of rounding for negative quotients.  Which was unspecified
before C99, and it's precisely pre-C99 compilers that are posing a
hazard to the current coding.

FWIW, I find the code still pretty darn unsightly.  I think this change
is just wrong:

     * Avoid problems with the most negative integer not being representable
     * as a positive integer.
     */
-   if (value == INT32_MIN)
+   if (value == INT_MIN)
    {
        memcpy(a, "-2147483648", 12);

and even with INT32_MIN it was pretty silly, because there is exactly 0
hope of the code behaving sanely for some other value of the symbolic
constant.  I think it'd be much better to abandon the macros altogether
and write

    if (value == (-2147483647-1))
    {
        memcpy(a, "-2147483648", 12);

Likewise for the int64 case, which BTW is no safer for pre-C99 compilers
than it was yesterday: LL is not the portable way to write int64
constants.

                        regards, tom lane

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to