From 5af449e98660a42d59347ec4119dec84ffb99f7e Mon Sep 17 00:00:00 2001 From: tgl Date: Mon, 6 Jul 2009 20:29:23 +0000 Subject: [PATCH] Use floor() not rint() when reducing precision of fractional seconds in timestamp_trunc, timestamptz_trunc, and interval_trunc(). This change only affects the float-datetime case; the integer-datetime case already behaved like truncation instead of rounding. Per gripe from Mario Splivalo. This is a pre-existing issue but I'm choosing not to backpatch, because it's such a corner case and there have not been prior complaints. The issue is largely moot anyway given the trend towards integer datetimes. --- src/backend/utils/adt/timestamp.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index a0bf47c264..e00f729e6f 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -3338,13 +3338,13 @@ timestamp_trunc(PG_FUNCTION_ARGS) #ifdef HAVE_INT64_TIMESTAMP fsec = (fsec / 1000) * 1000; #else - fsec = rint(fsec * 1000) / 1000; + fsec = floor(fsec * 1000) / 1000; #endif break; case DTK_MICROSEC: #ifndef HAVE_INT64_TIMESTAMP - fsec = rint(fsec * 1000000) / 1000000; + fsec = floor(fsec * 1000000) / 1000000; #endif break; @@ -3494,12 +3494,12 @@ timestamptz_trunc(PG_FUNCTION_ARGS) #ifdef HAVE_INT64_TIMESTAMP fsec = (fsec / 1000) * 1000; #else - fsec = rint(fsec * 1000) / 1000; + fsec = floor(fsec * 1000) / 1000; #endif break; case DTK_MICROSEC: #ifndef HAVE_INT64_TIMESTAMP - fsec = rint(fsec * 1000000) / 1000000; + fsec = floor(fsec * 1000000) / 1000000; #endif break; @@ -3591,12 +3591,12 @@ interval_trunc(PG_FUNCTION_ARGS) #ifdef HAVE_INT64_TIMESTAMP fsec = (fsec / 1000) * 1000; #else - fsec = rint(fsec * 1000) / 1000; + fsec = floor(fsec * 1000) / 1000; #endif break; case DTK_MICROSEC: #ifndef HAVE_INT64_TIMESTAMP - fsec = rint(fsec * 1000000) / 1000000; + fsec = floor(fsec * 1000000) / 1000000; #endif break; -- 2.11.4.GIT