Re: About numeric division again - Mailing list pgsql-hackers

From Gregory Stark
Subject Re: About numeric division again
Date
Msg-id 8763uyh4l0.fsf@oxford.xeocode.com
Whole thread Raw
In response to About numeric division again  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: About numeric division again  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
"Tom Lane" <tgl@sss.pgh.pa.us> writes:

> One of the items on the commit-fest list is my patch from last year
> to rewrite the numeric division operator using "schoolbook division":
> http://archives.postgresql.org/pgsql-patches/2007-06/msg00173.php
>
> The code that's currently in there sometimes has to propagate rounding
> to the left, meaning that you can never be certain whether all of the
> digits you have so far are good, and that means that it can sometimes
> generate an incorrect truncated output.  This leads to the bugs cited
> in the above message.

The case I looked into could be traced specifically to the fact that it
calculates an intermediate value which is the reciprocal of the divisor and
multiplies by that. The case where the digits were inaccurate was a case where
there reciprocal wasn't representable and multiplying by the reciprocal didn't
produce the same value as dividing.

I assume you're right about there being bigger problems but I don't follow how
the division is actually being done in enough detail to judge that for my
self.

--  Gregory Stark EnterpriseDB          http://www.enterprisedb.com Ask me about EnterpriseDB's 24x7 Postgres support!


pgsql-hackers by date:

Previous
From: "Sibte Abbas"
Date:
Subject: Re: [PATCHES] psql slash# command
Next
From: Sam Mason
Date:
Subject: Re: [GENERAL] SHA1 on postgres 8.3