```"Kent Dahl" <kentda / stud.ntnu.no> wrote in message
news:3B6461A6.65BE8F26 / stud.ntnu.no...

> > I'd like Rationals in Ruby, but a few divisions can run into huge
> > BixNums for denominator and whatstheothercalled. That can be an
> > unexpected speed slowdown. Guess you'd get:

A different pretty cool number class is interval arithmetic.
Given the topic of the discussion I thought I'd mention it.
Interval arithmetic is not just a gimmick. It is possible to do exact
calculations and reason about the accuracy of the result.

Sun has been doing a lot of work in this area. If I recall correctly they
have Java and C++ implementations.
Interval arithmetic is more precise than float arithmetic.
In reality float values belong to the class of rational numbers and cannot
represent all real values, even within its valuerange.

A value in intervalarithmetic is [lowerboundvalue, upperboundvalue].
If you are sure about the value, this could be [5, 5]. The you devid by [2,
2]
This yields [2, 3]. That is, the value is within the range 2 and 3. In this
case the exact value is 5/2 or 2.5. But remember that rational numbers
cannot represent all values - like pi for instance.
You can also use interval arithmetic with float values: [2.999, 3.0], or
rationals:
pi is_in [3/1, 22/7]

Interval arithmetic is not particularly fast, but it is sometimes used in
optimization problems where it can be rather fast, because the algorithms
can make 100% exact decisions:
[2.85, 2.99] is guaranteed to be different from [2.999, 3.0].

A variant of interval numbers is based on rational numbers:
([5, 5], 2) is 5/2. pi is_in [3, 22/7] = [21/7, 22/7] = ([21,22], 7)

Another variant is [lowerbound, delta]. Each representationmakes some
operations easier and others more difficult.

BigInts can take up a lot of space, Interval arithmetic can be used to only
store as many digits as makes sense with the given precision by using
lowerbound, upperbound and a scale.

Mikkel

```