Re: Keep compiler silence (clang 10, implicit conversion from 'long'to 'double' ) - Mailing list pgsql-hackers

From Yuya Watari
Subject Re: Keep compiler silence (clang 10, implicit conversion from 'long'to 'double' )
Date
Msg-id CAJ2pMkZ0HPEskk2UgXe4VVZuG2UpApEywZut8UwUM35O=2=TqQ@mail.gmail.com
Whole thread Raw
In response to Re: Keep compiler silence (clang 10, implicit conversion from'long' to 'double' )  (Kyotaro Horiguchi <horikyota.ntt@gmail.com>)
Responses Re: Keep compiler silence (clang 10, implicit conversion from 'long' to 'double' )
List pgsql-hackers
Hello Tom and Horiguchi-san,

On Tue, Nov 5, 2019 at 1:59 PM Kyotaro Horiguchi
<horikyota.ntt@gmail.com> wrote:
> At Mon, 04 Nov 2019 12:53:48 -0500, Tom Lane <tgl@sss.pgh.pa.us> wrote in
> > I do concur with creating a macro that encapsulates a correct version
> > of this test, maybe like
> >
> > #define DOUBLE_FITS_IN_INT64(num) \
> >       ((num) >= (double) PG_INT64_MIN && \
> >        (num) < -((double) PG_INT64_MIN))

Thank you for your comments. The proposed macro "DOUBLE_FITS_IN_INT64"
is a good and simple way to check the overflow. According to that, I
revised the patch, which includes regression tests.

In the patch, I additionally modified other occurrences as follows.

=========

+#define FLOAT8_FITS_IN_INT32(num) \
+   ((num) >= (float8) PG_INT32_MIN && (num) < -((float8) PG_INT32_MIN))

=========

-   if (unlikely(num < (float8) PG_INT32_MIN ||
-                num >= -((float8) PG_INT32_MIN) ||
-                isnan(num)))
+   /* Range check */
+   if (unlikely(!FLOAT8_FITS_IN_INT32(num)))

=========

The added macro FLOAT8_FITS_IN_INT32() does not check NaN explicitly,
but it sufficiently handles the case.

Best regards,
Yuya Watari
NTT Software Innovation Center
watari.yuya@gmail.com

Attachment

pgsql-hackers by date:

Previous
From: Gilles Darold
Date:
Subject: Re: [PATCH][DOC] Fix for PREPARE TRANSACTION doc and postgres_fdwmessage.
Next
From: Tatsuro Yamada
Date:
Subject: Re: progress report for ANALYZE