0
votes

I know that IEEE 754 is the specification for floating-point number data types, their representation and the semantics of operations on them; but - I'm not knowledgeable in the standard itself.

I also know that IEEE 754 defines the following four rounding modes: to nearest, up, down, to zero; and that in typical environments supporting IEEE 754 you can say "please round x using rounding mode m" (e.g. here's how it's done with glibc). That's all well and good.

However, rounding also happens when you simply perform arithmetic: If you have a single-precision 0.9999999 (or something close to that) and you add this to 100000, you will either get 100001, or something close to 100000.99 .

My question: Is this rounding supposed to be an application of a "default rounding mode"? Is that the IEEE 754 term, or is there another, specific term for what I've described? And are the four rounding modes supposed to be supported for implicit rounding arithmetic, as well?

1
afaict, that's not rounding, but an artifact of the imprecise representation of values like 0.9999999 - see stackoverflow.com/questions/588004/… for an explanation of the behaviour of such floatsGereon
@Gereon: Isn't automatic rounding an "artifact of imprecise representation"? Anyway, I won't split hairs, I just want to know how the choice of "rounding" mode is made for these ops.einpoklum
@Gereon: Converting the text numeral “0.9999999” to a floating-point number is an operation specified by IEEE 754 and is affected by rounding. However, I do not believe that passage in the question is asking about that conversion; it uses “0.9999999 (or something close to that)” as a proxy for some specific floating-point number that the author did not know the exact value of, and the question is about the operation of adding that number to some other floating-point number.Eric Postpischil
Note: IEEE 754-2008 defines five rounding modes, not four: round-to-nearest-ties-to-even, round-to-nearest-ties-to-away (from zero), round toward zero, round toward −∞, and round toward +∞. The new round, round-to-nearest-ties-to-away, is useful for dealing with mixed-precision arithmetic, as it preserves a bit conveying information about what was lost in the rounding.Eric Postpischil

1 Answers

2
votes

IEEE 754-2008 does not define “modes” for rounding, and it does not define a default rounding attribute. Round-to-nearest-ties-to-even is commonly used as a default by many program languages, program language implementations, and other environments.

IEEE 754-2008 subclause 4.3 specifies several rounding-direction attributes. It does not say any of them is a default. It does not say there has to be a mode that provides a rounding-direction setting. A computing environment could, for example, including the rounding-direction attribute as a parameter on each individual operation. For example, a processor architecture could have separate instructions for add with rounding-to-nearest-ties-to-even, add with rounding toward +∞, add with rounding toward zero, and so on. Or it could include the rounding-direction attribute as a operand to the instruction. Or the instruction could be affected by a global mode set in some special processor register.

When there is a default mode in some computing environment, it is one established by that computing environment, not by IEEE 754-2008. Many processor architectures provide rounding mode as a setting in a floating-point control register.

The IEEE 754-1985 standard described rounding modes and defined mode as “A variable that a user may set, sense, save, and restore to control the execution of subsequent arithmetic operations.” This may have influenced the development of rounding modes in control registers, but that has a detrimental effect on performance, as global registers cause dependencies between instructions: Every floating-point instruction depends on that global register, so any change to that register interferes with parallel execution of instructions.

However, it is desirable that the rounding direction be flexible, as one might want to alternately use different modes when implementing interval arithmetic or evaluating complicated routines such as implementations of sine or exponentiation. So the IEEE 754-2008 committee changed the standard not to define global modes. Clause 4 specifies some semantics for attributes, including that languages should provide ways to specify the attributes for all standard operations in a “block.” A block may be an entire program or a single operation; it is language-defined. Subclause 4.2 says languages should provide dynamic ways of specifying the attributes, so they can be determined at run-time.