Re: to_hex() for negative inputs - Mailing list pgsql-hackers

From Dean Rasheed
Subject Re: to_hex() for negative inputs
Date
Msg-id CAEZATCV7Gi08adZamHcL5Uy2MPqwbGGsz6E5he-_NeeXw4nhPg@mail.gmail.com
Whole thread Raw
In response to Re: to_hex() for negative inputs  (Aleksander Alekseev <aleksander@timescale.com>)
Responses Re: to_hex() for negative inputs
List pgsql-hackers
On Wed, 25 Jan 2023 at 10:57, Aleksander Alekseev
<aleksander@timescale.com> wrote:
>
> > Of course there is. This is easy to code in C using unsigned ints,
> > without resorting to abs() (yes, I'm aware that abs() is undefined for
> > INT_MIN).
>
> So in your opinion what is the expected result of to_hex(INT_MIN,
> with_sign => true)?
>

"-80000000" or "-0x80000000", depending on whether the prefix is
requested. The latter is legal input for an integer, which is the
point (to allow round-tripping):

SELECT int '-0x80000000';
    int4
-------------
 -2147483648
(1 row)

SELECT pg_typeof(-0x80000000);
 pg_typeof
-----------
 integer
(1 row)

Regards,
Dean



pgsql-hackers by date:

Previous
From: "Hayato Kuroda (Fujitsu)"
Date:
Subject: RE: [Proposal] Add foreign-server health checks infrastructure
Next
From: Amit Kapila
Date:
Subject: Re: Logical replication timeout problem