Re: [HACKERS] 123.45 - 123 = 0.45
От | jwieck@debis.com (Jan Wieck) |
---|---|
Тема | Re: [HACKERS] 123.45 - 123 = 0.45 |
Дата | |
Msg-id | m0zq0sB-000EBTC@orion.SAPserv.Hamburg.dsh.de обсуждение исходный текст |
Ответ на | Re: [HACKERS] 123.45 - 123 = 0.45 (Tom Lane <tgl@sss.pgh.pa.us>) |
Ответы |
Re: [HACKERS] 123.45 - 123 = 0.45
|
Список | pgsql-hackers |
Tom Lane wrote: > Sooner or later we ought to try to implement true fixed-point > arbitrary-precision numeric data types per the SQL spec. That'll be > a lot slower than hardware float math, but its roundoff properties will > be less surprising to novices. I think the string math done in bc(1) could be a good point to start from. In the old version (1.3 if I remember right) of the minix sources (yepp - still have them), there are the algorithm's to get sine, logarithm and the like in any precision as bc functions. Internally, only the four base operations, (think think) pow() and sqrt() are implemented in C. Anything else is done with them on the higher level. We need to define what the precision of a result should be, if it is not assigned to a column (where the precision can be the atttypmod). Is there any standard defined for? If not, what about this: Internal representation holds different precision for DISPLAY and CALC. On any operation, the DISPLAY precision is set to the higher of the two operands. On add/subtract, the CALC precision becomes the higher of the two. On multiply, the CALC precision is adjusted to hold the exact result up to a (variable settable?) maximum. On divide, the CALC precision is set to max and after it to the number of used digits. If the result get's assigned to an attribute, it is rounded to it's atttypmod and both precisions set to that. The types output function rounds it to the DISPLAY precision. The input function sets both precisions to the number of digits present after decimal point. Needless to say that there will be special functions to round explicitly and set the precisions. Jan -- #======================================================================# # It's easier to get forgiveness for being wrong than for being right. # # Let's break this rule - forgive me. # #======================================== jwieck@debis.com (Jan Wieck) #
В списке pgsql-hackers по дате отправления: