BUG #16357: Incorrect rounding for negative arguments in to_timestamp() - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #16357: Incorrect rounding for negative arguments in to_timestamp()
Date
Msg-id 16357-4ed50b3eb9a1a065@postgresql.org
Whole thread Raw
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      16357
Logged by:          Ivan Beloborodov
Email address:      ivbel@ispras.ru
PostgreSQL version: 9.6.17
Operating system:   Linux 5.0.0, Ubuntu 18.04.1
Description:

to_timestamp() returns incorrect results for some negative arguments: 

set extra_float_digits to 1;
SET
select extract(epoch from timestamp '1920-10-24 12:11:13.975227');
     date_part      
--------------------
 -1552218526.024773
(1 row)
select to_timestamp(-1552218526.024773) at time zone 'UTC';
          timezone          
----------------------------
 1920-10-24 12:11:13.975228
(1 row)

Whereas for positive arguments of the same magnitude everything's ok:

select extract(epoch from timestamp '2019-03-10 11:48:46.024773');
     date_part     
-------------------
 1552218526.024773
(1 row)
select to_timestamp(1552218526.024773) at time zone 'UTC';
          timezone          
----------------------------
 2019-03-10 11:48:46.024773
(1 row)

The problem is not with extra_float_digits:

set extra_float_digits to 0;
SET
select to_timestamp(-1552218526.024773) at time zone 'UTC' = timestamp
'1920-10-24 12:11:13.975227';
 ?column? 
----------
 f
(1 row)

And, as far as I understand, not with insufficient precision of float8, here
is an example with the same behaviour with 15 significant digits:

select extract(epoch from timestamp '1853-08-15 10:04:15.35064');
     date_part     
-------------------
 -3672568544.64936
(1 row)
select to_timestamp(-3672568544.64936) at time zone 'UTC';
          timezone          
----------------------------
 1853-08-15 10:04:15.350639
(1 row)
select extract(epoch from timestamp '2086-05-18 13:55:44.64936');
    date_part     
------------------
 3672568544.64936
(1 row)
select to_timestamp(3672568544.64936) at time zone 'UTC';
         timezone          
---------------------------
 2086-05-18 13:55:44.64936
(1 row)

Tested this behaviour on PostgreSQL 9.6.17, Linux 5.0.0, Ubuntu 18.04.1 and
PostgreSQL 10.1, Linux 4.4.0, Ubuntu 14.04.1


pgsql-bugs by date:

Previous
From: Sandeep Thakkar
Date:
Subject: Re: BUG #16341: Installation with EnterpriseDB Community installer inNT AUTHORITY\SYSTEM context not possible
Next
From: wenjing
Date:
Subject: Re: [bug] Wrong bool value parameter