pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix roundoff problems in float8_timestamptz() and make_interval(
4+ messages / 1 participants
[nested] [flat]

* pgsql: Fix roundoff problems in float8_timestamptz() and make_interval(
@ 2017-02-08 23:05 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2017-02-08 23:05 UTC (permalink / raw)
  To: pgsql-committers

Fix roundoff problems in float8_timestamptz() and make_interval().

When converting a float value to integer microseconds, we should be careful
to round the value to the nearest integer, typically with rint(); simply
assigning to an int64 variable will truncate, causing apparently off-by-one
values in cases that should work.  Most places in the datetime code got
this right, but not these two.

float8_timestamptz() is new as of commit e511d878f (9.6).  Previous
versions effectively depended on interval_mul() to do roundoff correctly,
which it does, so this fixes an accuracy regression in 9.6.

The problem in make_interval() dates to its introduction in 9.4.  Aside
from being careful to round not truncate, let's incorporate the hours and
minutes inputs into the result with exact integer arithmetic, rather than
risk introducing roundoff error where there need not have been any.

float8_timestamptz() problem reported by Erik Nordström, though this is
not his proposed patch.  make_interval() problem found by me.

Discussion: https://postgr.es/m/CAHuQZDS76jTYk3LydPbKpNfw9KbACmD=49dC4BrzHcfPv6yA1A@mail.gmail.com

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/8f93bd8512466c9b6c4dbc1e5efd0f72b8e2be9a

Modified Files
--------------
src/backend/utils/adt/timestamp.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* pgsql: Fix roundoff problems in float8_timestamptz() and make_interval(
@ 2017-02-08 23:05 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2017-02-08 23:05 UTC (permalink / raw)
  To: pgsql-committers

Fix roundoff problems in float8_timestamptz() and make_interval().

When converting a float value to integer microseconds, we should be careful
to round the value to the nearest integer, typically with rint(); simply
assigning to an int64 variable will truncate, causing apparently off-by-one
values in cases that should work.  Most places in the datetime code got
this right, but not these two.

float8_timestamptz() is new as of commit e511d878f (9.6).  Previous
versions effectively depended on interval_mul() to do roundoff correctly,
which it does, so this fixes an accuracy regression in 9.6.

The problem in make_interval() dates to its introduction in 9.4.  Aside
from being careful to round not truncate, let's incorporate the hours and
minutes inputs into the result with exact integer arithmetic, rather than
risk introducing roundoff error where there need not have been any.

float8_timestamptz() problem reported by Erik Nordström, though this is
not his proposed patch.  make_interval() problem found by me.

Discussion: https://postgr.es/m/CAHuQZDS76jTYk3LydPbKpNfw9KbACmD=49dC4BrzHcfPv6yA1A@mail.gmail.com

Branch
------
REL9_6_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/404756fe89f62735f6075abb594b54be9c262b27

Modified Files
--------------
src/backend/utils/adt/timestamp.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* pgsql: Fix roundoff problems in float8_timestamptz() and make_interval(
@ 2017-02-08 23:05 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2017-02-08 23:05 UTC (permalink / raw)
  To: pgsql-committers

Fix roundoff problems in float8_timestamptz() and make_interval().

When converting a float value to integer microseconds, we should be careful
to round the value to the nearest integer, typically with rint(); simply
assigning to an int64 variable will truncate, causing apparently off-by-one
values in cases that should work.  Most places in the datetime code got
this right, but not these two.

float8_timestamptz() is new as of commit e511d878f (9.6).  Previous
versions effectively depended on interval_mul() to do roundoff correctly,
which it does, so this fixes an accuracy regression in 9.6.

The problem in make_interval() dates to its introduction in 9.4.  Aside
from being careful to round not truncate, let's incorporate the hours and
minutes inputs into the result with exact integer arithmetic, rather than
risk introducing roundoff error where there need not have been any.

float8_timestamptz() problem reported by Erik Nordström, though this is
not his proposed patch.  make_interval() problem found by me.

Discussion: https://postgr.es/m/CAHuQZDS76jTYk3LydPbKpNfw9KbACmD=49dC4BrzHcfPv6yA1A@mail.gmail.com

Branch
------
REL9_5_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/7786b984825ea720aed3a11ee465dc3d6cfc8d96

Modified Files
--------------
src/backend/utils/adt/timestamp.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* pgsql: Fix roundoff problems in float8_timestamptz() and make_interval(
@ 2017-02-08 23:05 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2017-02-08 23:05 UTC (permalink / raw)
  To: pgsql-committers

Fix roundoff problems in float8_timestamptz() and make_interval().

When converting a float value to integer microseconds, we should be careful
to round the value to the nearest integer, typically with rint(); simply
assigning to an int64 variable will truncate, causing apparently off-by-one
values in cases that should work.  Most places in the datetime code got
this right, but not these two.

float8_timestamptz() is new as of commit e511d878f (9.6).  Previous
versions effectively depended on interval_mul() to do roundoff correctly,
which it does, so this fixes an accuracy regression in 9.6.

The problem in make_interval() dates to its introduction in 9.4.  Aside
from being careful to round not truncate, let's incorporate the hours and
minutes inputs into the result with exact integer arithmetic, rather than
risk introducing roundoff error where there need not have been any.

float8_timestamptz() problem reported by Erik Nordström, though this is
not his proposed patch.  make_interval() problem found by me.

Discussion: https://postgr.es/m/CAHuQZDS76jTYk3LydPbKpNfw9KbACmD=49dC4BrzHcfPv6yA1A@mail.gmail.com

Branch
------
REL9_4_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/1888fad440036195c7e7a933fc17410fad8dcc3d

Modified Files
--------------
src/backend/utils/adt/timestamp.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2017-02-08 23:05 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-02-08 23:05 pgsql: Fix roundoff problems in float8_timestamptz() and make_interval( Tom Lane <tgl@sss.pgh.pa.us>
2017-02-08 23:05 pgsql: Fix roundoff problems in float8_timestamptz() and make_interval( Tom Lane <tgl@sss.pgh.pa.us>
2017-02-08 23:05 pgsql: Fix roundoff problems in float8_timestamptz() and make_interval( Tom Lane <tgl@sss.pgh.pa.us>
2017-02-08 23:05 pgsql: Fix roundoff problems in float8_timestamptz() and make_interval( Tom Lane <tgl@sss.pgh.pa.us>

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