Arithmetic Operations and Square Root
Handling Signed 0
If x,y are nonzero, and x+y=0 or x−y=0 exactly, then it is +0 for RN, RZ, RU modes, and −0 for RD.
However, if we have x+x or x−(−x), and x=±0, then the result has the same sign as x.
So be careful. If you have x+0, the result is not necessarily x. If x=−0, then the result is +0 in RN.
Square Root
If the input is greater than or equal to 0, the result always has a positive sign, with the exception of √−0=−0 Remainders Let x be a finite floating point number. Let y be a nonzero, finite floating point number. Then the remainder r=xREMy is defined as:
- r=x−yn where n is the integer closest to x/y.
- If x/y half way between two integers, let n be the even integer.
- If r=0, its sign is that of x.
Note: Remainders are always exactly representable under these conditions.
Also note that nowhere does it say x,y need to be integers!
Finally, xREM∞=x. Preferred Exponent How do we decide what the exponent should be for the result of an operation? This is not obvious for decimal formats. The rules are:
- If the result is inexact, use the smallest exponent.
- If the result is exact, then if the cohort includes a preferred exponent (defined below), use that one. Otherwise pick the one with the closest exponent to the preferred one.
Below are the preferred exponents:
- x±y: The smaller of the two exponents
- xy: Add the two exponents
- x/y: Subtract the two exponents
- \FMA(x,y,z): min(Q(x)+Q(y),Q(z))
- √x: ⌊Q(x)/2⌋ scaleB and logB
scaleB(x,n) is defined as xβn, correctly rounded, where x is any floating point number and n is an integer.
When x is finite and nonzero, logB(x) is ⌊logβ|x|⌋. We also have logB(\NaN)=\NaN, logB(±0)=−∞, logB(±∞)=∞