Document: WG14 N1498

Add missing error conditions in math functions


Submitter: Fred J. Tydeman (USA)
Submission Date: 2010-06-17
Subject: Add missing error conditions in math functions

Currently, several of the math library functions do not specify error conditions that might happen on some implementations, e.g., sin(INFINITY). Since it is unspecified, different implementations could do any of several things: indicate no error, or indicate different errors. This makes writing portable applications difficult.

This is independent of IEEE-754.

For implementations that do not support INFINITY, having sin(INFINITY) be specified as a domain error has no effect on the implementation.

Add the following error conditions to the various math functions.

7.12.4.5 The cos functions

A domain error occurs for infinite arguments.

7.12.4.6 The sin functions

A domain error occurs for infinite arguments.

7.12.4.7 The tan functions

A domain error occurs for infinite arguments.

7.12.8.4 The tgamma functions

A domain error occurs for a negative infinite argument.

7.12.10.1 The fmod functions

If x is infinite and y is not a NaN, a domain error occurs.

7.12.10.2 The remainder functions

If x is infinite and y is not a NaN, a domain error occurs.

7.12.10.3 The remquo functions

If x is infinite and y is not a NaN, a domain error occurs.

7.12.13.1 The fma functions

A domain error may occur for fma(x,y,z) if one of x and y is infinite, the other is zero, and z is a NaN.

A domain error occurs for fma(x,y,z) if one of x and y is infinite, the other is zero, and z is not a NaN.

A domain error occurs for fma(x,y,z) if x times y is an exact infinity and z is also an infinity but with the opposite sign.

Add the following to the Rationale for <math.h>:

For the same function call, having one implementation indicate an error and another implementation indicate no error makes it difficult to write portable application code. An example of this is: sin(INFINITY); where one implementation calls it a domain error, while another implementation indicates no error.