pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: ivbel@ispras.ru
Subject: BUG #16357: Incorrect rounding for negative arguments in to_timestamp()
Date: Sat, 11 Apr 2020 06:01:49 +0000
Message-ID: <16357-4ed50b3eb9a1a065@postgresql.org> (raw)

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



Message-ID: <16357-4ed50b3eb9a1a065@postgresql.org>
Permalink:  ../16357-4ed50b3eb9a1a065@postgresql.org/
Also on:    postgresql.org/message-id/16357-4ed50b3eb9a1a065@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, ivbel@ispras.ru
  Subject: Re: BUG #16357: Incorrect rounding for negative arguments in to_timestamp()
  In-Reply-To: <16357-4ed50b3eb9a1a065@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox