next up previous contents index
Next: 4.9 Interval Projected Polyhedron Up: 4.8 Rounded interval arithmetic Previous: 4.8.4 Hardware rounding for   Contents   Index

4.8.5 Implementation of rounded interval arithmetic

For implementational simplicity when switching between $ ulp$ rounding and hardware rounding, we have developed a C++ class (shown in fragmentary form below) for interval numbers operating in floating point numbers [4]:

class Interval {
private:
double low; // lower bound of interval
double upp; // upper bound of interval
public:
Interval() { low = upp = 0.0; } // class constructors

friend Interval add(Interval, Interval, Interval &);
// utility function
};
Interval operator + (Interval a, Interval b)
// overloaded addition operator
{
Interval c;
add(a, b, c); // call appropriate utility function
return c; // return sum of a and b
}
Software rounding using the $ ulp$ is implemented by overloading the arithmetic operators as shown in the following example for addition:

    Interval add(Interval a, Interval b, Interval &c)
    {
      double low = a.low + b.low;  // calculate the lower bound
      double upp = a.upp + b.upp;  // calculate the upper bound

      c.low = low - ulp(low);      // extend the lower bound by ulp
      c.upp = upp + ulp(upp);      // extend the upper bound by ulp
    }
where $ ulp()$ is the function described previously for calculating the $ ulp$ .

Hardware rounding is implemented by overloading the arithmetic operators as follows:

  Interval add(Interval a, Interval b, Interval &c)
  {
    swapRM(ROUND_TO_MINUS_INFINITY); // set round to -infinity mode
    c.low = a.low + b.low;           // calculate the lower bound
    swapRM(ROUND_TO_PLUS_INFINITY);  // set round to +infinity mode
    c.upp = a.upp + b.upp;           // calculate the upper bound
  }
where $ swapRM()$ is the SGI-specific function for setting the IEEE-754 rounding mode. (Although requiring the implementation of the four rounding modes, the standard does not specify the mechanism by which the modes are set.)

The software rounding method is computationally more expensive than hardware rounding, requiring an extra addition and subtraction and the computation of the $ ulp$ of two values. Note that the software rounding method extends the upper and lower bounds of the interval during every arithmetic operation; the hardware rounding method only extends the bounds when the result of the operation cannot be exactly represented, producing tighter interval bounds. Thus, the relationship between an infinite precision value $ x$ and its interval under $ ulp$ rounding is $ x_\ell < x < x_u$ , while for hardware rounding it is $ x_\ell \leq x
\leq x_u$ .


next up previous contents index
Next: 4.9 Interval Projected Polyhedron Up: 4.8 Rounded interval arithmetic Previous: 4.8.4 Hardware rounding for   Contents   Index
December 2009