This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 28679 - math:log contradiction about result when argument is zero
Summary: math:log contradiction about result when argument is zero
Status: CLOSED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: Functions and Operators 3.1 (show other bugs)
Version: Working drafts
Hardware: PC Windows NT
: P2 normal
Target Milestone: ---
Assignee: Michael Kay
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-22 20:34 UTC by Priscilla Walmsley
Modified: 2016-12-16 19:55 UTC (History)
0 users

See Also:


Attachments

Description Priscilla Walmsley 2015-05-22 20:34:15 UTC
The text describing math:log says "The effect is that if the argument is less than or equal to zero, the result is NaN."  But, the 2nd example says that if the argument is zero, the result is -INF rather than NaN.
Comment 1 Michael Kay 2015-05-29 08:27:23 UTC
The same problem applies to math:log10(0)
Comment 2 Michael Kay 2015-05-29 08:58:09 UTC
Thanks for raising this.

IEEE 754-2008 says (section 9.2.1) that log(0) and log10(0) return -INF and signal the divideByZero exception.

We say in section 4.2:

The [IEEE 754-2008] specification also describes handling of two exception conditions called divideByZero and invalidOperation. The IEEE divideByZero exception is raised not only by a direct attempt to divide by zero, but also by operations such as log(0). The IEEE invalidOperation exception is raised by attempts to call a function with an argument that is outside the function's domain (for example, sqrt(-1) or log(-1). These IEEE exceptions do not cause a dynamic error at the application level; rather they result in the relevant function or operator returning NaN. The underlying IEEE exception may be notified to the application or to the user by some ·implementation-defined· warning condition, but the observable effect on an application using the functions and operators defined in this specification is simply to return NaN with no error.

Both Java and .NET follow our examples: log(0) returns -INF, while log(-1) returns NaN.

The text in 4.2 also appears to be incorrect as regards simple division by zero. Like log(0), division by zero returns ±INF, and signals the divideByZero exception.

I suggest revising the relevant paragraph in 4.2 to read:

The [IEEE 754-2008] specification also describes handling of two exception conditions called divideByZero and invalidOperation. The IEEE divideByZero exception is raised not only by a direct attempt to divide by zero, but also by operations such as log(0). The IEEE invalidOperation exception is raised by attempts to call a function with an argument that is outside the function's domain (for example, sqrt(-1) or log(-1)<add>)</add>. <add>Although IEEE defines these as exceptions, it also defines "default non-stop exception handling" in which the operation returns a defined result, typically positive or negative infinity, or NaN. With this function library,</add> these IEEE exceptions do not cause a dynamic error at the application level; rather they result in the relevant function or operator returning <mod>the defined non-error result</mod>. The underlying IEEE exception may be notified to the application or to the user by some ·implementation-defined· warning condition, but the observable effect on an application using the functions and operators defined in this specification is simply to return <mod>the defined result (typically -INF, +INF, or NaN)</mod> with no error.

Then in math:log and math:log10 we should say "The effect is that if the argument is zero, the result is -INF, and if the argument is less than zero, the result is NaN."
Comment 3 Michael Kay 2015-06-02 20:29:18 UTC
The proposal was accepted and has been applied.