Re: avoid negating LONG_MIN in cash_out() - Mailing list pgsql-hackers

From Tom Lane
Subject Re: avoid negating LONG_MIN in cash_out()
Date
Msg-id 23291.1660239613@sss.pgh.pa.us
Whole thread Raw
In response to avoid negating LONG_MIN in cash_out()  (Zhihong Yu <zyu@yugabyte.com>)
Responses Re: avoid negating LONG_MIN in cash_out()
List pgsql-hackers
Zhihong Yu <zyu@yugabyte.com> writes:
> In cash_out(), we have the following code:
>     if (value < 0)
>     {
>         /* make the amount positive for digit-reconstruction loop */
>         value = -value;

> The negation cannot be represented in type long when the value is LONG_MIN.

Possibly not good, but it seems like the subsequent loop works anyway:

regression=# select '-92233720368547758.08'::money;
            money            
-----------------------------
 -$92,233,720,368,547,758.08
(1 row)

Note that this exact test case appears in money.sql, so we know that
it works everywhere, not only my machine.

> It seems we can error out when LONG_MIN is detected instead of continuing
> with computation.

How could you think that that's an acceptable solution?  Once the
value is stored, we'd better be able to print it.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Zhihong Yu
Date:
Subject: avoid negating LONG_MIN in cash_out()
Next
From: Zhihong Yu
Date:
Subject: Re: avoid negating LONG_MIN in cash_out()