|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.vividsolutions.jts.algorithm.math.DoubleDouble
public class DoubleDouble
Immutable, extended-precision floating-point numbers which maintain 106 bits (approximately 30 decimal digits) of precision.
A DoubleDouble uses a representation containing two double-precision values. A number x is represented as a pair of doubles, x.hi and x.lo, such that the number represented by x is x.hi + x.lo, where
|x.lo| <= 0.5*ulp(x.hi)and ulp(y) means "unit in the last place of y". The basic arithmetic operations are implemented using convenient properties of IEEE-754 floating-point arithmetic.
The range of values which can be represented is the same as in IEEE-754. The precision of the representable numbers is twice as great as IEEE-754 double precision.
The correctness of the arithmetic algorithms relies on operations being performed with standard IEEE-754 double precision and rounding. This is the Java standard arithmetic model, but for performance reasons Java implementations are not constrained to using this standard by default. Some processors (notably the Intel Pentium architecure) perform floating point operations in (non-IEEE-754-standard) extended-precision. A JVM implementation may choose to use the non-standard extended-precision as its default arithmetic mode. To prevent this from happening, this code uses the Java strictfp modifier, which forces all operations to take place in the standard IEEE-754 rounding model.
The API provides a value-oriented interface. DoubleDouble values are immutable; operations on them return new objects carrying the result of the operation. This provides a much simpler semantics for writing DoubleDouble expressions, and Java memory management is efficient enough that this imposes very little performance penalty.
This implementation uses algorithms originally designed variously by Knuth, Kahan, Dekker, and Linnainmaa. Douglas Priest developed the first C implementation of these techniques. Other more recent C++ implementation are due to Keith M. Briggs and David Bailey et al.
Field Summary | |
---|---|
static DoubleDouble |
E
The value nearest to the constant e (the natural logarithm base). |
static double |
EPS
The smallest representable relative difference between two {link @ DoubleDouble} values |
static DoubleDouble |
NaN
A value representing the result of an operation which does not return a valid number. |
static DoubleDouble |
PI
The value nearest to the constant Pi. |
static DoubleDouble |
PI_2
The value nearest to the constant Pi / 2. |
static DoubleDouble |
TWO_PI
The value nearest to the constant 2 * Pi. |
Constructor Summary | |
---|---|
DoubleDouble()
Creates a new DoubleDouble with value 0.0. |
|
DoubleDouble(double x)
Creates a new DoubleDouble with value x. |
|
DoubleDouble(DoubleDouble dd)
Creates a new DoubleDouble with value equal to the argument. |
|
DoubleDouble(double hi,
double lo)
Creates a new DoubleDouble with value (hi, lo). |
|
DoubleDouble(java.lang.String str)
Creates a new DoubleDouble with value equal to the argument. |
Method Summary | |
---|---|
DoubleDouble |
abs()
Returns the absolute value of this value. |
DoubleDouble |
add(DoubleDouble y)
Returns a DoubleDouble whose value is (this + y). |
DoubleDouble |
ceil()
Returns the smallest (closest to negative infinity) value that is not less than the argument and is equal to a mathematical integer. |
java.lang.Object |
clone()
Creates and returns a copy of this value. |
int |
compareTo(java.lang.Object o)
Compares two DoubleDouble objects numerically. |
DoubleDouble |
divide(DoubleDouble y)
Returns a DoubleDouble whose value is (this / y). |
double |
doubleValue()
Converts this value to the nearest double-precision number. |
java.lang.String |
dump()
Dumps the components of this number to a string. |
boolean |
equals(DoubleDouble y)
Tests whether this value is equal to another DoubleDouble value. |
DoubleDouble |
floor()
Returns the largest (closest to positive infinity) value that is not greater than the argument and is equal to a mathematical integer. |
boolean |
ge(DoubleDouble y)
Tests whether this value is greater than or equals to another DoubleDouble value. |
boolean |
gt(DoubleDouble y)
Tests whether this value is greater than another DoubleDouble value. |
int |
intValue()
Converts this value to the nearest integer. |
boolean |
isNaN()
Tests whether this value is NaN. |
boolean |
isNegative()
Tests whether this value is less than 0. |
boolean |
isPositive()
Tests whether this value is greater than 0. |
boolean |
isZero()
Tests whether this value is equal to 0. |
boolean |
le(DoubleDouble y)
Tests whether this value is less than or equal to another DoubleDouble value. |
boolean |
lt(DoubleDouble y)
Tests whether this value is less than another DoubleDouble value. |
DoubleDouble |
multiply(DoubleDouble y)
Returns a DoubleDouble whose value is (this * y). |
DoubleDouble |
negate()
Returns a DoubleDouble whose value is -this. |
static DoubleDouble |
parse(java.lang.String str)
Converts a string representation of a real number into a DoubleDouble value. |
DoubleDouble |
pow(int exp)
Computes the value of this number raised to an integral power. |
DoubleDouble |
reciprocal()
Returns a DoubleDouble whose value is 1 / this. |
DoubleDouble |
rint()
Rounds this value to the nearest integer. |
int |
signum()
Returns an integer indicating the sign of this value. |
DoubleDouble |
sqr()
Computes the square of this value. |
DoubleDouble |
sqrt()
Computes the positive square root of this value. |
DoubleDouble |
subtract(DoubleDouble y)
Returns a DoubleDouble whose value is (this - y). |
java.lang.String |
toSciNotation()
Returns the string representation of this value in scientific notation. |
java.lang.String |
toStandardNotation()
Returns the string representation of this value in standard notation. |
java.lang.String |
toString()
Returns a string representation of this number, in either standard or scientific notation. |
DoubleDouble |
trunc()
Returns the integer which is largest in absolute value and not further from zero than this value. |
static DoubleDouble |
valueOf(double x)
Converts the double argument to a DoubleDouble number. |
static DoubleDouble |
valueOf(java.lang.String str)
Converts the string argument to a DoubleDouble number. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final DoubleDouble PI
public static final DoubleDouble TWO_PI
public static final DoubleDouble PI_2
public static final DoubleDouble E
public static final DoubleDouble NaN
public static final double EPS
Constructor Detail |
---|
public DoubleDouble()
public DoubleDouble(double x)
x
- the value to initializepublic DoubleDouble(double hi, double lo)
hi
- the high-order componentlo
- the high-order componentpublic DoubleDouble(DoubleDouble dd)
dd
- the value to initializepublic DoubleDouble(java.lang.String str) throws java.lang.NumberFormatException
str
- the value to initialize by
java.lang.NumberFormatException
- if str is not a valid representation of a numberMethod Detail |
---|
public static DoubleDouble valueOf(java.lang.String str) throws java.lang.NumberFormatException
str
- a string containing a representation of a numeric value
java.lang.NumberFormatException
- if s is not a valid representation of a numberpublic static DoubleDouble valueOf(double x)
x
- a numeric value
public java.lang.Object clone()
clone
in class java.lang.Object
public DoubleDouble add(DoubleDouble y)
y
- the addend
public DoubleDouble subtract(DoubleDouble y)
y
- the subtrahend
public DoubleDouble negate()
public DoubleDouble multiply(DoubleDouble y)
y
- the multiplicand
public DoubleDouble divide(DoubleDouble y)
y
- the divisor
public DoubleDouble reciprocal()
public DoubleDouble floor()
public DoubleDouble ceil()
public int signum()
public DoubleDouble rint()
public DoubleDouble trunc()
public DoubleDouble abs()
public DoubleDouble sqr()
public DoubleDouble sqrt()
public DoubleDouble pow(int exp)
exp
- the integer exponent
public double doubleValue()
public int intValue()
public boolean isZero()
public boolean isNegative()
public boolean isPositive()
public boolean isNaN()
public boolean equals(DoubleDouble y)
y
- a DoubleDouble value
public boolean gt(DoubleDouble y)
y
- a DoubleDouble value
public boolean ge(DoubleDouble y)
y
- a DoubleDouble value
public boolean lt(DoubleDouble y)
y
- a DoubleDouble value
public boolean le(DoubleDouble y)
y
- a DoubleDouble value
public int compareTo(java.lang.Object o)
compareTo
in interface java.lang.Comparable
public java.lang.String dump()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toStandardNotation()
public java.lang.String toSciNotation()
public static DoubleDouble parse(java.lang.String str) throws java.lang.NumberFormatException
[+|-] {digit} [ . {digit} ] [ ( e | E ) [+|-] {digit}+
str
- the string to parse
java.lang.NumberFormatException
- if str is not a valid representation of a number
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |