@Immutable public class DoubleOperations extends Object implements MathOperations<Double>, Comparator<Double>
math operations for double numbers.| Constructor and Description |
|---|
DoubleOperations() |
| Modifier and Type | Method and Description |
|---|---|
Double |
add(Double value1,
Double value2)
Add the two operands and return the sum.
|
BigDecimal |
asBigDecimal(Double value)
Create a
BigDecimal representation of the supplied value. |
int |
compare(Double value1,
Double value2)
Compare the two operands and return an integer that describes whether the first value is larger, smaller or the same as the
second value.
|
Double |
create(double value)
Convert the double representation into the natural object representation.
|
Double |
create(int value)
Convert the integer representation into the natural object representation.
|
Double |
create(long value)
Convert the long representation into the natural object representation.
|
Double |
createZeroValue()
Create the object form of the "zero value".
|
double |
divide(Double value1,
Double value2)
Divide the first operand by the second, and return the result.
|
double |
doubleValue(Double value)
Convert the value to a double.
|
float |
floatValue(Double value)
Convert the value to a float.
|
Double |
fromBigDecimal(BigDecimal value)
Convert the
BigDecimal representation into the natural object representation. |
Comparator<Double> |
getComparator()
Return a
Comparator for this operand class. |
int |
getExponentInScientificNotation(Double value)
Get the exponent if the number were written in exponential form.
|
Class<Double> |
getOperandClass()
Return the class that these operations operate upon.
|
Double |
increment(Double value)
Increment the supplied operand by 1.
|
int |
intValue(Double value)
Convert the value to an integer.
|
Double |
keepSignificantFigures(Double value,
int numSigFigs) |
long |
longValue(Double value)
Convert the value to a long integer.
|
Double |
maximum(Double value1,
Double value2)
Compare the two operands and return the one that is larger.
|
Double |
minimum(Double value1,
Double value2)
Compare the two operands and return the one that is smaller.
|
Double |
multiply(Double value1,
Double value2)
Multiply the two operands and return the product.
|
Double |
negate(Double value)
Negate the supplied operand.
|
Double |
random(Double minimum,
Double maximum,
Random rng)
Generate a random instance within the specified range.
|
Double |
roundDown(Double value,
int decimalShift)
Round down the supplied value to the desired scale.
|
Double |
roundUp(Double value,
int decimalShift)
Round up the supplied value to the desired scale.
|
short |
shortValue(Double value)
Convert the value to a short.
|
double |
sqrt(Double value)
Return the square root of the supplied operand.
|
Double |
subtract(Double value1,
Double value2)
Subtract the second operand from the first, and return the difference.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcomparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLongpublic Class<Double> getOperandClass()
MathOperationsgetOperandClass in interface MathOperations<Double>public Double add(Double value1, Double value2)
MathOperationszero value is used in place of any operand that is
null.add in interface MathOperations<Double>value1 - the first operandvalue2 - the second operandpublic Double subtract(Double value1, Double value2)
MathOperationszero value is used in
place of any operand that is null.subtract in interface MathOperations<Double>value1 - the first operandvalue2 - the second operandpublic Double multiply(Double value1, Double value2)
MathOperationszero value is used in place of any operand
that is null.multiply in interface MathOperations<Double>value1 - the first operandvalue2 - the second operandpublic double divide(Double value1, Double value2)
MathOperationszero value is used in place
of any operand that is null.divide in interface MathOperations<Double>value1 - the first operandvalue2 - the second operandpublic Double negate(Double value)
MathOperationszero value is used in place of any operand that is null.negate in interface MathOperations<Double>value - the value that is to be negatedpublic Double increment(Double value)
MathOperationsoperand class. The zero value is used in place of any operand that is
null.increment in interface MathOperations<Double>value - the value that is to be incrementedpublic Double maximum(Double value1, Double value2)
MathOperationsmaximum in interface MathOperations<Double>value1 - the first operandvalue2 - the second operandpublic Double minimum(Double value1, Double value2)
MathOperationsminimum in interface MathOperations<Double>value1 - the first operandvalue2 - the second operandpublic int compare(Double value1, Double value2)
MathOperationsComparable. The zero value is used
in place of any operand that is null.compare in interface Comparator<Double>compare in interface MathOperations<Double>value1 - the first operandvalue2 - the second operandpublic BigDecimal asBigDecimal(Double value)
MathOperationsBigDecimal representation of the supplied value.asBigDecimal in interface MathOperations<Double>value - the value that is to be converted to a BigDecimalvalue is nullpublic Double fromBigDecimal(BigDecimal value)
MathOperationsBigDecimal representation into the natural object representation. This may result in loss of some data
(e.g., converting a decimal to an integer results in the loss of the fractional part of the number).fromBigDecimal in interface MathOperations<Double>value - the BigDecimal valuevalue is nullpublic Double createZeroValue()
MathOperationscreateZeroValue in interface MathOperations<Double>public Double create(int value)
MathOperationscreate in interface MathOperations<Double>value - the integer valuepublic Double create(long value)
MathOperationscreate in interface MathOperations<Double>value - the long valuepublic Double create(double value)
MathOperationscreate in interface MathOperations<Double>value - the double valuepublic double sqrt(Double value)
MathOperationssqrt in interface MathOperations<Double>value - the value whose root is to be found; may not be null or 0public Comparator<Double> getComparator()
MathOperationsComparator for this operand class. The implementation is free to
return the same comparator instance from multiple invocations of this method.getComparator in interface MathOperations<Double>public Double random(Double minimum, Double maximum, Random rng)
MathOperationsrandom in interface MathOperations<Double>minimum - the minimum value, or null if the zero-value should be used for the minimummaximum - the maximum value, or null if the zero-value should be used for the maximumrng - the random number generator to useoperand class placed within the desired range using a random
distribution, or null if this class does not support generating random instancespublic double doubleValue(Double value)
MathOperationsoperand class.doubleValue in interface MathOperations<Double>value - the valuepublic float floatValue(Double value)
MathOperationsoperand
class.floatValue in interface MathOperations<Double>value - the valuepublic int intValue(Double value)
MathOperationsoperand class.intValue in interface MathOperations<Double>value - the valuepublic long longValue(Double value)
MathOperationsoperand class.longValue in interface MathOperations<Double>value - the valuepublic short shortValue(Double value)
MathOperationsoperand
class.shortValue in interface MathOperations<Double>value - the valuepublic int getExponentInScientificNotation(Double value)
MathOperationsgetExponentInScientificNotation in interface MathOperations<Double>value - the valuepublic Double roundUp(Double value, int decimalShift)
MathOperationsdecimalShift places, rounding, and then shifting the decimal point of the rounded value by
-decimalShift
For example, consider the number 10.000354. This can be rounded to 10.0004 by calling this method and supplying the value and an "exponentToKeep" value of -4.
roundUp in interface MathOperations<Double>value - the value to be roundeddecimalShift - the number of places the decimal point should be shifted before roundingpublic Double roundDown(Double value, int decimalShift)
MathOperationsdecimalShift places, rounding, and then shifting the decimal point of the rounded value by
-decimalShift
For example, consider the number 10.000354. This can be rounded to 10.0003 by calling this method and supplying the value and an "exponentToKeep" value of -4.
roundDown in interface MathOperations<Double>value - the value to be roundeddecimalShift - the number of places the decimal point should be shifted before roundingpublic Double keepSignificantFigures(Double value, int numSigFigs)
keepSignificantFigures in interface MathOperations<Double>Copyright © 2008–2016 JBoss, a division of Red Hat. All rights reserved.