J3/17-129r1 To: J3 From: Malcolm Cohen Subject: IEEE rounding modes badly described Date: 2017 February 14 1. Introduction and discussion The description of the rounding mode IEEE_AWAY is incorrect. This is supposed to be what 60559 calls roundTiesToAway; that is, it rounds to the nearest representable value, with ties rounding away from zero. Furthermore, our description of IEEE_NEAREST is incomplete; it states that it rounds to nearest, but not that it rounds ties to the even value, i.e. that it is the what 60559 calls roundTiesToEven. Finally, we say that "...60559 specifies fives possible modes for rounding: - IEEE_NEAREST ..." which is completely wrong. 60559 does not specify ANY rounding mode which it calls IEEE_NEAREST (or IEEE_UP etc.). This needs to be completely rewritten, so that we use the 60559 terms for the rounding modes (which it calls rounding-direction attributes - unlike the 1970s version, it does not in principle have to be a "mode"), and state directly what our parameter names correspond to. It is arguable that we should use the 60559 terms throughout when we are talking about the rounding modes, sorry rounding-direction attributes, instead of our PARAMETER names. However, this paper does not advocate that. 2. Edits to 17-007 [448:30-31] 17.2 Derived types, constants, and operators defined in the modules, p3, second bullet, change "and IEEE_AWAY ... mode." to "IEEE_AWAY, and IEEE_OTHER for the rounding modes specified in 17.4 ["The rounding modes"].", making that whole sentence read "Its only possible values are those of named constants defined in the module: IEEE_NEAREST, IEEE_TO_ZERO, IEEE_UP, IEEE_DOWN, IEEE_AWAY, and IEEE_OTHER for the rounding modes specified in this document." {The rounding modes are now specified in this document, not in 60559, even though in reference to 60559's rounding-direction attributes.} [450:31] 17.4 The rounding modes, p1, Change "ISO/IEC/IEEE 60559:2011" to "This document". {60559 no longer specifies rounding modes, but we want to (to preserve semantics of existing code).} [451:4-10] Replace entire p2 "ISO/IEC... binary floating-point." with "ISO/IEC/IEEE 60559:2011 specifies five possible rounding-direction attributes: roundTiesToEven, roundTowardZero, roundTowardPositive, roundTowardNegative, and roundTiesToAway. These correspond to the rounding modes IEEE_NEAREST, IEEE_TO_ZERO, IEEE_UP, IEEE_DOWN, and IEEE_AWAY respectively. The rounding mode IEEE_OTHER does not correspond to any ISO/IEC/IEEE 60559:2011 rounding-direction attribute; if supported, the effect of this rounding mode is processor dependent." {Attach our rounding modes to the 60559 specifications, except for IEEE_OTHER which is completely processor dependent.} [451:20+] Same subclause, after p5, before NOTE 17.4, insert new note "NOTE 17.3a ISO/IEC/IEEE 60559:2011 requires support for roundTiesToAway only for decimal floating-point." {This quirk is worth a note, but no more. For us, they are all processor dependent anyway.} [451:20++] Same subclause, new note "NOTE 17.3b ISO/IEC/IEEE 60559:2011 requires that there is a language-defined means to specify a constant value for the rounding-direction attribute for all standard operations in a block. The means provided by this document are a CALL to IEEE_GET_ROUNDING_MODE at the beginning of the block followed by a CALL to IEEE_SET_ROUNDING_MODE with constant arguments, together another CALL to IEEE_SET_ROUNDING_MODE at the end of the block to restore the rounding mode." {Document how we satisfy this 60559 requirement. It's ugly, but it does satisfy it.} [540:16+] Annex A, after bullet "the initial rounding modes (17.4);", insert new bullets "- whether the processor supports a particular rounding mode (17.4); - the effect of the rounding mode IEEE_OTHER, if supported (17.4);" {These have always been processor dependent, but not clearly documented as such.} 3. Alternative edits for paragraph 2 The suggested edit above to [451:4-10] is recommended, as otherwise we are simply duplicating the work of the IEEE standard. However, if desired, we could instead repair our defective specification as follows. [451:4] 17.4 The rounding modes, p2, "five possible modes for rounding" ->"five possible rounding-direction attributes (the corresponding named constant for the rounding mode in IEEE_ARITHMETIC appears after the attribute name in parentheses)". {That's what 60559 specifies. We could establish the correspondence between the 60559 attribute names and the IEEE_ARITHMETIC named constants in a separate table or a separate sentence or two, but listing them in parentheses seems adequate.} [451:5] same paragraph, first bullet, "IEEE_NEAREST" -> "roundTiesToEven (IEEE_NEAREST)", after "nearest representable value" insert ", choosing the one with the even least significant bit if there are two such values". [451:6] same paragraph, second bullet, "IEEE_TO_ZERO" -> "roundTowardZero (IEEE_TO_ZERO)". [451:7] same paragraph, third bullet, "IEEE_UP" -> "roundTowardPositive (IEEE_UP)". [451:8] same paragraph, fourth bullet, "IEEE_DOWN" -> "roundTowardNegative (IEEE_DOWN)". [451:9] same paragraph, fifth bullet (IEEE_AWAY) replace entirely with "roundTiesToAway (IEEE_AWAY) rounds the exact result to the nearest representable value, choosing the one with larger magnitude if there are two such values". [451:9+] same paragraph after the bullet list, append sentence "ISO/IEC/IEEE 60559:2011 requires support for roundTiesToAway only for decimal floating-point; it is optional for binary floating-point." {This reads slightly better as a separate sentence.} Making the whole paragraph read (infinity signs replaced by "Inf"): "ISO/IEC/IEEE 60559:2011 specifies five possible rounding-direction attributes (the corresponding named constant for the rounding mode in IEEE_ARITHMETIC appears after the attribute name in parentheses): - roundTiesToEven (IEEE_NEAREST) rounds the exact result to the nearest representable value, choosing the one with the even least significant bit if there are two such values; - roundTowardZero (IEEE_TO_ZERO) rounds the exact result towards zero to the next representable value; - roundTowardPositive (IEEE_UP) rounds the exact result towards +Inf to the next representable value; - roundTowardNegative (IEEE_DOWN) rounds the exact result towards -Inf to the next representable value; - roundTiesToAway (IEEE_AWAY) rounds the exact result away from zero to the next representable value. ISO/IEC/IEEE 60559:2011 requires support for roundTiesToAway only for decimal floating-point; it is optional for binary floating-point." ===END===