net.sf.jagg
Class DoubleDouble

java.lang.Object
  extended by net.sf.jagg.DoubleDouble
All Implemented Interfaces:
java.lang.Comparable<DoubleDouble>

public class DoubleDouble
extends java.lang.Object
implements java.lang.Comparable<DoubleDouble>

A DoubleDouble is used when extra precision is necessary to cut way down on floating point errors.

Since:
0.4.0
Author:
Randy Gettman

Field Summary
static DoubleDouble NaN
          The DoubleDouble NaN (Not a Number), immutable.
static DoubleDouble ZERO
          The DoubleDouble zero, immutable.
 
Constructor Summary
DoubleDouble()
          Create a DoubleDouble, initialized to zero.
DoubleDouble(double d)
          Create a DoubleDouble from a double.
DoubleDouble(DoubleDouble dd)
          Copy constructor.
DoubleDouble(double hi, double lo)
          Create a DoubleDouble from high and low parts.
 
Method Summary
 void addToSelf(double d)
          Adds a double to this.
 void addToSelf(DoubleDouble dd)
          Adds another DoubleDouble to this one.
 int compareTo(DoubleDouble other)
          Returns an integer less than zero, equal to zero, or greater than zero, depending on whether this compares less than, equal to, or greather than another DoubleDouble.
 void divideSelfBy(double d)
          Divides self by a double.
 void divideSelfBy(DoubleDouble dd)
          Divides self by a DoubleDouble.
 double doubleValue()
          Returns the double that is closest in value to this DoubleDouble.
 double getLow()
          Returns the low-order portion of this DoubleDouble.
 boolean isNaN()
          Returns whether this DoubleDouble is NaN.
 void multiplySelfBy(double d)
          Multiplies self by a double.
 void multiplySelfBy(DoubleDouble dd)
          Multiplies self by another DoubleDouble.
 void negateSelf()
          Negate each part.
 void nthRootSelf(long n)
          Takes the nth root of self.
 void powSelf(long exponent)
          Raise self to an integer exponent.
 void reset()
          Sets this DoubleDouble equal to zero.
 void sqrtSelf()
          Takes the square root of self.
 void squareSelf()
          Squares self.
 void subtractFromSelf(double d)
          Subtracts a double from this.
 void subtractFromSelf(DoubleDouble dd)
          Subtracts another DoubleDouble from this one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NaN

public static final DoubleDouble NaN
The DoubleDouble NaN (Not a Number), immutable.


ZERO

public static final DoubleDouble ZERO
The DoubleDouble zero, immutable.

Constructor Detail

DoubleDouble

public DoubleDouble()
Create a DoubleDouble, initialized to zero.


DoubleDouble

public DoubleDouble(double d)
Create a DoubleDouble from a double.

Parameters:
d - A double.

DoubleDouble

public DoubleDouble(double hi,
                    double lo)
Create a DoubleDouble from high and low parts.

Parameters:
hi - The high-order part.
lo - The low-order part.

DoubleDouble

public DoubleDouble(DoubleDouble dd)
Copy constructor.

Parameters:
dd - Another DoubleDouble.
Method Detail

reset

public void reset()
Sets this DoubleDouble equal to zero.


doubleValue

public double doubleValue()
Returns the double that is closest in value to this DoubleDouble.

Returns:
A double (the high portion of this DoubleDouble).

getLow

public double getLow()
Returns the low-order portion of this DoubleDouble.

Returns:
The low-order portion of this DoubleDouble.

isNaN

public boolean isNaN()
Returns whether this DoubleDouble is NaN.

Returns:
Whether this DoubleDouble is NaN.

addToSelf

public void addToSelf(DoubleDouble dd)
Adds another DoubleDouble to this one.

Parameters:
dd - Another DoubleDouble.

addToSelf

public void addToSelf(double d)
Adds a double to this. Algorithm is based on "Algorithms for Quad-Double Precision Floating Point Arithmetic" by Hida, Li, and Bailey, 2000, Berkeley.

Parameters:
d - A double.

subtractFromSelf

public void subtractFromSelf(DoubleDouble dd)
Subtracts another DoubleDouble from this one.

Parameters:
dd - Another DoubleDouble.

subtractFromSelf

public void subtractFromSelf(double d)
Subtracts a double from this.

Parameters:
d - A double.

negateSelf

public void negateSelf()
Negate each part. NaNs aren't negated (or negatable). The negation of NaN is NaN.


multiplySelfBy

public void multiplySelfBy(DoubleDouble dd)
Multiplies self by another DoubleDouble.

Parameters:
dd - Another DoubleDouble.

multiplySelfBy

public void multiplySelfBy(double d)
Multiplies self by a double.

Parameters:
d - A double.

squareSelf

public void squareSelf()
Squares self.


divideSelfBy

public void divideSelfBy(DoubleDouble dd)
Divides self by a DoubleDouble.

Parameters:
dd - Another DoubleDouble.

divideSelfBy

public void divideSelfBy(double d)
Divides self by a double.

Parameters:
d - A double.

sqrtSelf

public void sqrtSelf()
Takes the square root of self.


powSelf

public void powSelf(long exponent)
Raise self to an integer exponent.

Parameters:
exponent - The exponent.

nthRootSelf

public void nthRootSelf(long n)
Takes the nth root of self.

Parameters:
n - The root.

compareTo

public int compareTo(DoubleDouble other)
Returns an integer less than zero, equal to zero, or greater than zero, depending on whether this compares less than, equal to, or greather than another DoubleDouble.

Specified by:
compareTo in interface java.lang.Comparable<DoubleDouble>
Parameters:
other - Another DoubleDouble.
Returns:
An integer less than zero, equal to zero, or greater than zero, depending on whether this compares less than, equal to, or greather than another DoubleDouble.


Copyright © 2010-2013 jAgg Team. All Rights Reserved.