Re: Float output formatting options - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Float output formatting options
Date
Msg-id 4535.1036423989@sss.pgh.pa.us
Whole thread Raw
In response to Re: Float output formatting options  ("Pedro M. Ferreira" <pfrazao@ualg.pt>)
List pgsql-hackers
"Pedro M. Ferreira" <pfrazao@ualg.pt> writes:
> Tom Lane wrote:
>> I think a single setting extra_float_digits would be sufficient.

> Ok. Assuming,

> int extra_float_digits, default 0, min -13, max 2

> If extra_float_digits==-13 and we are outputing a float4 this results in 
> a negative value for FLT_DIG+extra_float_digits.

You would want to clamp the values passed to %g to not less than 1.
I'd favor code likeint    ndig = FLT_DIG + extra_float_digits;if (ndig < 1)    ndig = 1;sprintf(ascii, "%.*g", ndig,
num);

Probably best to do it this way with float8 too; otherwise we're
essentially wiring in the assumption that we know what DBL_DIG is.
Which is exactly what we're trying to avoid doing.
        regards, tom lane


pgsql-hackers by date:

Previous
From: "Pedro M. Ferreira"
Date:
Subject: Re: Float output formatting options
Next
From: "Pedro M. Ferreira"
Date:
Subject: Re: Float output formatting options