Document: WG14 N1354


Treatment of math error conditions


Submitter: Fred Tydeman (USA)
Submission Date: 2009-02-06
Subject: Treatment of math error conditions

I asked several questions about errno and the math library, similar to:

If an implementation sets

  math_errhandling to be MATH_ERREXCEPT
then
  math_errhandling & MATH_ERRNO     is zero
and
  math_errhandling & MATH_ERREXCEPT is non-zero

Now,

for a required domain error, sqrt(-1.0), by 7.12.1, "invalid" is raised. What can happen to errno? I saw several choices (and was told some others):

  errno is required to be left alone
  errno may be set to EDOM
  errno may be set to nonzero
  errno's value is undefined
  errno's value is indeterminate
  errno's value is unspecified

for a required range error, exp(DBL_MAX), by 7.12.1, "overflow" is raised. What can happen to errno? I saw several choices (and was told some others):

  errno is required to be left alone
  errno may be set to ERANGE
  errno may be set to nonzero
  errno's value is undefined
  errno's value is indeterminate
  errno's value is unspecified

for no errors mentioned, fabs(-1.0) What can happen to errno? I saw several choices (and was told others):

  errno is required to be left alone
  errno may be set to nonzero (by 7.5 <errno.h>, paragraph 3)
  errno's value is undefined
  errno's value is indeterminate
  errno's value is unspecified

Based upon the responses I got to those questions, implementations I have observed, and this

POSIX XBD: 4.19 Treatment of Error Conditions for Mathematical Functions:

I propose the following changes.

In 7.12.1, Treatment of error conditions, 1st paragraph: Add:

If no error occurs, errno shall be unaltered and none of "invalid", "div-by-zero" and "overflow" shall be raised.

If an error occurs and if the integer expression math_errhandling & MATH_ERRNO is zero, either errno is unaltered or errno acquires the value corresponding to the error condition.

If an error occurs and if the integer expression math_errhandling & MATH_ERREXCEPT is zero, either no floating-point exception is raised or the floating-point exception corresponding to the error condition is raised.

In F.9.1.* thru F.9.10.*: Add 'is a domain error and' before 'returns a NaN and raises the "invalid" floating-point exception'.

In F.9.1.* thru F.9.10.*: Add 'is a pole error and' before 'returns +/-INF and raises the "divide-by-zero" floating-point exception'.

In F.9.1.* thru F.9.10.*: Add 'is a range error and' before 'raises the "overflow" and "inexact" floating-point exceptions'.

In F.9.1.* thru F.9.10.*: Add 'is a range error and' before 'raises the "underflow" and "inexact" floating-point exceptions'.