**Submitter:** Fred Tydeman (US)

**Submission Date:** 2001-02-25

**Source:**

**Reference Document:** ISO/IEC
WG14 N943

**Version:** 1.1

**Date:** 2001-10-16 12:15:00

**Subject:** Make the base standard and Annex F consistent
for ` fmod()`,

**Summary**

,fmod(), andremainder()should be made consistent with each other when the divisor is zero. There are two "correct" behaviours when the divisor is zero: Treat it as a domain error (cannot divide by zero), or, based upon limits, compute a zero remainder. This series of changes may also require that IEEE-754 be changed (to allow a zero result in addition to the currently required invalid operation). Assuming thatremquo(),fmod(), andremainder()should be consistent with each other, the following needs to be done.remquo()An alternative is to do some of these changes, or changes along these lines.

It is assumed that requiring just the return of zero behaviour is too drastic as there are many millions of chips already doing the invalid operation behaviour.

**Details**

For a fixed, as one takes the limit asxapproaches zero, the remainder ofy/xapproaches zeroyand the quotient is unspecified.(0 <= |result| < |y|)IEC 60559 requires that

REMx, whenyis zero, be an invalid operation, e.g., a domain error.y

is currently allowed to be either 0 or a domain error by 7.12.10.1, while Annex F requires it to be an invalid exception, e.g., domain error.fmod(x,0)

is currently unspecified by 7.12.10.2, while Annex F requires it to be an invalid exception, e.g., domain error.remainder(x,0)

is currently unspecified by 7.12.10.3, while Annex F requires it to be an invalid exception, e.g., domain error. In addition, nothing is said about the quotient that is stored for this case.remquo(x,0)

Counter-argument: These functions are discontinuous along the linesory = mxfor integersy = (m+1/2)xm. We see no reason to "take the limit asapproaches zero".yAllowing two different behaviours for these functions for the same arguments, will cause applications to be more complicated, with no real added benefit.

Counter-counter-argument: By discontinuous, I assume you mean that they are like saw-tooth shaped functions, e.g., a linear rise and a vertical fall. I agree with that, but, as one approaches the line, the height of the teeth gets smaller and smaller.y=0

**Suggested Technical Corrigendum**

In 7.12.10.1 ` fmod`:

No change needed.

In 7.12.10.2 ` remainder`:

Add to Returns:

Ifis zero, whether a domain error occurs or theyfunctions return zero is implementation defined.remainder

In 7.12.10.3 ` remquo`:

Add to Returns:

Ifis zero, whether a domain error occurs or theyfunctions return zero is implementation defined.remquo

Ifis zero, the quotient stored is unspecified.y

In F.9.7.1 ` fmod`:

Change

to two items:returns afmod(x,y)and raises the "invalid" floating-point exception forNaNinfinite orxzero.y

andreturns afmod(x,y)and raises the "invalid" floating-point exception forNaNinfinite.x

Forzero,yeither returns a zero (with sign offmod(x,y)), or returns axand raises the "invalid" floating-point exception.NaN

In F.9.7.2 ` remainder`:

Add:

Forzero,yeither returns a zero (with sign ofremainder(x,y)), or returns axand raises the "invalid" floating-point exception.NaN

In F.9.7.3 ` remquo`:

Add:

ForAlso add,zero,yeither returns a zero (with sign ofremquo(x,y)), or returns axand raises the "invalid" floating-point exception; and, in both cases, has an unspecified quotient stored.NaN

Whenreturns aremquo, the quotient stored is unspecified.NaN

**Technical Corrigendum**

In 7.12.10.2 ` remainder`:

Add to Returns:

Ifis zero, whether a domain error occurs or theyfunctions return zero is implementation defined.remainder

In 7.12.10.3 ` remquo`:

Add to Returns:

Ifis zero, whether a domain error occurs or theyfunctions return zero is implementation defined.remquo

Ifis zero, the quotient stored is unspecified.y

In J.3.12 Library functions:

Add (after fmod):

Whether a domain error occurs or zero is returned when anfunction has a second argument of zero (7.12.10.2).remainder

Whether a domain error occurs or zero is returned when anfunction has a second argument of zero (7.12.10.3).remquo