Document: WG14 N1398
Submitter: Fred J. Tydeman (USA)
Submission Date: 2009-09-18
Related WG14 documents: N1354, DR 330
Subject: Treatment of math error conditions
Currently, some members of the committee believe that
errno is undefined, indeterminate, or
unspecified after calling a math function, even if no error
happens. This makes it difficult for application writters to
write robust mathematical software that uses the math library
In addition, POSIX assumes that
errno will only
be set to non-zero by a math function if an error happens,
errno will be left as 0 if no error
POSIX XBD: 4.19 Treatment of Error Conditions for Mathematical Functions has:
For all the functions in the <math.h> header, an application wishing to check for error situations should set errno to 0 and call feclearexcept(FE_ALL_EXCEPT) before calling the function. On return, if errno is non-zero or fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has occurred.
Defect Report 330 changed 7.12.1 paragrpah 1 last sentence to:
Each function shall execute as if it were a single operation without generating any of the exceptions "invalid", "divide-by-zero", or "overflow" except to reflect the result of the function.
Does "single operation" mean that the math functions cannot do "raise(SIGFPE)"? If so, should we make that requirement explicit?
If math errors are being indicated by
what happens to the floating-point status flags?
If math errors are being indicated by the floating-point
status flags, what happens to
I propose the following (DO A SEPERATE VOTE ON EACH CHANGE).
In 7.12.1, Treatment of error conditions, 1st paragraph: Add:
errnoshall be unaltered.
(math_errhandling & MATH_ERRNO)is zero [footnote], either
errnois unaltered or
errnoacquires the value corresponding to the error condition.
[Footnote] Math errors are being indicated by the floating-point exception flags.
(math_errhandling & MATH_ERREXCEPT)is zero [footnote], either none of the exceptions "invalid", "divide-by-zero", or "overflow" is raised or the floating-point exception corresponding to the error condition is raised.
[Footnote] Math errors are being indicated by