pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Pedro Gimeno <pgsql-004@personal.formauri.es>
To: Michael Paquier <michael.paquier@gmail.com>
Cc: Andrew Gierth <andrew@tao11.riddles.org.uk>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Pedro Gimeno <pgsql-004@personal.formauri.es>
Cc: rschaaf@commoninf.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: Re: BUG #12885: The result of casting a double to an integer depends on the database version
Date: Fri, 27 Mar 2015 18:53:11 +0100
Message-ID: <55159907.1060809@personal.formauri.es> (raw)
In-Reply-To: <CAB7nPqRq94VT5WiYyCjSS+E_=mwWL49W-MXv5qgyR-8S91YY-w@mail.gmail.com>
References: <20150320194337.2573.72944@wrigleys.postgresql.org>
	<26862.1427166720@sss.pgh.pa.us>
	<CAB7nPqST=EUbvsx-mapemgA0jD9e9sgVezaV-UvtkeMfXyrigw@mail.gmail.com>
	<13096.1427204266@sss.pgh.pa.us>
	<CAB7nPqSkh+Kma8+oGd5w67qZzSaVtkFo-2dgHwf5MAsr+enk4g@mail.gmail.com>
	<55121967.90308@personal.formauri.es>
	<CAB7nPqRRyhDtNMKC=vuTpO8XRwMEigyFh2VttnkC_eE7LbTAXQ@mail.gmail.com>
	<55129971.2070208@personal.formauri.es>
	<CAB7nPqQ=as+tSE6kA36RLpbueb__Zj_=L+wWonKMH5-nczj3yg@mail.gmail.com>
	<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>
	<CAB7nPqQL4wsAX3E9gjQtOetgYQ8w7kWtFQQ3ctJfCc3PONjprA@mail.gmail.com>
	<87h9t84ig5.fsf@news-spur.riddles.org.uk>
	<CAB7nPqTtEJB08PEVj48SL4fFYMTaAxVX3CPE77SCpHYoZ3763Q@mail.gmail.com>
	<CAB7nPqRq94VT5WiYyCjSS+E_=mwWL49W-MXv5qgyR-8S91YY-w@mail.gmail.com >
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

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



view thread (31+ messages)  latest in thread

Message-ID: <55159907.1060809@personal.formauri.es>
Permalink:  ../55159907.1060809@personal.formauri.es/
Also on:    postgresql.org/message-id/55159907.1060809@personal.formauri.es

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: pgsql-004@personal.formauri.es, michael.paquier@gmail.com, andrew@tao11.riddles.org.uk, tgl@sss.pgh.pa.us, rschaaf@commoninf.com
  Subject: Re: BUG #12885: The result of casting a double to an integer depends on the database version
  In-Reply-To: <55159907.1060809@personal.formauri.es>
  References: <20150320194337.2573.72944@wrigleys.postgresql.org> <26862.1427166720@sss.pgh.pa.us> <CAB7nPqST=EUbvsx-mapemgA0jD9e9sgVezaV-UvtkeMfXyrigw@mail.gmail.com> <13096.1427204266@sss.pgh.pa.us> <CAB7nPqSkh+Kma8+oGd5w67qZzSaVtkFo-2dgHwf5MAsr+enk4g@mail.gmail.com> <55121967.90308@personal.formauri.es> <CAB7nPqRRyhDtNMKC=vuTpO8XRwMEigyFh2VttnkC_eE7LbTAXQ@mail.gmail.com> <55129971.2070208@personal.formauri.es> <CAB7nPqQ=as+tSE6kA36RLpbueb__Zj_=L+wWonKMH5-nczj3yg@mail.gmail.com> <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> <CAB7nPqQL4wsAX3E9gjQtOetgYQ8w7kWtFQQ3ctJfCc3PONjprA@mail.gmail.com> <87h9t84ig5.fsf@news-spur.riddles.org.uk> <CAB7nPqTtEJB08PEVj48SL4fFYMTaAxVX3CPE77SCpHYoZ3763Q@mail.gmail.com> <55159907.1060809@personal.formauri.es>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox