<p>This is an update for N2823 as requested by WG14 in the 2021/11 meeting.</p>
<p>All changes requested by WG14 were made. They include: More text for motivation and rationale, removal of what was voted in already, and addition of relative diffs (from/to aspects of the suggested changes to the standard).</p>
<p>Some members of the WG21 committee seem to be concerned with the expansion in scope in freestanding environments in C23 due to the changes brought in from the integration of TS 18661. This paper tries to address the concerns brought forward in WG14 reflector messages 19444 and 19445.</p>
<p>In particular, bringing in more thread local storage via the errno variable and bringing in locales through the string to numeric value functions. The addition of thread local storage is a problem in general since freestanding applications often do not want to have "global" storage overhead or cannot have it. Locales have a similar issue in that most freestanding applications do not deal with locales (and hence the associated storage needed for them).</p>
<p>The general floating point environment (described in 7.6) also has thread storage duration and hence requires overhead in terms of "global" storage. This was not directly mentioned in the reflector messages but is a conceivable concern that needs to be addressed.</p>
<p>Two alternatives are proposed to try and alleviate the concerns given above. The first one is intended to reduce the scope of changes brought in by the TS to remove requirements for thread local storage (errno) and modification to "global" state (the floating-point environment, which also has thread storage duration), and does so in a general way. The second alternative (which can be done in conjunction with the first alternative as requested by WG14) is to let implementations choose between having errno or modifying the floating point exception states, or both where possible, and does so by modifying functions that require errno directly. Note that the second alternative does not remove the need to modify the floating-point environment in cases outside certain functions. For example, setting and clearing floating-point exception flags are required.</p>
<p>Note for alternative 1: The practical set of functions in the fenv.h header seem to be only fegetround and fe_dec_getround, but the other query functions were listed as well since they do not modify the floating-point environment either. The reduced list of functions is a possible modification to alternative 1, if chosen.</p>
<p>Alternative 1: In N2596, change Section 4#7 from:</p>
<p>The strictly conforming programs that shall be accepted by a conforming freestanding implementation that defines __STDC_IEC_60559_BFP__ or __STDC_IEC_60559_DFP__ may also use features in the contents of the standard headers <fenv.h> and <math.h> and the numeric conversion functions (7.22.1) of the standard header <stdlib.h>. All identifiers that are reserved when <stdlib.h> is included in a hosted implementation are reserved when it is included in a freestanding implementation.</p>
<p>to:</p>
<p>The strictly conforming programs that shall be accepted by a conforming freestanding implementation that defines __STDC_IEC_60559_BFP__ or __STDC_IEC_60559_DFP__ may also use features<span style="color: #00ff00;">, without the requirements to set errno (see 7.5) or modify the floating-point environment (see 7.6), in the following:</span><br /><span style="color: #00ff00;">- all the macros and the following functions in <span style="color: #000000;"><fenv.h></span>: fegetexceptflag, fetestexceptflag, fetestexcept, fegetmode, fegetround, fe_dec_getround, fegetenv</span><br /><span style="color: #00ff00;">- <span style="color: #000000;"><math.h></span></span><br /><span style="color: #00ff00;">- the floating-point numeric conversion functions (7.22.1) of the standard header <stdlib.h>: strtod, strtof, strtold, strtod32, strtod64, strtod128</span><br /><span style="color: #000000;">All identifiers that are reserved when <stdlib.h> is included in a hosted implementation are reserved when it is included in a freestanding implementation.</span></p>
<p><br />Independent addition/Alternative 2: In N2596 change 7.22.1.5#10 from:</p>
<p>The functions return the converted value, if any. If no conversion could be performed, zero is returned. If the correct value overflows and default rounding is in effect (7.12.1), plus or minus HUGE_VAL, HUGE_VALF, or HUGE_VALL is returned (according to the return type and sign of the value), and the value of the macro ERANGE is stored in errno. If the result underflows (7.12.1), the functions return a value whose magnitude is no greater than the smallest normalized positive number in the return type; whether errno acquires the value ERANGE is implementation-defined.</p>
<p>to:</p>
<p>The functions return the converted value, if any. If no conversion could be performed, zero is returned. If the correct value overflows and default rounding is in effect (7.12.1), plus or minus HUGE_VAL, HUGE_VALF, or HUGE_VALL is returned (according to the return type and sign of the value)<span style="color: #00ff00;">;</span> the value of the macro ERANGE is stored in errno <span style="color: #00ff00;">if the integer expression math_errhandling & MATH_ERRNO is nonzero; and the "overflow" floating-point exception is raised if the integer expression math_errhandling & MATH_ERREXCEPT is nonzero.</span></p>
<p>If the result underflows (7.12.1), the functions return a value whose magnitude is no greater than the smallest normalized positive number in the return type; whether errno acquires the value ERANGE <span style="color: #00ff00;">if the integer expression math_errhandling & MATH_ERRNO is nonzero</span> is implementation defined. <span style="color: #00ff00;">If the integer expression math_errhandling & MATH_ERREXCEPT is nonzero, whether the "underflow" floating-point exception is raised is implementation-defined.</span></p>
<p>Change 4#7 as follows from:</p>
<p>The strictly conforming programs that shall be accepted by a conforming freestanding implementation that defines __STDC_IEC_60559_BFP__ or __STDC_IEC_60559_DFP__ may also use features in the contents of the standard headers <fenv.h> and and <math.h> and the numeric conversion functions (7.22.1) of the standard header <stdlib.h>. All identifiers that are reserved when is included in a hosted implementation are reserved when <stdlib.h> is included in a freestanding implementation.</p>
<p>to:</p>
<p>The strictly conforming programs that shall be accepted by a conforming freestanding implementation that defines __STDC_IEC_60559_BFP__ or __STDC_IEC_60559_DFP__ may also use features in the contents of the standard headers <fenv.h> and <math.h> and the <span style="color: #00ff00;">floating-point</span> numeric conversion functions (7.22.1) of the standard header <stdlib.h>. All identifiers that are reserved when is included in a hosted implementation are reserved when <stdlib.h> is included in a freestanding implementation.</p>