JADE v6.1

Package com.dautelle.math.numbers

Provides common types of numbers (operable and real-time compliant).

See:
          Description

Class Summary
Complex This class represents an immutable complex number.
Complex.Value This inner class represents a mutable image of an immutable Complex.
Float32 This class represents a 32 bits floating point number.
Float32.Value This inner class represents a mutable image of an immutable Float32.
Float64 This class represents a 64 bits floating point number.
Float64.Value This inner class represents a mutable image of an immutable Float64.
Integer32 This class represents a 32 bits signed integer.
Integer32.Value This inner class represents a mutable image of an immutable Integer32.
Integer64 This class represents a 64 bits signed integer.
Integer64.Value This inner class represents a mutable image of an immutable Integer64.
LargeInteger This class represents an immutable integer number of arbitrary size.
LargeInteger.Value This inner class represents a mutable image of an immutable LargeInteger.
Rational This class represents the ratio of two LargeInteger numbers.
Rational.Value This inner class represents a mutable image of an immutable Rational.
Real This class represents a real number of arbitrary precision with known/guaranteed uncertainty.
Real.Value This inner class represents a mutable image of an immutable Real.
RealtimeNumber This class provides a default implementation of the Realtime interface for objects of type java.lang.Number.
RealtimeNumber.Factory This abstract class represents the factory responsible for the creation of RealtimeNumber instances.
 

Package com.dautelle.math.numbers Description

Provides common types of numbers (operable and real-time compliant).

Although numbers defined in this package are not as fast as primitives types (e.g. int or double). They have many advantages (such as arbitrary size for LargeInteger or precision for Real) which make them irreplaceable in some calculations. This can be illustrated with the following example:

        double x = 10864;
        double y = 18817;
        double z = 9 * Math.pow(x, 4.0)- Math.pow(y, 4.0) + 2 * Math.pow(y, 2.0);
        System.out.println("Result : " + z);

        > Result : 2.0
The mathematically correct value is z=1. However, Java compilers using ANSI/IEEE double precision numbers evaluate z=2. Not even the first digit is correct! This is due to a rounding error occurring when subtracting two nearly equal floating point numbers. Now, lets write the same formula using Real numbers:
        Real.setIntegerAccuracy(20); // 20 digits accuracy for integer values.
        Real x = Real.valueOf(10864);
        Real y = Real.valueOf(18817);
        Real z = (Real) Real.valueOf(9).times(x.pow(4)).plus(y.pow(4).opposite()).plus(Real.valueOf(2).times(y.pow(2)));
        System.out.println("Result : " + z);

        > Result   : 1.000
Not only the correct result is returned, but this result is also guaranteed to be 1 ± 0.001 (only exact digits are written out).


JADE v6.1

Copyright © 2004 Jean-Marie Dautelle.