fix integer datetime division rounding error

Started by Andrew Dunstanabout 21 years ago3 messagespatches
Jump to latest
#1Andrew Dunstan
andrew@dunslane.net

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

Attachments:

ts.patchtext/x-patch; name=ts.patchDownload+2-2
#2Bruce Momjian
bruce@momjian.us
In reply to: Andrew Dunstan (#1)
Re: fix integer datetime division rounding error

Andrew Dunstan wrote:

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.

Ah, brilliant! I knew I was missing something fundamental, and the use
of rint() was it. Strangely enough, the 8.0 code uses rint() in that
function, but for floating point intervals, and the code was buggy,
generating negative time values for division.

Patch attached and applied. I also improved the interval multiplication
code.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Attachments:

/bjm/difftext/plainDownload+48-53
#3Rocco Altier
RoccoA@Routescape.com
In reply to: Bruce Momjian (#2)
Re: fix integer datetime division rounding error

This fixes the problem for me.

Thanks,
-rocco

Show quoted text

-----Original Message-----
From: Bruce Momjian [mailto:pgman@candle.pha.pa.us]
Sent: Sunday, July 24, 2005 12:37 AM
To: Andrew Dunstan
Cc: Patches (PostgreSQL); Rocco Altier
Subject: Re: [PATCHES] fix integer datetime division rounding error

Andrew Dunstan wrote:

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.

Ah, brilliant! I knew I was missing something fundamental,
and the use
of rint() was it. Strangely enough, the 8.0 code uses rint() in that
function, but for floating point intervals, and the code was buggy,
generating negative time values for division.

Patch attached and applied. I also improved the interval
multiplication
code.

-- 
Bruce Momjian                        |  http://candle.pha.pa.us
pgman@candle.pha.pa.us               |  (610) 359-1001
+  If your life is a hard drive,     |  13 Roberts Road
+  Christ can be your backup.        |  Newtown Square, 
Pennsylvania 19073