Re: [HACKERS] Patch: Avoid precision error in to_timestamp(). - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [HACKERS] Patch: Avoid precision error in to_timestamp().
Date
Msg-id 12772.1486587127@sss.pgh.pa.us
Whole thread Raw
In response to Re: [HACKERS] Patch: Avoid precision error in to_timestamp().  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [HACKERS] Patch: Avoid precision error in to_timestamp().  (Erik Nordström <erik.nordstrom@gmail.com>)
List pgsql-hackers
I wrote:
> I wonder if we could make things better just by using rint() rather than
> a naive cast-to-integer.  The cast will truncate not round, and I think
> that might be what's mostly biting you.  Does this help for you?

> #ifdef HAVE_INT64_TIMESTAMP
> -        result = seconds * USECS_PER_SEC;
> +        result = rint(seconds * USECS_PER_SEC);
> #else

I poked around looking for possible similar issues elsewhere, and found
that a substantial majority of the datetime-related code already uses
rint() when trying to go from float to int representations.  As far as
I can find, this function and make_interval() are the only ones that
fail to do so.  So I'm now thinking that this is a clear oversight,
and both those places need to be patched to use rint().
        regards, tom lane



pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: [HACKERS] Press Release Draft - 2016-02-09 Cumulative Update
Next
From: Robert Haas
Date:
Subject: Re: [HACKERS] WAL consistency check facility