]> granicus.if.org Git - postgresql/commit
Fix roundoff problems in float8_timestamptz() and make_interval().
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 8 Feb 2017 23:04:59 +0000 (18:04 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 8 Feb 2017 23:04:59 +0000 (18:04 -0500)
commit404756fe89f62735f6075abb594b54be9c262b27
treeaff7317e5ac9465d575e805b8aa46377bc46ead2
parentae8a602c32f839af8e467230fedb8e0c48540666
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
src/backend/utils/adt/timestamp.c