Re: dividing money by money

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

Andy Balholm <andy(at)balholm(dot)com> writes:
> On Jul 15, 2010, at 7:25 PM, Tom Lane wrote:
>> * 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.

> Sorry about that. Is there documentation anywhere for backend
> functions and types?

Nothing at that level of detail, unfortunately, beyond the code itself.
If you'd read the comments near the head of numeric.c, maybe the mistake
would've been apparent to you, or maybe not.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Thom Brown 2010-07-16 14:42:55 psql auto-completion for multiple where clauses
Previous Message Tom Lane 2010-07-16 14:31:50 Re: dividing money by money

Browse pgsql-www by date

  From Date Subject
Next Message Tom Lane 2010-07-16 14:43:16 Re: dividing money by money
Previous Message Tom Lane 2010-07-16 14:31:50 Re: dividing money by money