[Cfp-interest] strtodN subject sequence with minus sign

Jim Thomas jaswthomas at sbcglobal.net
Mon Aug 27 16:15:12 PDT 2012


On Aug 26, 2012, at 9:36 PM, Fred J. Tydeman wrote:

> On Tue, 21 Aug 2012 11:36:20 -0700 Jim Thomas wrote:
>> 
>>>> 
>>>> 11.6 strtod32, strtod64, and strtod128 functions <stdlib.h>
>>>> PDF page 31, item [4]:
>>>> Add at the end of: 
>>>> "If the subject sequence begins with a minus sign, the sequence is
>>>>  interpreted as negated."
>>>> (before rounding).
>>> 
>>> It says the sequence is interpreted as negated, not that the result of 
>> rounding the unnegated sequence is negated. So no change needed
> 
> C11 has a footnote on negated.  That footnote is:
> 
> 292) It is unspecified whether a minus-signed sequence is converted 
> to a negative number directly or by negating the value resulting from 
> converting the corresponding unsigned sequence (see F.5); the two
> methods may yield different results if rounding is toward positive or 
> negative infinity. In either case, the functions honor the sign of 
> zero if floating-point arithmetic supports signed zeros.
> 
> That makes it clear the "interpreted as negated" phrase has two meanings.

I believe the words give an implementation license to mis-round in this particular way. This doesn't really seem necessary since C11 without Annex F doesn't require correct rounding for strtod functions anyway. See below.

> 
>> In the Aug teleconference, David asked would "interpreted as negative" be 
>> better? I think it might be a little clearer. However, the current words ( 
>> negated) match what's in C11 for the generic strtod family. I'm inclined 
>> against making strtodN differ from strtod on this point. Does anyone think a 
>> C11 defect report is in order?
> 
> C11 F.5 has:
> 
> Functions such as strtod that convert character sequences to floating 
> types honor the rounding direction. Hence, if the rounding direction 
> might be upward or downward, the implementation cannot convert a 
> minus-signed sequence by negating the converted unsigned sequence.

This says that honoring the directed rounding modes requires negating before rounding. And we require the decimal strto functions to round correctly.

> 
> Since strtod32/64/128 are for IEEE-754 DFP types, F.5 is in effect and
> I believe we could differ some from strtof/d/ld.
> 
> I see no defect in C11.
> 
> I prefer adding "(before rounding)".

I still don't think it's strictly necessary, but wouldn't object to adding it.

-Jim

> 
> ---
> Fred J. Tydeman        Tydeman Consulting
> tydeman at tybor.com      Testing, numerics, programming
> +1 (775) 287-5904      Vice-chair of PL22.11 (ANSI "C")
> Sample C99+FPCE tests: http://www.tybor.com
> Savers sleep well, investors eat well, spenders work forever.
> 
> _______________________________________________
> Cfp-interest mailing list
> Cfp-interest at oakapple.net
> http://mailman.oakapple.net/mailman/listinfo/cfp-interest




More information about the Cfp-interest mailing list