Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id DADAFB5DC09 for ; Tue, 20 Sep 2011 18:57:18 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 09060-09 for ; Tue, 20 Sep 2011 21:57:12 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 61963B5DBF2 for ; Tue, 20 Sep 2011 18:57:12 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p8KLvAjp028406; Tue, 20 Sep 2011 17:57:10 -0400 (EDT) To: Greg Stark cc: Kevin Grittner , Christopher Gernon , pgsql-bugs@postgresql.org Subject: Re: BUG #6217: to_char() gives incorrect output for very small float values In-reply-to: References: <201109201717.p8KHHlZU087195@wwwmaster.postgresql.org> <4E78899D020000250004140B@gw.wicourts.gov> <4E789528020000250004141A@gw.wicourts.gov> <12259.1316545519@sss.pgh.pa.us> <4E78A6890200002500041430@gw.wicourts.gov> <13033.1316548340@sss.pgh.pa.us> Comments: In-reply-to Greg Stark message dated "Tue, 20 Sep 2011 22:25:54 +0100" Date: Tue, 20 Sep 2011 17:57:10 -0400 Message-ID: <28405.1316555830@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.404 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201109/129 X-Sequence-Number: 31146 Greg Stark writes: > On Tue, Sep 20, 2011 at 8:52 PM, Tom Lane 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