[comp.arch] IEEE 754 "rem" query

ok@quintus.UUCP (Richard A. O'Keefe) (12/15/89)

I have read the IEEE 754 and IEEE 854 standards as carefully as I can,
and it is not clear to me what the sign of x REM y should be when x=0.
x REM y is "defined ... by the mathematical relation r = x - y.n"
in section 5.1.  If we thought of this as involving an subtraction in
the implementation, section 6.3's rule that "when the sum of two operands
with opposite signs (or the difference of two operands with like signs)
is exactly zero, the sign of that sum (or difference) shall be "+" in
all rounding modes except round towards -oo, in which mode that sign 
shall be "-".  However, x+x = x-(-x) retains the same sign as x even
when x is zero."  This would mean that the sign of -0.0 REM y might be
"+" or "-" depending on the sign of "y.n".  However, (a) the sign of y.n
is not defined because this is a mathematical multiplication, not an IEEE
one, and (b) if we took this reading the result of (-0.0 REM y) would
depend on the rounding mode, and x REM y is "defined regardless of the
rounding mode".

I think the result of (-0.0 REM y) should be -0.0 for any non-zero y, and
that's what I get when I try it, but is that the intent of the standard?

tim@nucleus.amd.com (Tim Olson) (12/15/89)

In article <1291@quintus.UUCP> ok@quintus.UUCP (Richard A. O'Keefe) writes:
| I have read the IEEE 754 and IEEE 854 standards as carefully as I can,
| and it is not clear to me what the sign of x REM y should be when x=0.
| x REM y is "defined ... by the mathematical relation r = x - y.n"
| in section 5.1.  If we thought of this as involving an subtraction in
| the implementation, section 6.3's rule that "when the sum of two operands
| with opposite signs (or the difference of two operands with like signs)
| is exactly zero, the sign of that sum (or difference) shall be "+" in
| all rounding modes except round towards -oo, in which mode that sign 
| shall be "-".  However, x+x = x-(-x) retains the same sign as x even
| when x is zero."  This would mean that the sign of -0.0 REM y might be
| "+" or "-" depending on the sign of "y.n".  However, (a) the sign of y.n
| is not defined because this is a mathematical multiplication, not an IEEE
| one, and (b) if we took this reading the result of (-0.0 REM y) would
| depend on the rounding mode, and x REM y is "defined regardless of the
| rounding mode".
| 
| I think the result of (-0.0 REM y) should be -0.0 for any non-zero y, and
| that's what I get when I try it, but is that the intent of the standard?

Yes.  My copy of the Standard 754 (admittedly old) says:

      "... r = x - y*n, where n is the integer nearest the exact value
      x/y... If r=0, its sign shall be that of x."


	-- Tim Olson
	Advanced Micro Devices
	(tim@amd.com)