Document: WG14 N1594


Possible defect in <math.h>: missing domain errors


Submitter: Fred J. Tydeman (USA)
Submission Date: 2012-1-11
Subject: Missing domain errors

There are many implementations that use IEEE-754 floating-point (so have infinities), but do not claim conformance to Annex F (so are not bound by the error requirements of that annex).

7.12.1 Treatment of error conditions has:

The behavior of each of the functions in <math.h> is specified for all representable values of its input arguments, except where stated otherwise.

So, for an implementation that has infinity, but is not supporting Annex F, what is cos(infinity)?

The description of cos() has no errors listed (so there are no errors as per 7.12.1), yet cos(infinity) has no mathematical meaning, so it cannot compute the cosine of x (as per 7.12.4.5). This seems like a contradiction.

We should add to the main body of the standard the missing domain error cases. I believe that the following changes to C11 should be done.

  1. 7.12.4.5 The cos functions

    Add: A domain error occurs for an infinite argument.

  2. 7.12.4.6 The sin functions

    Add: A domain error occurs for an infinite argument.

  3. 7.12.4.7 The tan functions

    Add: A domain error occurs for an infinite argument.

  4. 7.12.8.4 The tgamma functions

    Change to: A domain error or pole error may occur if x is a negative integer, zero, or -infinity.

  5. 7.12.10.1 The fmod functions

    Add: A domain error occurs for x infinite and y not a NaN.

  6. 7.12.13.1 The fma functions

    Add: A domain error may occur for infinite arguments.