4
$\begingroup$

Are there any instances of scientific numerical problems where the choice of rounding mode matters?

There are usually a number of different rounding modes available: to $0$, away from $0$, to $\pm\infty$, nearest ties to even, nearest ties down. Apart from various currency-manipulation problems where rounding is mandated by problem details, does anyone know an example of where choice of rounding mode might actually matter?

A numerically stable algorithm would be insensitive to round-off errors and hence to choice of rounding mode, but are there any other issues that might be relevant?

$\endgroup$

2 Answers 2

4
$\begingroup$

Using the rounding modes, it's possible to implement interval arithmetic.

Suppose that two positive quantities $x$ and $y$ are represented by the intervals $[x_l,x_u]$ and $[y_l,y_u]$. The product is represented in interval arithmetic by $[x_l \otimes y_l, x_u \otimes y_u]$, where $x_l\otimes y_l$ should be rounded down and $x_u\otimes y_u$ should be rounded up. Control over rounding modes makes it easy to do this.

Varying the rounding mode and rerunning your code is also a quick test of your algorithm- if the answers change a lot then you know that the algorithm is quite sensitive to round-off errors (and that you probably need to rewrite it!)

$\endgroup$
4
  • $\begingroup$ Interval arithmetic did not occur to me. Would you mind expanding your answer a little bit? $\endgroup$
    – Kirill
    Commented Nov 3, 2014 at 20:19
  • $\begingroup$ What other details would you be interested in knowing? $\endgroup$
    – boyfarrell
    Commented Nov 3, 2014 at 22:00
  • $\begingroup$ Suppose that two positive quantities x and y are represented by the intervals [xl,xu] and [yl,yu]. The product is represented in interval arithmetic by [product(xl,yl),product(xu,yu)], where product(xl,yl) should be rounded down and product(xu,yu) should be rounded up. Control over rounding modes makes it easy to do this. $\endgroup$ Commented Nov 4, 2014 at 1:35
  • $\begingroup$ The Wikipedia article on interval arithmetic that I linked to discusses how IEEE rounding modes can be used in implementing interval arithmetic. $\endgroup$ Commented Nov 4, 2014 at 1:43
0
$\begingroup$

The choice of rounding mode is governed by IEEE standards--Ref [1] mentions IEEE 754 and IEEE 854. Without the standards, one could find different results when porting code from one machine to another (see Goldberg [1]). Portability would be important if you want to be check if the different answer you get on another machine is due to a bug versus due to differences in implementation. The article also gives examples such as $x^2-y^2$ being more accurate than $(x+y)(x-y)$ when $x>>y$ or $y<<x$. In such cases, rounding error may become more important. As for compiler support, an example is the C99 standard which supports IEEE floating point arithmetic.

Note: some situations call for something more rigorous than rounding modes--these are problems involving the use of "arbitrary precision arithmetic. In the Wikipedia article on the topic, a number of applications are given, as well as appropriate libraries.

Reference:

[1] David Goldberg, "What every computer scientist should know about floating-point arithmetic", ACM Computing Surveys (CSUR), 23(1), 5-48, 1991. See http://dl.acm.org/ft_gateway.cfm?id=103163&type=pdf.

$\endgroup$
2
  • $\begingroup$ "is governed by an IEEE standard" I think it's worth saying that the C++ standard doesn't specify any floating-point arithmetic standard, so the only guarantee comes knowing what hardware one executes the programs on. $\endgroup$
    – Kirill
    Commented Nov 4, 2014 at 4:13
  • $\begingroup$ to answer your question, I've made an edit mentioning the C99 standard which has IEEE support. A compiler that supports this standard would allow one to implement the standard in software even if it's not available in hardware. $\endgroup$ Commented Nov 4, 2014 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.