Re: dividing money by money

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: dividing money by money
Дата
Msg-id 4660.1279247109@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: dividing money by money  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
Ответы Re: dividing money by money  (Peter Eisentraut <peter_e@gmx.net>)
Re: dividing money by money  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
Re: dividing money by money  (Andy Balholm <andy@balholm.com>)
Список pgsql-hackers
"Kevin Grittner" <Kevin.Grittner@wicourts.gov> writes:
> Andy Balholm <andy@balholm.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


В списке pgsql-hackers по дате отправления:

Предыдущее
От: "Joshua D. Drake"
Дата:
Сообщение: Re: SHOW TABLES
Следующее
От: Fujii Masao
Дата:
Сообщение: Re: suppress automatic recovery after back crash