Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YcxDa-0006gn-0r for pgsql-bugs@arkaria.postgresql.org; Tue, 31 Mar 2015 14:32:38 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YcxDY-0006De-JM for pgsql-bugs@arkaria.postgresql.org; Tue, 31 Mar 2015 14:32:36 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YbYRc-0007m5-3U for pgsql-bugs@postgresql.org; Fri, 27 Mar 2015 17:53:20 +0000 Received: from formauri.es ([78.47.205.180]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YbYRY-000736-0H for pgsql-bugs@postgresql.org; Fri, 27 Mar 2015 17:53:17 +0000 Received: from [0.0.0.0] (formauri.es [78.47.205.180]) by formauri.es (Postfix) with ESMTPS id 9311D813C6; Fri, 27 Mar 2015 18:53:12 +0100 (CET) Message-ID: <55159907.1060809@personal.formauri.es> Date: Fri, 27 Mar 2015 18:53:11 +0100 From: Pedro Gimeno User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Icedove/24.7.0 MIME-Version: 1.0 To: Michael Paquier CC: Andrew Gierth , Tom Lane , Pedro Gimeno , rschaaf@commoninf.com, pgsql-bugs@postgresql.org Subject: Re: Re: BUG #12885: The result of casting a double to an integer depends on the database version References: <20150320194337.2573.72944@wrigleys.postgresql.org> <26862.1427166720@sss.pgh.pa.us> <13096.1427204266@sss.pgh.pa.us> <55121967.90308@personal.formauri.es> <55129971.2070208@personal.formauri.es> <3736.1427294258@sss.pgh.pa.us> <5512E0AF.9050103@personal.formauri.es> <5512F2C0.9080007@personal.formauri.es> <8192.1427306273@sss.pgh.pa.us> <5512FE17.6020702@personal.formauri.es> <22366.1427313454@sss.pgh.pa.us> <87lhik4o45.fsf@news-spur.riddles.org.uk> <87h9t84ig5.fsf@news-spur.riddles.org.uk> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Michael Paquier wrote, On 2015-03-27 13:32: > Attached is a patch that adds nearest-to-even rounding for numeric > when dscale = 0. This gives the following results with the previous > query: That produces some quite surprising results: =# select '2.5'::numeric(9,0)::numeric(9,1), '2.25'::numeric(9,1)::numeric(9,2), '2.225'::numeric(9,2)::numeric(9,3), '2.2225'::numeric(9,3)::numeric(9,4), '2.22225'::numeric(9,4)::numeric(9,5); numeric | numeric | numeric | numeric | numeric ---------+---------+---------+---------+--------- 2.0 | 2.30 | 2.230 | 2.2230 | 2.22220 (1 row) That rounding is inconsistent: since DEC_DIGITS is 4 by default, numbers with a number of digits which is a multiple of 4 + 1 will be rounded to nearest or even, and numbers with a different number of digits will be rounded up on a tie. And I have not tested, but apparently when DEC_DIGITS == 1 (array elements are single digits rather than packing several) it always rounds down on a tie. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs