Class DoubleDouble
- All Implemented Interfaces:
Serializable
- Yozo Hida, Xiaoye S. Li, David H. Bailey. Library for Double-Double and Quad-Double arithmetic, 2007.
- Jonathan R. Shewchuk. Adaptive precision floating-point arithmetic and fast robust geometric predicates. Discrete & Computational Geometry, 18(3):305–363, 1997.
DoubleDouble is used as an alternative to BigDecimal when we do not need arbitrary
precision, we do not want to convert from base 2 to base 10, we need support for NaN and infinities, we want
more compact storage and better performance. DoubleDouble can be converted to BigDecimal as
below:
Impact of availability of FMA instructions
When allowed to use fused multiply-add (FMA) instruction added in JDK9 (see SIS-136 on Apache SIS JIRA), then the following methods should be revisited:setToProduct(double, double)- revisit with [Hida & al.] algorithm 7.
- Since:
- 0.4
- Version:
- 1.3
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleantruefor disabling the extended precision.doubleThe error that shall be added to the mainvaluein order to get the "real" (actually "the most accurate that we can") value.private static final double[]The errors associated to the values in theVALUESarray.static final doubleMaximal value that can be handled bymultiply(double, double).private static final longFor cross-version compatibility.private static final doubleThe split constant used as part of multiplication algorithms.doubleThe main value, minus theerror.private static final double[]Pre-defined constants frequently used in SIS, sorted in increasing order.private static final intWhen computing a - b as a double-double (106 significand bits) value, if the amount of non-zero significand bits is equal or lower thanZERO_THRESHOLD+1, consider the result as zero. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new value initialized to zero.DoubleDouble(double value) Creates a new instance initialized to the given value verbatim, without inferring an error term for double-double arithmetic.DoubleDouble(double value, double error) Creates a new value initialized to the given value and error.DoubleDouble(long value) Creates a new instance initialized to the given long integer.DoubleDouble(Number otherValue) Creates a new value initialized to the given number.DoubleDouble(DoubleDouble other) Creates a new value initialized to the given value. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(double otherValue) Adds adoublevalue to thisDoubleDoublewithout error term.voidadd(double[] array, int index, int errorOffset) Adds another double-double value to thisDoubleDouble, reading the values from an array.voidadd(double otherValue, double otherError) Adds another double-double value to thisDoubleDouble.voidadd(DoubleDouble other) Adds another double-double value to thisDoubleDouble.voidaddGuessError(double otherValue) Adds adoublevalue to thisDoubleDoublewith a default error term.voidaddGuessError(Number other) Adds aNumbervalue to thisDoubleDouble.voidaddKahan(double y) Adds the givendoublevalue using Kahan summation algorithm.static DoubleDoublecastOrCopy(Number value) Returns the given value as aDoubleDouble.voidclear()static DoubleDoublecreateAndGuessError(double value) Creates a new value initialized to the given value and an error term inferred byerrorForWellKnownValue(double).static DoubleDoubleReturns a newDoubleDoubleinstance initialized to the conversion factor from angular degrees to radians.static DoubleDoublecreatePi()Returns a newDoubleDoubleinstance initialized to the π value.static DoubleDoubleReturns a newDoubleDoubleinstance initialized to the conversion factor from radians to angular degrees.static DoubleDoubleReturns a newDoubleDoubleinstance initialized to the conversion factor from arc-seconds to radians.voiddivide(double otherValue) Divides thisDoubleDoubleby adoublewithout error term.voiddivide(double[] array, int index, int errorOffset) Divides thisDoubleDoubleby another double-double value stored in the given array.voiddivide(double denominatorValue, double denominatorError) Divides thisDoubleDoubleby another double-double value.voiddivide(DoubleDouble other) Divides thisDoubleDoubleby another double-double value.voiddivideGuessError(double otherValue) Divides thisDoubleDoubleby adoublewith a default error term.voiddivideGuessError(Number other) Divides thisDoubleDoubleby aNumber.doublebooleanCompares this number with the given object for equality.static doubleerrorForWellKnownValue(double value) Suggests anerrorfor the given value.floatinthashCode()Returns a hash code value for this number.intintValue()voidinverseDivide(double numeratorValue) Divides the givendoublevalue by thisDoubleDoublewithout error term.voidinverseDivide(double[] array, int index, int errorOffset) Divides the given double-double value by thisDoubleDouble.voidinverseDivide(double numeratorValue, double numeratorError) Divides the given double-double value by thisDoubleDouble.voidinverseDivide(DoubleDouble other) Divides the given double-double value by thisDoubleDouble.voidinverseDivideGuessError(double numeratorValue) Divides the givendoublevalue by thisDoubleDoublewith a default error term.voidinverseDivideGuessError(Number other) Divides the givenNumbervalue by thisDoubleDouble.booleanisZero()Returnstrueif thisDoubleDoubleis equal to zero.longvoidmultiply(double otherValue) Multiplies thisDoubleDoubleby adoublewithout error term.voidmultiply(double[] array, int index, int errorOffset) Multiplies thisDoubleDoubleby another double-double value stored in the given array.voidmultiply(double otherValue, double otherError) Multiplies thisDoubleDoubleby another double-double value.voidmultiply(DoubleDouble other) Multiplies thisDoubleDoubleby another double-double value.voidmultiplyGuessError(double otherValue) Multiplies thisDoubleDoubleby adoublewith a default error term.voidmultiplyGuessError(Number other) Multiplies thisDoubleDoubleby aNumber.voidnegate()Sets this number to-this.(package private) final voidEquivalent to a call tosetToQuickSum(value, error)inlined.voidComputes (1-x)/(1+x) where x isthis.voidseries(double... coefficients) Computes c₀ + c₁x + c₂x² + c₃x³ + c₄x⁴ + … where x isthis.voidset(long n) Sets thisDoubleDoubleto the given 64-bits signed integer.voidsetFrom(double[] array, int index, int errorOffset) voidsetFrom(DoubleDouble other) Sets thisDoubleDoubleto the same value than the given instance.voidsetToProduct(double a, double b) Sets thisDoubleDoubleto the product of the given numbers.(package private) final voidsetToQuickSum(double a, double b) Sets thisDoubleDoubleto the sum of the given numbers, to be used only whenabs(a) >= abs(b).voidsetToSum(double a, double b) Sets thisDoubleDoubleto the sum of the given numbers.static booleanshouldConvert(Number value) Returnstrueif the given value is one of the special cases recognized by theDoubleDouble(Number)constructor.voidsqrt()Sets this double-double value to its square root.voidsquare()Computes the square of this value.voidstoreTo(double[] array, int index, int errorOffset) voidsubtract(double otherValue) Subtracts adoublefrom thisDoubleDoublewithout error term.voidsubtract(double[] array, int index, int errorOffset) Subtracts another double-double value from thisDoubleDouble, reading the values from an array.voidsubtract(double otherValue, double otherError) Subtracts another double-double value from thisDoubleDouble.voidsubtract(DoubleDouble other) Subtracts another double-double value from thisDoubleDouble.voidsubtractGuessError(double otherValue) Subtracts adoublefrom thisDoubleDoublewith a default error term.voidsubtractGuessError(Number other) Subtracts aNumberfrom thisDoubleDouble.static voidswap(double[] array, int i0, int i1, int errorOffset) Swaps two double-double values in the given array.toString()Returns a string representation of this number for debugging purpose.Methods inherited from class java.lang.Number
byteValue, shortValue
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
DISABLED
public static final boolean DISABLEDtruefor disabling the extended precision. This variable should always befalse, except for testing purpose. If set totrue, then all double-double arithmetic operations are immediately followed by a clearing oferror. The result should then be identical to computation performed using the normaldoublearithmetic.Since this flag is static final, all expressions of the form
if (DISABLED)should be omitted by the compiler from the class files in normal operations.Setting this flag to
truecauses some JUnit tests to fail. This is normal. The main purpose of this flag is to alloworg.apache.sis.referencing.operation.matrix.MatrixTestCaseto perform strict comparisons of matrix operation results with JAMA, which is taken as the reference implementation. Since JAMA usesdoublearithmetic, SIS needs to disabledouble-doublearithmetic if the results are to be compared for strict equality.- See Also:
-
ZERO_THRESHOLD
private static final int ZERO_THRESHOLDWhen computing a - b as a double-double (106 significand bits) value, if the amount of non-zero significand bits is equal or lower thanZERO_THRESHOLD+1, consider the result as zero.- See Also:
-
SPLIT
private static final double SPLITThe split constant used as part of multiplication algorithms. The split algorithm is as below (we have to inline it in multiplication methods because Java cannot return multi-values):Source: [Hida & al.] page 4 algorithm 5, itself reproduced from [Shewchuk] page 325.
- See Also:
-
MAX_VALUE
public static final double MAX_VALUEMaximal value that can be handled bymultiply(double, double). If a multiplication is using a value greater thanMAX_VALUE, then the result will be infinity or NaN.- See Also:
-
VALUES
private static final double[] VALUESPre-defined constants frequently used in SIS, sorted in increasing order. This table contains only constants that cannot be inferred byDecimalFunctions.deltaForDoubleToDecimal(double), for example some transcendental values.Elements in this array shall be sorted in strictly increasing order. For any value at index i, the associated error is
ERRORS[i].- See Also:
-
ERRORS
private static final double[] ERRORSThe errors associated to the values in theVALUESarray.Tips:
- To compute a new value in this array, just put zero and execute
DoubleDoubleTest.testErrorForWellKnownValue(). The error message will give the expected value. - If a computed value is zero, then there is no point to create an entry
in the
(VALUES, ERRORS)arrays for that value.
- To compute a new value in this array, just put zero and execute
-
value
public double valueThe main value, minus theerror. -
error
public double errorThe error that shall be added to the mainvaluein order to get the "real" (actually "the most accurate that we can") value.
-
-
Constructor Details
-
DoubleDouble
public DoubleDouble()Creates a new value initialized to zero. -
DoubleDouble
Creates a new value initialized to the given value.- Parameters:
other- the other value to copy.
-
DoubleDouble
Creates a new value initialized to the given number. If the given number is an instance ofDoubleDouble,BigDecimal,BigIntegerorFraction, then the error term will be taken in account.- Parameters:
otherValue- the initial value.
-
DoubleDouble
public DoubleDouble(long value) Creates a new instance initialized to the given long integer.- Parameters:
value- the long integer value to wrap.
-
DoubleDouble
public DoubleDouble(double value) Creates a new instance initialized to the given value verbatim, without inferring an error term for double-double arithmetic. We use this constructor when the value has been computed using transcendental functions (cosine, logarithm, etc.) in which case there is no way we can infer a meaningful error term. It should also be used when the value is known to have an exact representation as adoubleprimitive type.- Parameters:
value- the value to wrap in aDoubleDoubleinstance.- See Also:
-
DoubleDouble
public DoubleDouble(double value, double error) Creates a new value initialized to the given value and error. It is caller's responsibility to ensure that the (value, error) pair is normalized.- Parameters:
value- the initial value.error- the initial error.
-
-
Method Details
-
shouldConvert
Returnstrueif the given value is one of the special cases recognized by theDoubleDouble(Number)constructor. Those special cases should rarely occur, so we do not complicate the code with optimized code paths.This method does not test if the given value is already an instance of
DoubleDouble. That verification should be done by the caller.- Parameters:
value- the value to test.- Returns:
trueif it is worth to convert the given value to aDoubleDouble.- Since:
- 0.8
-
castOrCopy
Returns the given value as aDoubleDouble. This method returns the given instance directly if it can be safely casted toDoubleDouble.- Parameters:
value- the value to cast or to copy, ornull.- Returns:
- the value as a
DoubleDouble(may be the same instance than the given argument), ornullif the given value was null. - Since:
- 0.8
-
createAndGuessError
Creates a new value initialized to the given value and an error term inferred byerrorForWellKnownValue(double). Tip: if the other value is known to be an integer or a power of 2, then invokingDoubleDouble(value)is more efficient.- Parameters:
value- the initial value.- Returns:
- an instance initialized to the given value and a default error term.
-
createPi
Returns a newDoubleDoubleinstance initialized to the π value.- Returns:
- an instance initialized to the 3.14159265358979323846264338327950 value.
-
createRadiansToDegrees
Returns a newDoubleDoubleinstance initialized to the conversion factor from radians to angular degrees.- Returns:
- an instance initialized to the 57.2957795130823208767981548141052 value.
-
createDegreesToRadians
Returns a newDoubleDoubleinstance initialized to the conversion factor from angular degrees to radians.- Returns:
- an instance initialized to the 0.01745329251994329576923690768488613 value.
-
createSecondsToRadians
Returns a newDoubleDoubleinstance initialized to the conversion factor from arc-seconds to radians.- Returns:
- an instance initialized to the 0.000004848136811095359935899141023579480 value.
-
doubleValue
public double doubleValue()- Specified by:
doubleValuein classNumber- Returns:
value+error.
-
floatValue
public float floatValue()- Specified by:
floatValuein classNumber
-
longValue
public long longValue() -
intValue
public int intValue() -
errorForWellKnownValue
public static double errorForWellKnownValue(double value) Suggests anerrorfor the given value. TheDoubleDoubleclass contains a hard-coded list of some frequently used constants, for example for various factors of π. If the given value matches exactly one of those constants, then its error term is returned. Otherwise this method assumes that the given value is defined in base 10 (e.g. many unit conversion factors) and tries to compute an error term withDecimalFunctions.deltaForDoubleToDecimal(double).Rational
SIS often creates matrices for unit conversions, and most conversion factors are defined precisely in base 10. For example, the conversion from feet to metres is defined by a factor of exactly 0.3048, which cannot be represented precisely as adouble. Consequently, if a value of 0.3048 is given, we can assume that the intent was to provide the "feet to metres" conversion factor and complete the double-double instance accordingly.- Parameters:
value- the value for which to get this error.- Returns:
- the error for the given value, or 0 if unknown. In the latter case, the base 2 representation of the given value is assumed to be accurate enough.
-
isZero
public boolean isZero()Returnstrueif thisDoubleDoubleis equal to zero.- Returns:
trueif thisDoubleDoubleis equal to zero.
-
clear
public void clear() -
set
public void set(long n) Sets thisDoubleDoubleto the given 64-bits signed integer.- Parameters:
n- the value to set.
-
setFrom
Sets thisDoubleDoubleto the same value than the given instance.- Parameters:
other- the instance to copy.
-
setFrom
public void setFrom(double[] array, int index, int errorOffset) Sets thevalueanderrorterms to values read from the given array. This is a convenience method for a frequently used operation, implemented as below:- Parameters:
array- the array from which to get the value and error.index- index of the value in the given array.errorOffset- offset to add toindexin order to get the index of the error in the given array.
-
normalize
final void normalize()Equivalent to a call tosetToQuickSum(value, error)inlined. This is invoked after addition or multiplication operations. -
setToQuickSum
final void setToQuickSum(double a, double b) Sets thisDoubleDoubleto the sum of the given numbers, to be used only whenabs(a) >= abs(b).Source: [Hida & al.] page 4 algorithm 3, itself reproduced from [Shewchuk] page 312.
- Parameters:
a- the first number to add.b- the second number to add, which must be smaller thana.
-
setToSum
public void setToSum(double a, double b) Sets thisDoubleDoubleto the sum of the given numbers.Source: [Hida & al.] page 4 algorithm 4, itself reproduced from [Shewchuk] page 314.
- Parameters:
a- the first number to add.b- the second number to add.
-
setToProduct
public void setToProduct(double a, double b) Sets thisDoubleDoubleto the product of the given numbers. The given numbers shall not be greater than 1.3393857490036326E300 in magnitude.Source: [Hida & al.] page 4 algorithm 6, itself reproduced from [Shewchuk] page 326.
- Parameters:
a- the first number to multiply.b- the second number to multiply.
-
storeTo
public void storeTo(double[] array, int index, int errorOffset) Stores thevalueanderrorterms in the given array. This is a convenience method for a frequently used operation, implemented as below:- Parameters:
array- the array where to store the value and error.index- index of the value in the given array.errorOffset- offset to add toindexin order to get the index of the error in the given array.
-
swap
public static void swap(double[] array, int i0, int i1, int errorOffset) Swaps two double-double values in the given array.- Parameters:
array- the array where to swap the values and errors.i0- index of the first value to swap.i1- index of the second value to swap.errorOffset- offset to add to the indices in order to get the error indices in the given array.- See Also:
-
negate
public void negate()Sets this number to-this. -
add
Adds another double-double value to thisDoubleDouble. This is a convenience method for:- Parameters:
other- the other value to add to thisDoubleDouble.
-
addGuessError
Adds aNumbervalue to thisDoubleDouble. If the given number is an instance ofDoubleDoubleorFraction, then the error term will be taken in account.- Parameters:
other- the other value to add to thisDoubleDouble.
-
addGuessError
public void addGuessError(double otherValue) Adds adoublevalue to thisDoubleDoublewith a default error term. This is a convenience method for: Tip: if the other value is known to be an integer or a power of 2, then invokingadd(otherValue)is more efficient.- Parameters:
otherValue- the other value to add to thisDoubleDouble.
-
addKahan
public void addKahan(double y) Adds the givendoublevalue using Kahan summation algorithm. This can be used whenotherValueis known to be smaller thanvalue.- Parameters:
y- the other value to add to thisDoubleDouble.
-
add
public void add(double otherValue) Adds adoublevalue to thisDoubleDoublewithout error term. This is a convenience method for:- Parameters:
otherValue- the other value to add to thisDoubleDouble.
-
add
public void add(double otherValue, double otherError) Adds another double-double value to thisDoubleDouble. The result is stored in this instance.Implementation
If a and b areDoubleDoubleinstances, then:(a + b)
can be computed as:(a.value + a.error) + (b.value + b.error)
keeping in mind that the result of (a.value + b.value) has itself an error which needs to be added to (a.error + b.error). In Java code:
= (a.value + b.value) + (a.error + b.error)- Parameters:
otherValue- the other value to add to thisDoubleDouble.otherError- the error of the other value to add to thisDoubleDouble.
-
add
public void add(double[] array, int index, int errorOffset) Adds another double-double value to thisDoubleDouble, reading the values from an array. This is a convenience method for a frequently used operation, implemented as below:- Parameters:
array- the array from which to get the value and error.index- index of the value in the given array.errorOffset- offset to add toindexin order to get the index of the error in the given array.
-
subtract
Subtracts another double-double value from thisDoubleDouble. This is a convenience method for:- Parameters:
other- the other value to subtract from this value.
-
subtractGuessError
Subtracts aNumberfrom thisDoubleDouble. If the given number is an instance ofDoubleDoubleorFraction, then the error term will be taken in account.- Parameters:
other- the other value to subtract from thisDoubleDouble.
-
subtractGuessError
public void subtractGuessError(double otherValue) Subtracts adoublefrom thisDoubleDoublewith a default error term. This is a convenience method for: Tip: if the other value is known to be an integer or a power of 2, then invokingsubtract(otherValue)is more efficient.- Parameters:
otherValue- the other value to subtract from thisDoubleDouble.
-
subtract
public void subtract(double otherValue) Subtracts adoublefrom thisDoubleDoublewithout error term. This is a convenience method for:- Parameters:
otherValue- the other value to subtract from thisDoubleDouble.
-
subtract
public void subtract(double otherValue, double otherError) Subtracts another double-double value from thisDoubleDouble. The result is stored in this instance.- Parameters:
otherValue- the other value to subtract from thisDoubleDouble.otherError- the error of the other value to subtract from thisDoubleDouble.
-
subtract
public void subtract(double[] array, int index, int errorOffset) Subtracts another double-double value from thisDoubleDouble, reading the values from an array. This is a convenience method for a frequently used operation, implemented as below:- Parameters:
array- the array from which to get the value and error.index- index of the value in the given array.errorOffset- offset to add toindexin order to get the index of the error in the given array.
-
multiply
Multiplies thisDoubleDoubleby another double-double value. This is a convenience method for:- Parameters:
other- the other value to multiply by this value.
-
multiplyGuessError
Multiplies thisDoubleDoubleby aNumber. If the given number is an instance ofDoubleDoubleorFraction, then the error term will be taken in account.- Parameters:
other- the other value to multiply by thisDoubleDouble.
-
multiplyGuessError
public void multiplyGuessError(double otherValue) Multiplies thisDoubleDoubleby adoublewith a default error term. This is a convenience method for: Tip: if the other value is known to be an integer or a power of 2, then invokingmultiply(otherValue)is more efficient.- Parameters:
otherValue- the other value to multiply by thisDoubleDouble.
-
multiply
public void multiply(double otherValue) Multiplies thisDoubleDoubleby adoublewithout error term. This is a convenience method for:- Parameters:
otherValue- the other value to multiply by thisDoubleDouble.
-
multiply
public void multiply(double otherValue, double otherError) Multiplies thisDoubleDoubleby another double-double value. The result is stored in this instance.Implementation
If a and b areDoubleDoubleinstances, then:(a * b)
can be computed as:(a.value + a.error) * (b.value + b.error)
The first term is the main product. All other terms are added to the error, keeping in mind that the main product has itself an error. The last term (the product of errors) is ignored because presumed very small. In Java code:
= (a.value * b.value) + (a.error * b.value) + (a.value * b.error) + (a.error * b.error)
≅ (a.value * b.value) + (a.error * b.value) + (a.value * b.error)- Parameters:
otherValue- the other value by which to multiply thisDoubleDouble.otherError- the error of the other value by which to multiply thisDoubleDouble.
-
multiply
public void multiply(double[] array, int index, int errorOffset) Multiplies thisDoubleDoubleby another double-double value stored in the given array. This is a convenience method for a frequently used operation, implemented as below:- Parameters:
array- the array from which to get the value and error.index- index of the value in the given array.errorOffset- offset to add toindexin order to get the index of the error in the given array.
-
divide
Divides thisDoubleDoubleby another double-double value. This is a convenience method for:- Parameters:
other- the other value to by which to divide this value.
-
divideGuessError
Divides thisDoubleDoubleby aNumber. If the given number is an instance ofDoubleDoubleorFraction, then the error term will be taken in account.- Parameters:
other- the other value by which to divide thisDoubleDouble.
-
divideGuessError
public void divideGuessError(double otherValue) Divides thisDoubleDoubleby adoublewith a default error term. This is a convenience method for: Tip: if the other value is known to be an integer or a power of 2, then invokingdivide(otherValue)is more efficient.- Parameters:
otherValue- the other value by which to divide thisDoubleDouble.
-
divide
public void divide(double otherValue) Divides thisDoubleDoubleby adoublewithout error term. This is a convenience method for:- Parameters:
otherValue- the other value by which to divide thisDoubleDouble.
-
divide
public void divide(double denominatorValue, double denominatorError) Divides thisDoubleDoubleby another double-double value. The result is stored in this instance.- Parameters:
denominatorValue- the other value by which to divide thisDoubleDouble.denominatorError- the error of the other value by which to divide thisDoubleDouble.
-
divide
public void divide(double[] array, int index, int errorOffset) Divides thisDoubleDoubleby another double-double value stored in the given array. This is a convenience method for a frequently used operation, implemented as below:- Parameters:
array- the array from which to get the value and error.index- index of the value in the given array.errorOffset- offset to add toindexin order to get the index of the error in the given array.
-
inverseDivide
Divides the given double-double value by thisDoubleDouble. This is a convenience method for:- Parameters:
other- the other value to divide by this value.
-
inverseDivideGuessError
Divides the givenNumbervalue by thisDoubleDouble. If the given number is an instance ofDoubleDoubleorFraction, then the error term will be taken in account.- Parameters:
other- the other value to divide by thisDoubleDouble.
-
inverseDivideGuessError
public void inverseDivideGuessError(double numeratorValue) Divides the givendoublevalue by thisDoubleDoublewith a default error term. This is a convenience method for: Tip: if the other value is known to be an integer or a power of 2, then invokinginverseDivide(otherValue)is more efficient.- Parameters:
numeratorValue- the other value to divide by thisDoubleDouble.
-
inverseDivide
public void inverseDivide(double numeratorValue) Divides the givendoublevalue by thisDoubleDoublewithout error term. This is a convenience method for:- Parameters:
numeratorValue- the other value to divide by thisDoubleDouble.
-
inverseDivide
public void inverseDivide(double numeratorValue, double numeratorError) Divides the given double-double value by thisDoubleDouble. The result is stored in this instance.Implementation
If a and b areDoubleDoubleinstances, then we estimate:(a / b) = (a.value / b.value) + remainder / b
where:remainder = a - b * (a.value / b.value)
- Parameters:
numeratorValue- the other value to divide by thisDoubleDouble.numeratorError- the error of the other value to divide by thisDoubleDouble.
-
inverseDivide
public void inverseDivide(double[] array, int index, int errorOffset) Divides the given double-double value by thisDoubleDouble. This is a convenience method for a frequently used operation, implemented as below:- Parameters:
array- the array from which to get the value and error.index- index of the value in the given array.errorOffset- offset to add toindexin order to get the index of the error in the given array.
-
ratio_1m_1p
public void ratio_1m_1p()Computes (1-x)/(1+x) where x isthis. This pattern occurs in map projections. -
square
public void square()Computes the square of this value. -
sqrt
public void sqrt()Sets this double-double value to its square root.Implementation
This method searches for a(r + ε)value where:(r + ε)² = value + error
If we could computer = sqrt(value + error)with enough precision, then ε would be 0. But with thedoubletype, we can only estimater ≈ sqrt(value). However, since that r value should be close to the "true" value, then ε should be small.value + error = (r + ε)² = r² + 2rε + ε²
Neglecting ε² on the assumption that |ε| ≪ |r|:value + error ≈ r² + 2rε
Isolating ε:ε ≈ (value + error - r²) / (2r)
-
series
public void series(double... coefficients) Computes c₀ + c₁x + c₂x² + c₃x³ + c₄x⁴ + … where x isthis. The given c coefficients are presumed accurate in base 2 (i.e. this method does not try to apply a correction for base 10).- Parameters:
coefficients- Theccoefficients. The array length must be at least 1.
-
hashCode
public int hashCode()Returns a hash code value for this number. -
equals
Compares this number with the given object for equality. -
toString
Returns a string representation of this number for debugging purpose. The returned string does not need to contains all digits that thisDoubleDoublecan handle.
-