[Cfp-interest 2892] Re: standardize printf %a/%A

Paul Zimmermann Paul.Zimmermann at inria.fr
Tue Sep 5 10:55:38 PDT 2023


       Hi Steve,

can you detail what the issue would be, for example for the three conventions
below?

1) force the output (when non-zero) to begin with hexadecimal digit '1'
   (this makes it easy to grasp the magnitude of the number by looking
   at the exponent)
2) for the output (when non-zero) to begin with an hexadecimal digit >= '8'
   (this minimizes the number of hexadecimal digits)
3) force the radix-2 exponent to be a multiple of 4
   (this corresponds to a radix-16 output, with the exponent converted into
   redix 2)

Paul

> From: "Steve (Swift) Canon" <scanon at apple.com>
> Date: Tue, 05 Sep 2023 13:20:26 -0400
> Cc: cfp-interest at ucbtest.org
> 
> > On Sep 4, 2023, at 12:19 PM, Paul Zimmermann <Paul.Zimmermann at inria.fr> wrote:
> > 
> >       Hi,
> > 
> > on the MPFR list there was some discussion about printf with hexadecimal
> > values (%a/%A):
> > 
> > https://sympa.inria.fr/sympa/arc/mpfr/2023-09/msg00004.html
> > 
> > It seems to me there is no convention in the C standard
> > (both for normal and subnormal values).
> > Would it make sense to have one?
> 
> One consideration that makes it difficult to have a sensible default is the mandatory promotion of float (and other small types) to double in varargs functions like the printf family. Unfortunately float and double don’t have the same number of fractional bits mod 4, so many rules that one might want to standardize will not hold when floats are used, leading to a certain amount of surprise for users who don’t understand the promotion rules.
> 
> That isn’t to say that it’s not worth doing, but a certain amount of confusion is hard to avoid.
> 
> – Steve=


More information about the Cfp-interest mailing list