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

Steve (Swift) Canon scanon at apple.com
Tue Sep 5 11:06:10 PDT 2023


My own preference is for rule 1 that you suggest (or maybe a modification that aligns subnormals with the minimum normal), but the rule that I have most-often heard requested by users is “the apparent LSB of the printed representation should be the LSB of the significand” (so that if 1.xxxxx8p0 is representable, so is 1.xxxxx1p0).

This would have us format binary64 as 1.xxxxxxxxxxxxxpE and 80-bit as [8-f].xxxxxxxxxxxxxxxxpE, but binary32 would be [8-f].xxxxxpE, which doesn’t line up with binary64.

– Steve

> On Sep 5, 2023, at 1:55 PM, Paul Zimmermann <Paul.Zimmermann at inria.fr> wrote:
> 
>       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