<div dir="ltr"><div dir="ltr">Hi, I agreed to look into this "easy" issue on the 7 Feb 2024 call. Fred reported the issue and Jim provided significant background below.</div><div dir="ltr"><br></div><div dir="ltr">A refinement of the description of exceptional cases in gamma and log gamma foliates into a tangle of issues tracing back to language in 754. Here are minimal changes intended to improve reader understanding.</div><div dir="ltr"><br></div><div>Proposal 1 -- IEEE 754/IEC 60559 sect. 9.2, included here in CFP as background for the C proposals that follow.</div><div>Current:</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>divideByZero: An operation that has a simple pole for some finite floating-point operand shall signal the divideByZero exception and return an infinity by default.</div></blockquote><div>Proposed:</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>divideByZero: An operation that has a <span style="background-color:rgb(255,255,0)">singularity</span> for some finite floating-point operand, <span style="background-color:rgb(255,255,0)">where the mathematical result tends to infinity</span>, shall signal the divideByZero exception and return an infinity by default.</div><div><br></div></blockquote><div dir="ltr"><div>Proposal 2 -- C sect 7.12.1 para 3</div><div>Current:</div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div>Similarly, a pole error (also known as a singularity or infinitary) occurs if and only if the mathematical function has an exact infinite result as the finite input argument(s) are approached in the limit (for example, log(0.0)). The description of each function lists any required pole errors; an implementation may define additional pole errors, provided that such errors are consistent with the mathematical definition of the function. On a pole error, the function returns an implementation-defined value; if the integer expression math_errhandling & MATH_ERRNO is nonzero, the integer expression errno acquires the value ERANGE; if the integer expression math_errhandling & MATH_ERREXCEPT is nonzero, the "divide-by-zero" floating-point exception is raised.</div></div></blockquote><div dir="ltr"><div>Proposed:</div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div>Similarly, a <span style="background-color:rgb(255,255,0)">singularity</span> error occurs if and only if the mathematical function <span style="background-color:rgb(255,255,0)">tends to infinity</span> as the finite input argument(s) are approached in the limit (for example, log(0.0)). The description of each function lists any required <span style="background-color:rgb(255,255,0)">singularity</span> errors; an implementation may define additional <span style="background-color:rgb(255,255,0)">singularity</span> errors, provided that such errors are consistent with the mathematical definition of the function. On a <span style="background-color:rgb(255,255,0)">singularity</span> error, the function returns an implementation-defined value; if the integer expression math_errhandling & MATH_ERRNO is nonzero, the integer expression errno acquires the value ERANGE; if the integer expression math_errhandling & MATH_ERREXCEPT is nonzero, the "divide-by-zero" floating-point exception is raised.</div></div></blockquote><div><br></div>Proposal 3 -- C sect 7.12.x, Change 25 instances<div>Current:</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>pole error</div></blockquote><div>Proposed:</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="background-color:rgb(255,255,0)">singularity</span> error</div></blockquote><div><br></div>Proposal 4 -- C sect 1.12.8.3 para 2 on log gamma<div>Current:</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>A pole error may occur if x is a negative integer or zero.</div></blockquote><div>Proposed:</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>A <span style="background-color:rgb(255,255,0)">domain error or singularity error</span> may occur if x is a negative integer or zero.</div></blockquote><br>Proposal 5 -- C sect 1.12.8.4 para 2 on log gamma<div>Current:</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>A domain error or a pole error may occur if x is a negative integer or zero.</div></blockquote><div>Proposed:</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>A <span style="background-color:rgb(255,255,0)">domain error or singularity error</span> may occur if x is a negative integer or zero.</div></blockquote><div><div dir="ltr"><div><br></div><div><br></div>DISCUSSION -- item by item</div><div dir="ltr"><br><div>Proposal 1 -- The use of "pole" in 754-2019 is not best. Refer to the Mathematical Discussion below for some elaboration on singularities. Given the decades of "divide-by-zero" exceptions behind us, why fuss about the name, even if some cases are not, strictly speaking, divide by zero?</div><div><br></div><div>Proposals 2 & 3 -- The current C usage "exact infinite result" seems to descend from the language of the real numbers augmented by signed infinity. The "exact" may suggest a distinction from overflow to infinity, where a result is finite but too large to represent (and the Inexact exception is raised).<br><br>BONUS ITEM: 7.2.1 para 1 talks about "domain error". Whose domain? There are two functions at play here, the mathematical function defined over the real numbers, and the computer function, defined over a finite set enhanced with signed zero and signed infinity. This is a topic of its own.<br></div><div><br>Proposals 4 & 5 -- The domain vs. singularity error matter appears in item (2) just above. Jim calls out that zero is in the domain of gamma() in IEEE arithmetic, because the sign of zero determines the sign of the resulting infinity. This language will change if the special cases from annex section F.10 are brought into the body of the standard.<div><div class="gmail_signature"><div><br></div><div>MATHEMATICAL DISCUSSION -- singularities in 3 flavors</div><div><b><br></b></div><div>Briefly, the language of the exceptions in this note pertains to the complex domain. An "isolated singularity" x of f() is value for which f() is analytic in a punctured disc around x, but excluding x. An isolated singularity may take exactly one of three forms:</div><div><ol><li style="margin-left:15px">Removable singularity – a case such as f(x) = sin(x)/x, which can be defined as 1.0 at x=0, resulting in a function analytic at the removable singularity.<br><br></li><li style="margin-left:15px">Pole<b> </b>– a case such as f(x) = 1/x, which tends to infinity at x but and for which f(x)*p(x) is bounded, for a polynomial p() of sufficient degree (the "order" of the pole). If the degree of p() is one, it's a "simple pole". (This is the source of the "simple pole" language in 754.)<br><br></li><li style="margin-left:15px">Essential singularity – a case such as f(x) = log(x) at zero, which cannot be bounded by any polynomial, and remarkably takes every complex value arbitrarily close to x, depending on the direction of approach.</li></ol></div><div>The simple observation is that not all singularities encountered in the math library are poles. It's inelegant to bend the term "pole" rather than use a mathematically correct term like "singularity". I have initiated discussion of a possible change to 754, but C can use robust terminology independent of 754.</div><div><br></div></div></div></div></div></div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">-Jerome Coonen<div> 650.996.4738</div><div> <a href="mailto:jcoonen@gmail.com" target="_blank">jcoonen@gmail.com</a></div></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Feb 6, 2024 at 2:51 PM Jim Thomas <<a href="mailto:jaswthomas@sbcglobal.net">jaswthomas@sbcglobal.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>Some followup, including suggestion for how to proceed ...<br><div><br><blockquote type="cite"><div>On Feb 5, 2024, at 9:49 AM, Jim Thomas <<a href="mailto:jaswthomas@sbcglobal.net" target="_blank">jaswthomas@sbcglobal.net</a>> wrote:</div><br><div><div>Some thoughts related to Issue 1 in <a href="https://wiki.edg.com/pub/CFP/WebHome/C26C.HTM" target="_blank">https://wiki.edg.com/pub/CFP/WebHome/C26C.HTM</a> ...<div><div><br></div><div>Back to the definitions of errors. 7.12.1 says:</div></div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div>… a domain error occurs if and only if an input argument is outside the domain over which the mathematical function is defined. </div></div></blockquote><div><div><br></div><div>and </div><div><br></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div>… a pole error (also known as a singularity or infinitary) occurs if and only if the mathematical function has an exact infinite result as the finite input argument(s) are approached in the limit (for example, <b>log(0.0)</b>).</div></div></blockquote><div><div><br></div><div>Domain and pole errors are defined in terms of mathematical functions. The pole error definition obscures this fact by referring to “an exact infinite result”, though “exact” isn’t applicable to mathematical function results. (Note that <b>log(0.0)</b> is in program font, which is appropriate: a pole error occurs for the execution of <b>log(0.0)</b> because the mathematical function log(x) has a pole at 0.)</div></div></div></div></blockquote><blockquote type="cite"><div><div><div><div><br></div><div>Does the mathematical function’s range include an infinity? The domain error definition doesn’t say, but if an infinity were not included, a domain error would occur for <b>log(0.0)</b>. The pole error definition implies the mathematical function’s range does include an infinity, and the parenthetical example says a pole error occurs for <b>log(0.0)</b>. </div><div><br></div><div>I think the mathematical functions should have the range of the extended real numbers, i.e. of the real numbers together with infinity. Then poles are at points within the domain, and <b>log(0.0)</b> causes a pole error and not a domain error, as I believe is the general understanding.</div></div></div></div></blockquote><div><br></div>1a Suggest we review these definitions with an eye toward rewording them to clarify that the mathematical functions include infinity. </div><div><br></div><div>For the pole error definition, maybe “… if and only if the mathematical function has an infinite value where a finite argument *) is approached in the limit.” where the footnote is:</div><div><br></div><div>*) For a function of n variables "a finite argument" is intended to mean an n-tuple of finite arguments.</div><div><br></div><div><blockquote type="cite"><div><div><div><div><br></div><div>Unlike domain and pole errors, range errors are defined in terms of implementation limitations. This seems right, because range errors are about limitations of the approximation, not about the mathematical function.</div><div><br></div><div>For some math library functions, it’s may not be clear what the mathematical function is, e.g. <b>atan2</b>, and <b>logb</b>. For <b>pow</b> the mathematical function might appear to be x^y but IEC 60559 defines <b>pow</b> for some cases where x^y is undefined, e.g. <b>pow(</b>0<b>,</b> 0<b>)</b> = 1, thus the mathematical function corresponding to <b>pow</b> is a piecewise function. </div></div></div></div></blockquote><div><br></div>1b Suggest we consider how to clarify what is meant by "the mathematical function".</div><div><br><blockquote type="cite"><div><div><div><div><br></div><div>7.12.1 says “The description of each function lists any required domain/pole/range errors”. I think CFP agreed that this means these are the errors that are required to be reported (via errno or exceptions), </div></div></div></div></blockquote><div><br></div>Not quite right. Underflow range errors are not required to be reported. For underflow, a required range error would mean one where whether it is reported is implementation defined.</div><div>.<br><blockquote type="cite"><div><div><div><div>but his meaning is not clear in the standard. We should consider proposing a clarification.</div></div></div></div></blockquote><div><br></div>1c Suggest we consider how to clarify what is meant by "required error".<br><blockquote type="cite"><div><div><div><div><br></div><div>7.12.1 says the implementation is free to report domain/pole/range errors in other cases, provided the definition of the error fits. Given this, what is the intended meaning of, “a domain/pole/range error may occur” in a function description? It might just note a case that fits the definition of the error for which the implementation may (but is not required to) report the error. Or it might mean the definition fits for some implementations but not for others. Or it might mean that the implementation can determine whether the definition fits. </div></div></div></div></blockquote><div><br></div>1d Suggest we review function by function (including <b>tgamma</b> and <b>lgamma</b>) what “error may occur” is intended to mean. Then consider how to clarify what “error may occur” means (or use other words).</div><div><br></div><div><blockquote type="cite"><div><div><div><div><br></div><div>An error can't be required unless IEC 60559 allows a corresponding floating-point exception. For example, a non-IEC 60559 implementation might regard <b>atan2(0, 0)</b> to be a domain error. However, IEC 60559 defines the result and does not allow an “invalid” floating-point exception in this case. Thus, IEC 60559 implementations can not be allowed to report <b>atan2(0, 0)</b> as a domain error. </div></div></div></div></blockquote><div><br></div>I meant “ … can not be required to report …”. This is just a reminder of the constraint on the specification.</div><div><br></div><div>The handing of overflow is different for errno and exceptions. Was that a legacy case?</div><div><br></div><div>- Jim Thomas</div><div><br><blockquote type="cite"><div><div><div><div><br></div><div>These are not “easy” issues.</div><div><br></div><div>I suggest CFP defer discussion of Issue 1, and first clarify the broader issues.</div></div><div><br></div><div>- Jim Thomas</div><div><br></div></div></div></blockquote></div><br></div>_______________________________________________<br>
Cfp-interest mailing list<br>
<a href="mailto:Cfp-interest@oakapple.net" target="_blank">Cfp-interest@oakapple.net</a><br>
<a href="http://mailman.oakapple.net/mailman/listinfo/cfp-interest" rel="noreferrer" target="_blank">http://mailman.oakapple.net/mailman/listinfo/cfp-interest</a><br>
</blockquote></div>