pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Greg Stark <stark@mit.edu>
Cc: Kevin Grittner <Kevin.Grittner@wicourts.gov>
Cc: Christopher Gernon <kabigon@gmail.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #6217: to_char() gives incorrect output for very small float values
Date: Tue, 20 Sep 2011 17:57:10 -0400
Message-ID: <28405.1316555830@sss.pgh.pa.us> (raw)
In-Reply-To: <CAM-w4HPEucRFT7PYWKDDmeW9RmOamKmar8GzNrD=-mKQUW0faA@mail.gmail.com>
References: <201109201717.p8KHHlZU087195@wwwmaster.postgresql.org>
	<4E78899D020000250004140B@gw.wicourts.gov>
	<CAKwX5KiRDRkWKwvPq5XQy43_LdF+1CR51vzGy9MmbVikmYORew@mail.gmail.com>
	<4E789528020000250004141A@gw.wicourts.gov>
	<12259.1316545519@sss.pgh.pa.us>
	<4E78A6890200002500041430@gw.wicourts.gov>
	<13033.1316548340@sss.pgh.pa.us>
	<CAM-w4HPEucRFT7PYWKDDmeW9RmOamKmar8GzNrD=-mKQUW0faA@mail.gmail.com>

Greg Stark <stark@mit.edu> writes:
> On Tue, Sep 20, 2011 at 8:52 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> However, it would
>> be interesting to know what Oracle etc do with NaN and Infinity,
>> assuming they even support such numbers.

> Note that it looks like NUMBER cannot store either Infinity or NaN.
> They can only occur in BINARY_FLOAT and BINARY_DOUBLE. From the docs:

>> If a BINARY_FLOAT or BINARY_DOUBLE value is converted to CHAR or NCHAR, and the input is either infinity or NaN (not a number), then Oracle always returns the pound signs to replace the value.

> And testing shows:

> SQL> select to_char(cast('NAN' as binary_float), 'FM9999.9999') from dual;

> TO_CHAR(CA
> ----------
> ##########

Hmm, interesting.  They replace the whole field with '#', not just the
digit positions?  Because that's not what is happening in our code at
the moment, for the one case where we consider this at all:

regression=# select to_char('nan'::float8, '9999.9999EEEE');
    to_char     
----------------
  ####.########
(1 row)

The EEEE path seems rather broken in some other ways as well:

regression=# select to_char('43.5'::float8, '9999.9999EEEE');
   to_char   
-------------
  4.3500e+01
(1 row)

Since I did not say FM, why is it suppressing leading spaces here?

I'm starting to think that that code needs a wholesale rewrite
(not but what that's true of just about every part of formatting.c).

			regards, tom lane



view thread (11+ messages)

Message-ID: <28405.1316555830@sss.pgh.pa.us>
Permalink:  ../28405.1316555830@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/28405.1316555830@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, stark@mit.edu, Kevin.Grittner@wicourts.gov, kabigon@gmail.com
  Subject: Re: BUG #6217: to_char() gives incorrect output for very small float values
  In-Reply-To: <28405.1316555830@sss.pgh.pa.us>
  References: <201109201717.p8KHHlZU087195@wwwmaster.postgresql.org> <4E78899D020000250004140B@gw.wicourts.gov> <CAKwX5KiRDRkWKwvPq5XQy43_LdF+1CR51vzGy9MmbVikmYORew@mail.gmail.com> <4E789528020000250004141A@gw.wicourts.gov> <12259.1316545519@sss.pgh.pa.us> <4E78A6890200002500041430@gw.wicourts.gov> <13033.1316548340@sss.pgh.pa.us> <CAM-w4HPEucRFT7PYWKDDmeW9RmOamKmar8GzNrD=-mKQUW0faA@mail.gmail.com> <28405.1316555830@sss.pgh.pa.us>

* 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