fix integer datetime division rounding error - Mailing list pgsql-patches

From Andrew Dunstan
Subject fix integer datetime division rounding error
Date
Msg-id 42E2DF6E.3000208@dunslane.net
Whole thread Raw
Responses Re: fix integer datetime division rounding error
List pgsql-patches
The attached patch seems to fix the rounding error that is causing
regression failures on machines with integer datetimes. (Source of error
discovered by Andrew@Supernews).ISTM this code needs to be given some
careful analysis - I know it makes my head spin reading it.

cheers

andrew
Index: src/backend/utils/adt/timestamp.c
===================================================================
RCS file: /home/cvsmirror/pgsql/src/backend/utils/adt/timestamp.c,v
retrieving revision 1.145
diff -c -r1.145 timestamp.c
*** src/backend/utils/adt/timestamp.c   23 Jul 2005 14:53:21 -0000      1.145
--- src/backend/utils/adt/timestamp.c   24 Jul 2005 00:04:08 -0000
***************
*** 2319,2325 ****
        day_remainder += (month_remainder * DAYS_PER_MONTH) - (int)(month_remainder * DAYS_PER_MONTH);

  #ifdef HAVE_INT64_TIMESTAMP
!       result->time += day_remainder * USECS_PER_DAY;
  #else
        result->time += day_remainder * SECS_PER_DAY;
        result->time = JROUND(result->time);
--- 2319,2325 ----
        day_remainder += (month_remainder * DAYS_PER_MONTH) - (int)(month_remainder * DAYS_PER_MONTH);

  #ifdef HAVE_INT64_TIMESTAMP
!       result->time += rint(day_remainder * USECS_PER_DAY);
  #else
        result->time += day_remainder * SECS_PER_DAY;
        result->time = JROUND(result->time);

pgsql-patches by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: [HACKERS] Patch to fix plpython on OS X
Next
From: Michael Fuhr
Date:
Subject: Re: [HACKERS] Patch to fix plpython on OS X