[Cfp-interest] freestanding

Joel C. Salomon joelcsalomon at gmail.com
Sun Feb 26 18:33:35 PST 2012


On 02/26/2012 06:20 PM, Jim Thomas wrote:
> On Feb 25, 2012, at 8:00 PM, Joel C. Salomon wrote:
>> Might it be reasonable, for reasons of completeness, to also define
>> strfromf, or does the lack of a float-specific format make this too
>> confusing?
>>
>> I could go either way on this, but if there is no strfromf, add a note
>> that strfromd doubles as the IEEE 754-mandated
>> single-precision-to-string operation. [pun intended]
> 
> An ideal specification of strfromf would convert float  to a character sequence directly, without first promoting x to double, as would happen with snprintf. The difference can show up in %a formatting. But such a specification would be a fair amount more complicated. I'm inclined to add strfromf, using the same snprintf definition as for the other two strfrom functions and noting the implicit promotion to double. If it becomes troublesome, we could easily remove it later. What do you think?

Dilemma:  If strfromf(f) is indistinguishable from strfromd((double)f),
it doesn't make much sense to define it; defining strfromf in the
"reasonable" way could get complicated -- but my reading of 754 requires
(or at least strongly suggests) that the function exist.

Maybe we ask the 754 list whether I'm right and the float-specific
version is mandated.  If it is, we define it; otherwise we leave it out
and note that we've done so in the CFP document.

If we end up omitting strfromf, we should also include a note on the
correct usage of strfromd when applied to floats, specifically what the
maximum meaningful precision is when using the %a format.

--Joel


More information about the Cfp-interest mailing list