Re: WIP: to_char, support for EEEE format

From: Brendan Jurd <direvus(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Euler Taveira de Oliveira <euler(at)timbira(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: WIP: to_char, support for EEEE format
Date: 2009-08-09 07:15:31
Message-ID: 37ed240d0908090015y3f6fd07ep3dcbe57eedc523a9@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2009/8/9 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> Brendan Jurd <direvus(at)gmail(dot)com> writes:
>> That would allow for a maximum of 10 exponent digits.  As an aside, I
>> note that int4out() hardcodes the maximum number of digits rather than
>> exposing a constant (c.f. MAXINT8LEN in int8.c).  I'm considering
>> adding MAXINT2LEN and MAXINT4LEN to int.c in passing.  Excessive
>> tinkering, or worthy improvement?
>
> Don't really care.  short and int are the same sizes on all platforms of
> interest, and are likely to remain so --- if they don't, we'll have way
> more places to fix than this one.  INT8 has historically been more
> platform-dependent.
>

"Excessive tinkering" it is, then. I went ahead with hardcoding the
expected 10 digits.

Here's version 6 of the EEEE patch, now with an all-new implementation
of (normalised) scientific notation in numeric.c, via the functions
numeric_out_sci() and get_str_from_var_sci(). So EEEE should now be
able to represent the full gamut of the numeric type.

regression=# select to_char(-1e-1000, '9.99EEEE');
to_char
-------------
-1.00e-1000
(1 row)

I also noticed that EEEE wasn't outputting a leading space for
positive numbers like the rest of to_char does. This meant that
positive and negative numbers weren't aligned. The logic to do this
for ordinary decimal representations is tied up in NUM_processor() and
NUM_numpart_to_char(), so unfortunately I wasn't able to reuse it.
Instead I just frobbed the code in the *_to_char() functions to make
this work.

Noting that Robert has dropped the patch from the July CF (and having
no objection to that) I'm going to submit this for September.

Cheers,
BJ

Attachment Content-Type Size
EEEE_6.diff.bz2 application/x-bzip2 5.1 KB
EEEE_5-to-6.diff.bz2 application/x-bzip2 3.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2009-08-09 07:40:00 Re: WIP: to_char, support for EEEE format
Previous Message Boszormenyi Zoltan 2009-08-09 06:00:39 Re: Split-up ECPG patches