Received: from news.tht.net (news.hub.org [216.126.91.242]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f99NYsn19404 for ; Tue, 9 Oct 2001 19:34:54 -0400 (EDT) (envelope-from news@news.tht.net) Received: (from news@localhost) by news.tht.net (8.11.4/8.11.4) id f99NI3T51795 for pgsql-sql@postgresql.org; Tue, 9 Oct 2001 19:18:03 -0400 (EDT) (envelope-from news) From: Allan Engelhardt X-Newsgroups: comp.databases.postgresql.sql Subject: Re: ROUND function ?? Date: Wed, 10 Oct 2001 00:16:42 +0100 Organization: http://cybaea.com/ Message-ID: <3BC3855A.9909FE71@cybaea.com> References: <21186.1002602561@sss.pgh.pa.us> X-NNTP-Posting-Host: engelhardt.demon.co.uk:193.237.12.86 X-Complaints-To: abuse@demon.net X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.4.7 i686) X-Accept-Language: en MIME-Version: 1.0 To: Tom Lane , lattim@hotmail.com Content-Type: text/plain; charset=iso-8859-1 Lines: 27 To: pgsql-sql@postgresql.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by postgresql.org id f99NYtn19405 X-Archive-Number: 200110/138 X-Sequence-Number: 5093 Tom Lane wrote: > [...]Because the IEEE float math standard says so. Round-to-nearest-even > is considered good practice. I learn something new every day. :-) While it is true that IEEE 754 defaults to "round-to-nearest", which means rounding midway points to even, it is slightly confusing that this is implemented in the math library (libc) by the rint function (subject to compiler defaults and fesetround calls) while the round functions ((ll|l)?round(f|l)?) of the library does indeed 'round half-way cases away from zero to the nearest integer', which is also the mathematical behavior. Try % info libc Arithmetic Rounding % info libc Arithmetic 'Arithmetic Functions' 'Rounding Functions' on you local friendly U*ix clone and you shall find enlightenment... The SQL standard seems to leave it implementation dependent ('92, sec 4.4.1): An approximation obtained by rounding of a numerical value N for an T is a value V representable in T such that the absolute value of the difference between N and the nu- merical value of V is not greater than half the absolute value of the difference between two successive numerical values repre- sentable in T. If there are more than one such values V, then it is implementation-defined which one is taken. So PostgreSQL does "the right thing" (again!). Allan.