Re: Improve performance of pg_strtointNN functions - Mailing list pgsql-hackers

From Dean Rasheed
Subject Re: Improve performance of pg_strtointNN functions
Date
Msg-id CAEZATCVEtwfhdm-K-etZYFB0=qsR0nT6qXta_W+GQx4RYph1dg@mail.gmail.com
Whole thread Raw
In response to Re: Improve performance of pg_strtointNN functions  (David Rowley <dgrowleyml@gmail.com>)
Responses Re: Improve performance of pg_strtointNN functions
List pgsql-hackers
On Sun, 4 Dec 2022 at 03:19, David Rowley <dgrowleyml@gmail.com> wrote:
>
> Pushed with some small adjustments.
>

Ah, I see that you changed the overflow test, and I realise that I
forgot to answer your question about why I wrote that as 1 - INT_MIN /
10 over on the other thread.

The reason is that we need to detect whether tmp * base will exceed
-INT_MIN, not INT_MAX, since we're accumulating the absolute value of
a signed integer. So the right test is

    tmp >= 1 - INT_MIN / base

or equivalently

    tmp > -(INT_MIN / base)

I used the first form, because it didn't require extra parentheses,
but that doesn't really matter. The point is that, in general, that's
not the same as

    tmp > INT_MAX / base

though it happens to be the same for base = 10, because INT_MIN and
INT_MAX aren't divisible by 10. It will break when base is a power of
2 though, so although it's not broken now, it's morally wrong, and it
risks breaking when Peter commits his patch.

Regards,
Dean



pgsql-hackers by date:

Previous
From: Corey Huinker
Date:
Subject: Re: Add SHELL_EXIT_CODE to psql
Next
From: "houzj.fnst@fujitsu.com"
Date:
Subject: RE: Perform streaming logical transactions by background workers and parallel apply