com.hedgehog.types
Class HDouble

java.lang.Object
  extended by com.hedgehog.types.HDouble
All Implemented Interfaces:
java.lang.Comparable<HDouble>, java.util.Comparator

public class HDouble
extends java.lang.Object
implements java.util.Comparator, java.lang.Comparable<HDouble>

Title: HDouble - wrapper around type double.

Description: Wrapper for double. Provides additional functionality, lacking in Double.

Copyright: Copyright (c) Hedgehog Software 2007-2009.

Company: Hedgehog Software

Since:
1.0
Version:
1.1

Field Summary
static int MAX_EXPONENT
          Maximum exponent a double may have; ie 1,023.
static double MAX_VALUE
          Maximum double value; ie // 1.8e+308.
static int MIN_EXPONENT
          Minimum exponent a double may have; ie -1022.
static double MIN_VALUE
          Minimum double value; ie 4.9e-324.
static double NaN
          Not-a-Number (NaN), equivalent to Double.longBitsToDouble(0x7ff8000000000000L).
 
Constructor Summary
HDouble()
          Default constructor.
HDouble(double d)
          Constructor.
HDouble(java.lang.Double d)
          Constructor.
HDouble(HDouble object)
          Copy constructor.
HDouble(java.lang.String d)
          Constructor.
 
Method Summary
 HDouble abs()
          Returns the absolute value of this double value.
static HDouble add(HDouble d1, double d2)
          Addition.
static HDouble add(HDouble d1, java.lang.Double d2)
          Addition.
static HDouble add(HDouble d1, HDouble d2)
          Addition.
 void addTo(double d)
          Arithmetic addition.
 void addTo(java.lang.Double d)
          Arithmetic addition.
 void addTo(HDouble d)
          Arithmetic addition.
 HDouble ceil()
          Returns the smallest value that is greater than or equal to this value and is equal to a mathematical integer.
 java.lang.Object clone()
          Returns a clone of this object.
 int compare(java.lang.Object obj1, java.lang.Object obj2)
          Overrides the Comparator.compare() method
 int compareTo(HDouble obj)
          Overrides the Comparable.compareTo() method
 HDouble cosine()
          Returns the cosine of this value.
 void divide(double d)
          Divides the value by the specified double d.
 void divide(java.lang.Double d)
          Divides the value by the specified Double d.
 void divide(HDouble d)
          Divides the value by the specified HDouble d.
static HDouble divide(HDouble d1, double d2)
          Divides the HDouble d1 by double d2.
static HDouble divide(HDouble d1, java.lang.Double d2)
          Divides the HDouble d1 by Double d2.
static HDouble divide(HDouble d1, HDouble d2)
          Divides the HDouble d1 by HDouble d2.
 boolean equals(java.lang.Object obj)
          Overrides the Comparator.equals() method.
 boolean equals(java.lang.Object obj, double tolerance)
          Compares the specified object with this object.
 HDouble exp()
          Returns the exponential value of this value.
 void flipSign()
          Flips the sign of this value.
 HDouble floor()
          Returns the largest value that is less than or equal to the argument and is equal to a mathematical integer.
 double getValue()
          Returns this object's value.
 boolean greaterThan(HDouble obj)
          Tests whether or not this value is greater than the specified value.
 boolean greaterThanOrEqualTo(HDouble obj)
          Tests whether or not this value is greater than or equal to the specified value.
 int hashCode()
          Returns the hashcode of this HDouble object.
 HBoolean isNegative()
          Tests whether or not this value is negative.
 HBoolean isPositive()
          Tests whether or not this value is positive.
 HBoolean isZero(double tolerance)
          Tests whether or not this value is zero.
 boolean lessThan(HDouble obj)
          Tests whether or not this value is less than the specified value.
 boolean lessThanOrEqualTo(HDouble obj)
          Tests whether or not this value is less than or equal to the specified value.
 HDouble log()
          Returns the natural logarithm of this value.
static HDouble multiply(HDouble d1, double d2)
          Multiplication.
static HDouble multiply(HDouble d1, java.lang.Double d2)
          Multiplication.
static HDouble multiply(HDouble d1, HDouble d2)
          Multiplication.
 void multiplyBy(double d)
          Multiplies this value by the specified value.
 void multiplyBy(java.lang.Double d)
          Multiplies this value by the specified value.
 void multiplyBy(HDouble d)
          Multiplies this value by the specified value.
 boolean sameValue(HDouble object, double tolerance)
          Tests whether or not the specified object has the same value as this object, within the specified tolerance.
 void setValue(double newD)
          Sets this object's value.
 void setValue(java.lang.Double newD)
          Sets this object's value.
 void setValue(HDouble newD)
          Sets this object's value.
 HDouble sine()
          Returns the sine of this value.
 HDouble sqrt()
          Returns the sine of this value.
 void subtract(double d)
          Subtracts the specified scalar value from this value.
 void subtract(java.lang.Double d)
          Subtracts the specified scalar value from this value.
 void subtract(HDouble d)
          Subtracts the specified scalar value from this value.
static HDouble subtract(HDouble d1, double d2)
          Subtraction.
static HDouble subtract(HDouble d1, java.lang.Double d2)
          Subtraction.
static HDouble subtract(HDouble d1, HDouble d2)
          Subtraction.
 HDouble tan()
          Returns the tangent of this value.
 java.lang.Double toDouble()
          Returns a Double equivalent of this object.
 java.lang.String toString()
          Returns a String representation of a HDouble object.
 java.lang.String toStringFormat2()
          Returns a formatted String representation of this HDouble object, formatting the number with two decimal places.
 java.lang.String toStringFormat3()
          Returns a formatted String representation of this HDouble object, formatting the number with three decimal places.
 java.lang.String toStringFormat4()
          Returns a formatted String representation of this HDouble object, formatting the number with four decimal places.
 java.lang.String toStringFormatE2()
          Returns a formatted String representation of this HDouble object, formatting the number with two decimal places using scientific notation.
 java.lang.String toStringFormatE3()
          Returns a formatted String representation of this HDouble object, formatting the number with three decimal places using scientific notation.
 java.lang.String toStringFormatE4()
          Returns a formatted String representation of this HDouble object, formatting the number with four decimal places using scientific notation.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MIN_VALUE

public static final double MIN_VALUE
Minimum double value; ie 4.9e-324.

See Also:
Constant Field Values

MAX_VALUE

public static final double MAX_VALUE
Maximum double value; ie // 1.8e+308.

See Also:
Constant Field Values

MAX_EXPONENT

public static final int MAX_EXPONENT
Maximum exponent a double may have; ie 1,023.

See Also:
Constant Field Values

MIN_EXPONENT

public static final int MIN_EXPONENT
Minimum exponent a double may have; ie -1022.

See Also:
Constant Field Values

NaN

public static final double NaN
Not-a-Number (NaN), equivalent to Double.longBitsToDouble(0x7ff8000000000000L).

See Also:
Constant Field Values
Constructor Detail

HDouble

public HDouble()
Default constructor. Sets the value to 0.0.


HDouble

public HDouble(double d)
Constructor. Sets the value to the specified value.

Parameters:
d - Value of type double.

HDouble

public HDouble(java.lang.Double d)
Constructor. Sets the value to the specified value.

Parameters:
d - Value of type Double.

HDouble

public HDouble(java.lang.String d)
Constructor. Sets the value to the specified value.

Parameters:
d - Value of type String.

HDouble

public HDouble(HDouble object)
Copy constructor.

Parameters:
object - Object to copy.
Method Detail

abs

public HDouble abs()
Returns the absolute value of this double value.

Returns:
Absolute value.

addTo

public void addTo(double d)
Arithmetic addition.

Parameters:
d - double number to add.

addTo

public void addTo(HDouble d)
Arithmetic addition.

Parameters:
d - HDouble number to add.

addTo

public void addTo(java.lang.Double d)
Arithmetic addition.

Parameters:
d - Double number to add.

add

public static HDouble add(HDouble d1,
                          HDouble d2)
Addition.

Parameters:
d1 - First HDouble operand.
d2 - Second HDouble operand.
Returns:
The sum of the two operands.

add

public static HDouble add(HDouble d1,
                          java.lang.Double d2)
Addition.

Parameters:
d1 - First HDouble operand.
d2 - Second Double operand.
Returns:
The sum of the two operands.

add

public static HDouble add(HDouble d1,
                          double d2)
Addition.

Parameters:
d1 - First HDouble operand.
d2 - Second double operand.
Returns:
The sum of the two operands.

clone

public java.lang.Object clone()
Returns a clone of this object. Simply calls the copy constructor.

Overrides:
clone in class java.lang.Object
Returns:
A colone of this object.

ceil

public HDouble ceil()
Returns the smallest value that is greater than or equal to this value and is equal to a mathematical integer.

Returns:
Ceil value.

floor

public HDouble floor()
Returns the largest value that is less than or equal to the argument and is equal to a mathematical integer.

Returns:
Floor value.

flipSign

public void flipSign()
Flips the sign of this value.


compare

public int compare(java.lang.Object obj1,
                   java.lang.Object obj2)
Overrides the Comparator.compare() method

Specified by:
compare in interface java.util.Comparator
Parameters:
obj1 - Object 1.
obj2 - Object 2.
Returns:
0 if obj1==obj2, -1 if obj1obj2.

compareTo

public int compareTo(HDouble obj)
Overrides the Comparable.compareTo() method

Specified by:
compareTo in interface java.lang.Comparable<HDouble>
Parameters:
obj - Object to compare against this object.
Returns:
0 if this==obj, -1 if thisobj.

lessThan

public boolean lessThan(HDouble obj)
Tests whether or not this value is less than the specified value.

Parameters:
obj - Object to compare.
Returns:
Logical-true if this value is less than the specified value, else logical-false.

greaterThan

public boolean greaterThan(HDouble obj)
Tests whether or not this value is greater than the specified value.

Parameters:
obj - Object to compare.
Returns:
Logical-true if this value is greater than the specified value, else logical-false.

lessThanOrEqualTo

public boolean lessThanOrEqualTo(HDouble obj)
Tests whether or not this value is less than or equal to the specified value.

Parameters:
obj - Object to compare.
Returns:
Logical-true if this value is less than or equal to the specified value, else logical-false.

greaterThanOrEqualTo

public boolean greaterThanOrEqualTo(HDouble obj)
Tests whether or not this value is greater than or equal to the specified value.

Parameters:
obj - Object to compare.
Returns:
Logical-true if this value is greater than or equal to the specified value, else logical-false.

cosine

public HDouble cosine()
Returns the cosine of this value. Ensure that the value is in radians.

Returns:
Cosine of this value.

equals

public boolean equals(java.lang.Object obj,
                      double tolerance)
Compares the specified object with this object.

Parameters:
obj - Object to compare with invoking object.
tolerance - Required tolerance.
Returns:
Logical-true if obj==invoking object within the specified tolerance.

equals

public boolean equals(java.lang.Object obj)
Overrides the Comparator.equals() method.

Specified by:
equals in interface java.util.Comparator
Overrides:
equals in class java.lang.Object
Parameters:
obj - Object to compare with invoking object.
Returns:
Logical-true if obj==invoking object within Tolerances.TOLERANCE.

hashCode

public int hashCode()
Returns the hashcode of this HDouble object. Uses the same method as Java's Double object for calculating the hash code.

Overrides:
hashCode in class java.lang.Object
Returns:
This object's hash code.

exp

public HDouble exp()
Returns the exponential value of this value.

Returns:
The exponential.

divide

public void divide(double d)
Divides the value by the specified double d.

Parameters:
d - Divisor.

divide

public void divide(HDouble d)
Divides the value by the specified HDouble d.

Parameters:
d - Divisor.

divide

public void divide(java.lang.Double d)
Divides the value by the specified Double d.

Parameters:
d - Divisor.

divide

public static HDouble divide(HDouble d1,
                             HDouble d2)
Divides the HDouble d1 by HDouble d2.

Parameters:
d1 - Numerator.
d2 - Denomanator.
Returns:
d1/d2 provided abs(d2)>Tolerances.ZERO. If d2>0 and d2 < Tolerances.ZERO then Double.POSITIVE_INFINITY is returned. If d2<0 && abs(d2) < Tolerances.ZERO then Double.NEGATIVE_INFINITY is returned.

divide

public static HDouble divide(HDouble d1,
                             double d2)
Divides the HDouble d1 by double d2.

Parameters:
d1 - Numerator.
d2 - Denomanator.
Returns:
d1/d2 provided abs(d2)>Tolerances.ZERO. If d2>0 and d2 < Tolerances.ZERO then Double.POSITIVE_INFINITY is returned. If d2<0 && abs(d2) < Tolerances.ZERO then Double.NEGATIVE_INFINITY is returned.

divide

public static HDouble divide(HDouble d1,
                             java.lang.Double d2)
Divides the HDouble d1 by Double d2.

Parameters:
d1 - Numerator.
d2 - Denomanator.
Returns:
d1/d2 provided abs(d2)>Tolerances.ZERO. If d2>0 and d2 < Tolerances.ZERO then Double.POSITIVE_INFINITY is returned. If d2<0 && abs(d2) < Tolerances.ZERO then Double.NEGATIVE_INFINITY is returned.

getValue

public double getValue()
Returns this object's value.

Returns:
This object's value.

isPositive

public HBoolean isPositive()
Tests whether or not this value is positive.

Returns:
Logical-true if this value is greater than zero, else logical-false.

isNegative

public HBoolean isNegative()
Tests whether or not this value is negative.

Returns:
Logical-true if this value is less than zero, else logical-false.

isZero

public HBoolean isZero(double tolerance)
Tests whether or not this value is zero.

Parameters:
tolerance - Required tolerance.
Returns:
Logical-true if this value is zero, else logical-false.

log

public HDouble log()
Returns the natural logarithm of this value.

Returns:
The natural logarithm of this value.

multiplyBy

public void multiplyBy(double d)
Multiplies this value by the specified value.

Parameters:
d - Scalar floaitng-point value.

multiplyBy

public void multiplyBy(HDouble d)
Multiplies this value by the specified value.

Parameters:
d - HDouble object.

multiplyBy

public void multiplyBy(java.lang.Double d)
Multiplies this value by the specified value.

Parameters:
d - Java Double object.

multiply

public static HDouble multiply(HDouble d1,
                               HDouble d2)
Multiplication.

Parameters:
d1 - First HDouble operand.
d2 - Second HDouble operand.
Returns:
The multiplication of the two operands.

multiply

public static HDouble multiply(HDouble d1,
                               java.lang.Double d2)
Multiplication.

Parameters:
d1 - First HDouble operand.
d2 - Second Double operand.
Returns:
The multiplication of the two operands.

multiply

public static HDouble multiply(HDouble d1,
                               double d2)
Multiplication.

Parameters:
d1 - First HDouble operand.
d2 - Second double operand.
Returns:
The sum of the two operands.

sameValue

public boolean sameValue(HDouble object,
                         double tolerance)
Tests whether or not the specified object has the same value as this object, within the specified tolerance.

Parameters:
object - Object to compare.
tolerance - Required tolerance.
Returns:
Logical-true if the specified object has the same value as this object, else logical-false.

setValue

public void setValue(double newD)
Sets this object's value.

Parameters:
newD - New value.

setValue

public void setValue(HDouble newD)
Sets this object's value.

Parameters:
newD - New value.

setValue

public void setValue(java.lang.Double newD)
Sets this object's value.

Parameters:
newD - New value.

sine

public HDouble sine()
Returns the sine of this value. Ensure that the value is in radians.

Returns:
The sine of this value.

sqrt

public HDouble sqrt()
Returns the sine of this value. Ensure that the value is in radians.

Returns:
The sine of this value.

subtract

public void subtract(double d)
Subtracts the specified scalar value from this value.

Parameters:
d - Value to subtract.

subtract

public void subtract(HDouble d)
Subtracts the specified scalar value from this value.

Parameters:
d - Value to subtract.

subtract

public void subtract(java.lang.Double d)
Subtracts the specified scalar value from this value.

Parameters:
d - Value to subtract.

subtract

public static HDouble subtract(HDouble d1,
                               HDouble d2)
Subtraction.

Parameters:
d1 - First HDouble operand.
d2 - Second HDouble operand.
Returns:
The subtraction of the two operands.

subtract

public static HDouble subtract(HDouble d1,
                               java.lang.Double d2)
Subtraction.

Parameters:
d1 - First HDouble operand.
d2 - Second Double operand.
Returns:
The subtraction of the two operands.

subtract

public static HDouble subtract(HDouble d1,
                               double d2)
Subtraction.

Parameters:
d1 - First HDouble operand.
d2 - Second double operand.
Returns:
The subtraction of the two operands.

tan

public HDouble tan()
Returns the tangent of this value. Ensure that the value is in radians.

Returns:
The tangent of this value.

toDouble

public java.lang.Double toDouble()
Returns a Double equivalent of this object.

Returns:
A Double equivalent of this object.

toString

public java.lang.String toString()
Returns a String representation of a HDouble object.

Overrides:
toString in class java.lang.Object
Returns:
A string representation of a HDouble object.

toStringFormat2

public java.lang.String toStringFormat2()
Returns a formatted String representation of this HDouble object, formatting the number with two decimal places.

Returns:
A formatted string representation of a HDouble object.

toStringFormat3

public java.lang.String toStringFormat3()
Returns a formatted String representation of this HDouble object, formatting the number with three decimal places.

Returns:
A formatted string representation of a HDouble object.

toStringFormat4

public java.lang.String toStringFormat4()
Returns a formatted String representation of this HDouble object, formatting the number with four decimal places.

Returns:
A formatted string representation of a HDouble object.

toStringFormatE2

public java.lang.String toStringFormatE2()
Returns a formatted String representation of this HDouble object, formatting the number with two decimal places using scientific notation.

Returns:
A formatted string representation of a HDouble object.

toStringFormatE3

public java.lang.String toStringFormatE3()
Returns a formatted String representation of this HDouble object, formatting the number with three decimal places using scientific notation.

Returns:
A formatted string representation of a HDouble object.

toStringFormatE4

public java.lang.String toStringFormatE4()
Returns a formatted String representation of this HDouble object, formatting the number with four decimal places using scientific notation.

Returns:
A formatted string representation of a HDouble object.