"Pedro M. Ferreira" <pfrazao(at)ualg(dot)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 like
int 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