Re: dividing money by money

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
Cc: "Andy Balholm" <andy(at)balholm(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: dividing money by money
Date: 2010-07-16 02:25:09
Message-ID: 4660.1279247109@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-www

"Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov> writes:
> Andy Balholm <andy(at)balholm(dot)com> wrote:
>> On Jun 21, 2010, at 11:47 AM, Kevin Grittner wrote:
>> I deleted the excess comments and moved some lines around. Here it
>> is with the changes.

> I ran pgindent to standardize the white space. (No changes of
> substance.) Patch attached.

> I'll mark it "Ready for Committer".

Applied with some editorial changes. The noncosmetic changes were:

* I didn't like this bit in cash_numeric():

result->n_sign_dscale = NUMERIC_SIGN(result) | fpoint;

Not only is that unwarranted chumminess with the implementation of
numeric, it's flat-out wrong. If the result isn't exactly the right
number of digits (say, it's 12.33999999 instead of the desired 12.34)
this just hides the extra digits, it doesn't make the result correct.
The right way is to use numeric_round(), which not only sets the dscale
where we want it but rounds off any inaccuracy that might have crept in
from the division.

* The cast functions were marked immutable, which is wrong because they
depend on the setting of lc_monetary. The right marking is "stable".

It struck me in connection with the latter that cash_in and cash_out
were also improperly marked as immutable --- they also depend on
lc_monetary and so can be no better than stable. I changed that
in this commit. I'm not sure if it's worth trying to back-patch;
in practice people probably aren't changing lc_monetary on the fly,
and the volatility of I/O functions is usually not that interesting
anyway.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2010-07-16 03:14:15 Re: suppress automatic recovery after back crash
Previous Message Robert Haas 2010-07-16 01:57:44 Re: SHOW TABLES

Browse pgsql-www by date

  From Date Subject
Next Message Peter Eisentraut 2010-07-16 05:17:43 Re: dividing money by money
Previous Message Thom Brown 2010-07-15 18:32:05 Re: [Fwd: RE: PostgreSQL community request]