Document: WG14 N1470


FP flags to errno correspondence


Submitter: Fred J. Tydeman (USA)
Submission Date: 2010-05-10
Related documents: N1398
Subject: FP flags to errno correspondence

Problem: 7.12.1 Treatment of error conditions, in paragraph 7, mentions a correspondence between math errors, the floating-point exception flags and errno, but does not give the actual correspondence.

If a domain, pole, or range error occurs and the integer expression math_errhandling & MATH_ERRNO is zero,222) then errno shall either be set to the value corresponding to the error or left unmodified.

222) Math errors are being indicated by the floating-point exception flags rather than by errno.

I know of at least one implementation that uses the floating-point exception flags as the primary means of indicating math errors, and sometimes uses errno as a secondary means. For at least one function, they set the floating-point exception flags to indicate one kind of error (domain), yet set errno to indicate another kind of error (range).

Proposal.

Add the following table after 7.12.1 Treatment of error conditions, paragraph 7

Correspondence between floating-point exception flags, errors, and errno

FP flags       error    errno
invalid        domain   EDOM
divide-by-zero pole     ERANGE
overflow       range    ERANGE
underflow      range    ERANGE

Add to the rationale in the section on math errors:

If an error occurs in the math library functions, that error will be indicated with the floating-point exception flags and/or errno. If both are used, they are required to indicate the same error. The correspondence between the FP flags and errno is shown in 7.12.1.