[cfp-interest 3549] Re: C23 possible defect: output bounds of imprecise math functions

Jim Thomas jaswthomas at sbcglobal.net
Fri Jul 18 17:17:02 PDT 2025


Greetings Trevor,

The short answer is yes, C (even with Annex F) does allow most library functions to produce values outside the range of the corresponding mathematical function. 

As noted in your report below, C specifies an output range where the mathematical function is multivalued, e.g. for asin(). 

Correctly rounded functions, e.g. sqrt(x) per Annex F, won’t return out-of-range values. C reserves cr_ prefixed names for correctly rounded math functions. 

Annex F recommends that implementations preserve as many useful mathematical properties as possible. Staying in range is one of many properties a user might want or expect from a C math function. Which of these properties are reasonable to require?

I think the C FP study group will be interested to consider the matter.

- Jim


> On Jul 16, 2025, at 8:32 PM, Trevor Gross <tmgross at umich.edu> wrote:
> 
> Hello Robert, Jim,
> 
> We are referencing N3220 and would like to receive clarification on the clause
> stating that some C mathematical operations are not required to be precise.
> Does this ever allow an implementation to produce values that are outside of the
> continuous function's output domain?
> 
> A HTML-formatted (but unrendered) defect report is below.
> 
> Best regards,
> Trevor Gross
> 
> ---
> 
> <b>Submitter:</b> Trevor Gross<br />
> <b>Submission Date:</b> 2025-07-16<br />
> 
> <p><b>Summary</b></p>
> 
> <p>Within Appendix F <em>ISO/IEC 60559 floating-point arithmetic</em>, s3p20
> states:</p>
> 
> <blockquote>
>    The C functions in the following table correspond to mathematical operations
>    recommended by ISO/IEC 60559. However, correct rounding, which ISO/IEC
>    60559 specifies for its operations, is not required for the C functions in
>    the table.
> </blockquote>
> 
> <p>This is followed by a table of operations. For operations where the output
> of the real-valued continuous function is bounded, does this paragraph allow a C
> function to return a result outside of these bounds?</p>
> 
> <p>As an example, <code>y = sin(x)</code> implies <code>|y| ≤ 1</code> for
> any real <code>x</code>. Would a C implementation that returns <code>sin(x) =
> 1.01</code> for some floating point value <code>x</code> be considered allowed
> imprecision, or is this disallowed?</p>
> 
> <p>A number of functions do specify an output domain, but these tend to be
> functions with repeating possible output values (e.g. inverse trigonometric
> functions). Functions that should have bounded output but do not specify this in
> the standard include:</p>
> 
> <ul>
>    <li><code>compoundn</code></li>
>    <li><code>cos</code></li>
>    <li><code>cosh</code></li>
>    <li><code>cospi</code></li>
>    <li><code>erf</code></li>
>    <li><code>erfc</code></li>
>    <li><code>exp</code></li>
>    <li><code>exp10</code></li>
>    <li><code>exp10m1</code></li>
>    <li><code>exp2</code></li>
>    <li><code>exp2m1</code></li>
>    <li><code>expm1</code></li>
>    <li><code>lgamma</code></li>
>    <li><code>rsqrt</code></li>
>    <li><code>sin</code></li>
>    <li><code>sinpi</code></li>
>    <li><code>sqrt</code></li>
>    <li><code>tanh</code></li>
> </ul>
> 
> <p><b>Suggested Technical Corrigendum</b><br></p>
> 
> <p>Add a new paragraph after F.3p20 that clarifies it is possible to rely on
> output being bounded:</p>
> 
> <blockquote>
> <b>
>    Unless otherwise specified, if the real-valued function corresponding to
>    a C function has a bounded output, that C function must also be bounded.
>    That is, a C function may return values that are imprecise (correspond to
>    different input values) but it may not return values that are not possble
>    to produce from the real function. An exception is made for outputs that
>    asymptotically approach a finite value, for which an open bound may be
>    replaced with a closed bound.
> </b>
> </blockquote>
> 
> <p>The asymptote clause is necessary to account for situations like
> <code>exp(-DBL_MIN) = 0.0</code>.</p>
> 




More information about the cfp-interest mailing list