Package org.apache.commons.math3.util
Class Decimal64
java.lang.Object
java.lang.Number
org.apache.commons.math3.util.Decimal64
- All Implemented Interfaces:
Serializable
,Comparable<Decimal64>
,FieldElement<Decimal64>
,RealFieldElement<Decimal64>
This class wraps a
double
value in an object. It is similar to the
standard class Double
, while also implementing the
RealFieldElement
interface.- Since:
- 3.1
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Decimal64
The constant value ofDouble.NaN
as aDecimal64
.static final Decimal64
The constant value ofDouble.NEGATIVE_INFINITY
as aDecimal64
.static final Decimal64
The constant value of1d
as aDecimal64
.static final Decimal64
The constant value ofDouble.POSITIVE_INFINITY
as aDecimal64
.static final Decimal64
The constant value of0d
as aDecimal64
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabs()
absolute value.acos()
Arc cosine operation.acosh()
Inverse hyperbolic cosine operation.add
(double a) '+' operator.Compute this + a.asin()
Arc sine operation.asinh()
Inverse hyperbolic sine operation.atan()
Arc tangent operation.Two arguments arc tangent operation.atanh()
Inverse hyperbolic tangent operation.byte
The current implementation performs casting to abyte
.cbrt()
Cubic root.ceil()
Get the smallest whole number larger than instance.int
The current implementation returns the same value asnew Double(this.doubleValue()).compareTo(new Double(o.doubleValue()))
copySign
(double sign) Returns the instance with the sign of the argument.Returns the instance with the sign of the argument.cos()
Cosine operation.cosh()
Hyperbolic cosine operation.divide
(double a) '÷' operator.Compute this ÷ a.double
boolean
exp()
Exponential.expm1()
Exponential minus 1.float
The current implementation performs casting to afloat
.floor()
Get the largest whole number smaller than instance.getField()
Get theField
to which the instance belongs.double
getReal()
Get the real value of the number.int
hashCode()
The current implementation returns the same value asnew Double(this.doubleValue()).hashCode()
Returns the hypotenuse of a triangle with sidesthis
andy
- sqrt(this2 +y2) avoiding intermediate overflow or underflow.int
intValue()
The current implementation performs casting to aint
.boolean
Returnstrue
ifthis
double precision number is infinite (Double.POSITIVE_INFINITY
orDouble.NEGATIVE_INFINITY
).boolean
isNaN()
Returnstrue
ifthis
double precision number is Not-a-Number (NaN
), false otherwise.linearCombination
(double[] a, Decimal64[] b) Compute a linear combination.linearCombination
(double a1, Decimal64 b1, double a2, Decimal64 b2) Compute a linear combination.linearCombination
(double a1, Decimal64 b1, double a2, Decimal64 b2, double a3, Decimal64 b3) Compute a linear combination.linearCombination
(double a1, Decimal64 b1, double a2, Decimal64 b2, double a3, Decimal64 b3, double a4, Decimal64 b4) Compute a linear combination.linearCombination
(Decimal64[] a, Decimal64[] b) Compute a linear combination.linearCombination
(Decimal64 a1, Decimal64 b1, Decimal64 a2, Decimal64 b2) Compute a linear combination.linearCombination
(Decimal64 a1, Decimal64 b1, Decimal64 a2, Decimal64 b2, Decimal64 a3, Decimal64 b3) Compute a linear combination.linearCombination
(Decimal64 a1, Decimal64 b1, Decimal64 a2, Decimal64 b2, Decimal64 a3, Decimal64 b3, Decimal64 a4, Decimal64 b4) Compute a linear combination.log()
Natural logarithm.log10()
Base 10 logarithm.log1p()
Shifted natural logarithm.long
The current implementation performs casting to along
.multiply
(double a) '×' operator.multiply
(int n) Compute n × this.Compute this × a.negate()
Returns the additive inverse ofthis
element.pow
(double p) Power operation.pow
(int n) Integer power operation.Power operation.Returns the multiplicative inverse ofthis
element.remainder
(double a) IEEE remainder operator.IEEE remainder operator.rint()
Get the whole number that is the nearest to the instance, or the even one if x is exactly half way between two integers.rootN
(int n) Nth root.long
round()
Get the closest long to instance value.scalb
(int n) Multiply the instance by a power of 2.short
The current implementation performs casting to ashort
.signum()
Compute the signum of the instance.sin()
Sine operation.sinh()
Hyperbolic sine operation.sqrt()
Square root.subtract
(double a) '-' operator.Compute this - a.tan()
Tangent operation.tanh()
Hyperbolic tangent operation.toString()
The returnedString
is equal toDouble.toString(this.doubleValue())
-
Field Details
-
ZERO
The constant value of0d
as aDecimal64
. -
ONE
The constant value of1d
as aDecimal64
. -
NEGATIVE_INFINITY
The constant value ofDouble.NEGATIVE_INFINITY
as aDecimal64
. -
POSITIVE_INFINITY
The constant value ofDouble.POSITIVE_INFINITY
as aDecimal64
. -
NAN
The constant value ofDouble.NaN
as aDecimal64
.
-
-
Constructor Details
-
Decimal64
public Decimal64(double x) Creates a new instance of this class.- Parameters:
x
- the primitivedouble
value of the object to be created
-
-
Method Details
-
getField
Get theField
to which the instance belongs.- Specified by:
getField
in interfaceFieldElement<Decimal64>
- Returns:
Field
to which the instance belongs
-
add
Compute this + a. The current implementation strictly enforcesthis.add(a).equals(new Decimal64(this.doubleValue() + a.doubleValue()))
.- Specified by:
add
in interfaceFieldElement<Decimal64>
- Parameters:
a
- element to add- Returns:
- a new element representing this + a
-
subtract
Compute this - a. The current implementation strictly enforcesthis.subtract(a).equals(new Decimal64(this.doubleValue() - a.doubleValue()))
.- Specified by:
subtract
in interfaceFieldElement<Decimal64>
- Parameters:
a
- element to subtract- Returns:
- a new element representing this - a
-
negate
Returns the additive inverse ofthis
element. The current implementation strictly enforcesthis.negate().equals(new Decimal64(-this.doubleValue()))
.- Specified by:
negate
in interfaceFieldElement<Decimal64>
- Returns:
- the opposite of
this
.
-
multiply
Compute this × a. The current implementation strictly enforcesthis.multiply(a).equals(new Decimal64(this.doubleValue() * a.doubleValue()))
.- Specified by:
multiply
in interfaceFieldElement<Decimal64>
- Parameters:
a
- element to multiply- Returns:
- a new element representing this × a
-
multiply
Compute n × this. Multiplication by an integer number is defined as the following sumn × this = ∑i=1n this. The current implementation strictly enforcesthis.multiply(n).equals(new Decimal64(n * this.doubleValue()))
.- Specified by:
multiply
in interfaceFieldElement<Decimal64>
- Parameters:
n
- Number of timesthis
must be added to itself.- Returns:
- A new element representing n × this.
-
divide
Compute this ÷ a. The current implementation strictly enforcesthis.divide(a).equals(new Decimal64(this.doubleValue() / a.doubleValue()))
.- Specified by:
divide
in interfaceFieldElement<Decimal64>
- Parameters:
a
- element to divide by- Returns:
- a new element representing this ÷ a
-
reciprocal
Returns the multiplicative inverse ofthis
element. The current implementation strictly enforcesthis.reciprocal().equals(new Decimal64(1.0 / this.doubleValue()))
.- Specified by:
reciprocal
in interfaceFieldElement<Decimal64>
- Specified by:
reciprocal
in interfaceRealFieldElement<Decimal64>
- Returns:
- the inverse of
this
.
-
byteValue
public byte byteValue()The current implementation performs casting to abyte
. -
shortValue
public short shortValue()The current implementation performs casting to ashort
.- Overrides:
shortValue
in classNumber
-
intValue
public int intValue()The current implementation performs casting to aint
. -
longValue
public long longValue()The current implementation performs casting to along
. -
floatValue
public float floatValue()The current implementation performs casting to afloat
.- Specified by:
floatValue
in classNumber
-
doubleValue
public double doubleValue()- Specified by:
doubleValue
in classNumber
-
compareTo
The current implementation returns the same value asnew Double(this.doubleValue()).compareTo(new Double(o.doubleValue()))
- Specified by:
compareTo
in interfaceComparable<Decimal64>
- See Also:
-
equals
-
hashCode
public int hashCode()The current implementation returns the same value asnew Double(this.doubleValue()).hashCode()
-
toString
The returnedString
is equal toDouble.toString(this.doubleValue())
-
isInfinite
public boolean isInfinite()Returnstrue
ifthis
double precision number is infinite (Double.POSITIVE_INFINITY
orDouble.NEGATIVE_INFINITY
).- Returns:
true
ifthis
number is infinite
-
isNaN
public boolean isNaN()Returnstrue
ifthis
double precision number is Not-a-Number (NaN
), false otherwise.- Returns:
true
ifthis
isNaN
-
getReal
public double getReal()Get the real value of the number.- Specified by:
getReal
in interfaceRealFieldElement<Decimal64>
- Returns:
- real value
- Since:
- 3.2
-
add
'+' operator.- Specified by:
add
in interfaceRealFieldElement<Decimal64>
- Parameters:
a
- right hand side parameter of the operator- Returns:
- this+a
- Since:
- 3.2
-
subtract
'-' operator.- Specified by:
subtract
in interfaceRealFieldElement<Decimal64>
- Parameters:
a
- right hand side parameter of the operator- Returns:
- this-a
- Since:
- 3.2
-
multiply
'×' operator.- Specified by:
multiply
in interfaceRealFieldElement<Decimal64>
- Parameters:
a
- right hand side parameter of the operator- Returns:
- this×a
- Since:
- 3.2
-
divide
'÷' operator.- Specified by:
divide
in interfaceRealFieldElement<Decimal64>
- Parameters:
a
- right hand side parameter of the operator- Returns:
- this÷a
- Since:
- 3.2
-
remainder
IEEE remainder operator.- Specified by:
remainder
in interfaceRealFieldElement<Decimal64>
- Parameters:
a
- right hand side parameter of the operator- Returns:
- this - n × a where n is the closest integer to this/a (the even integer is chosen for n if this/a is halfway between two integers)
- Since:
- 3.2
-
remainder
IEEE remainder operator.- Specified by:
remainder
in interfaceRealFieldElement<Decimal64>
- Parameters:
a
- right hand side parameter of the operator- Returns:
- this - n × a where n is the closest integer to this/a (the even integer is chosen for n if this/a is halfway between two integers)
- Since:
- 3.2
-
abs
absolute value.- Specified by:
abs
in interfaceRealFieldElement<Decimal64>
- Returns:
- abs(this)
- Since:
- 3.2
-
ceil
Get the smallest whole number larger than instance.- Specified by:
ceil
in interfaceRealFieldElement<Decimal64>
- Returns:
- ceil(this)
- Since:
- 3.2
-
floor
Get the largest whole number smaller than instance.- Specified by:
floor
in interfaceRealFieldElement<Decimal64>
- Returns:
- floor(this)
- Since:
- 3.2
-
rint
Get the whole number that is the nearest to the instance, or the even one if x is exactly half way between two integers.- Specified by:
rint
in interfaceRealFieldElement<Decimal64>
- Returns:
- a double number r such that r is an integer r - 0.5 ≤ this ≤ r + 0.5
- Since:
- 3.2
-
round
public long round()Get the closest long to instance value.- Specified by:
round
in interfaceRealFieldElement<Decimal64>
- Returns:
- closest long to
RealFieldElement.getReal()
- Since:
- 3.2
-
signum
Compute the signum of the instance. The signum is -1 for negative numbers, +1 for positive numbers and 0 otherwise- Specified by:
signum
in interfaceRealFieldElement<Decimal64>
- Returns:
- -1.0, -0.0, +0.0, +1.0 or NaN depending on sign of a
- Since:
- 3.2
-
copySign
Returns the instance with the sign of the argument. A NaNsign
argument is treated as positive.- Specified by:
copySign
in interfaceRealFieldElement<Decimal64>
- Parameters:
sign
- the sign for the returned value- Returns:
- the instance with the same sign as the
sign
argument - Since:
- 3.2
-
copySign
Returns the instance with the sign of the argument. A NaNsign
argument is treated as positive.- Specified by:
copySign
in interfaceRealFieldElement<Decimal64>
- Parameters:
sign
- the sign for the returned value- Returns:
- the instance with the same sign as the
sign
argument - Since:
- 3.2
-
scalb
Multiply the instance by a power of 2.- Specified by:
scalb
in interfaceRealFieldElement<Decimal64>
- Parameters:
n
- power of 2- Returns:
- this × 2n
- Since:
- 3.2
-
hypot
Returns the hypotenuse of a triangle with sidesthis
andy
- sqrt(this2 +y2) avoiding intermediate overflow or underflow.- If either argument is infinite, then the result is positive infinity.
- else, if either argument is NaN then the result is NaN.
- Specified by:
hypot
in interfaceRealFieldElement<Decimal64>
- Parameters:
y
- a value- Returns:
- sqrt(this2 +y2)
- Since:
- 3.2
-
sqrt
Square root.- Specified by:
sqrt
in interfaceRealFieldElement<Decimal64>
- Returns:
- square root of the instance
- Since:
- 3.2
-
cbrt
Cubic root.- Specified by:
cbrt
in interfaceRealFieldElement<Decimal64>
- Returns:
- cubic root of the instance
- Since:
- 3.2
-
rootN
Nth root.- Specified by:
rootN
in interfaceRealFieldElement<Decimal64>
- Parameters:
n
- order of the root- Returns:
- nth root of the instance
- Since:
- 3.2
-
pow
Power operation.- Specified by:
pow
in interfaceRealFieldElement<Decimal64>
- Parameters:
p
- power to apply- Returns:
- thisp
- Since:
- 3.2
-
pow
Integer power operation.- Specified by:
pow
in interfaceRealFieldElement<Decimal64>
- Parameters:
n
- power to apply- Returns:
- thisn
- Since:
- 3.2
-
pow
Power operation.- Specified by:
pow
in interfaceRealFieldElement<Decimal64>
- Parameters:
e
- exponent- Returns:
- thise
- Since:
- 3.2
-
exp
Exponential.- Specified by:
exp
in interfaceRealFieldElement<Decimal64>
- Returns:
- exponential of the instance
- Since:
- 3.2
-
expm1
Exponential minus 1.- Specified by:
expm1
in interfaceRealFieldElement<Decimal64>
- Returns:
- exponential minus one of the instance
- Since:
- 3.2
-
log
Natural logarithm.- Specified by:
log
in interfaceRealFieldElement<Decimal64>
- Returns:
- logarithm of the instance
- Since:
- 3.2
-
log1p
Shifted natural logarithm.- Specified by:
log1p
in interfaceRealFieldElement<Decimal64>
- Returns:
- logarithm of one plus the instance
- Since:
- 3.2
-
log10
Base 10 logarithm.- Returns:
- base 10 logarithm of the instance
- Since:
- 3.2
-
cos
Cosine operation.- Specified by:
cos
in interfaceRealFieldElement<Decimal64>
- Returns:
- cos(this)
- Since:
- 3.2
-
sin
Sine operation.- Specified by:
sin
in interfaceRealFieldElement<Decimal64>
- Returns:
- sin(this)
- Since:
- 3.2
-
tan
Tangent operation.- Specified by:
tan
in interfaceRealFieldElement<Decimal64>
- Returns:
- tan(this)
- Since:
- 3.2
-
acos
Arc cosine operation.- Specified by:
acos
in interfaceRealFieldElement<Decimal64>
- Returns:
- acos(this)
- Since:
- 3.2
-
asin
Arc sine operation.- Specified by:
asin
in interfaceRealFieldElement<Decimal64>
- Returns:
- asin(this)
- Since:
- 3.2
-
atan
Arc tangent operation.- Specified by:
atan
in interfaceRealFieldElement<Decimal64>
- Returns:
- atan(this)
- Since:
- 3.2
-
atan2
Two arguments arc tangent operation.- Specified by:
atan2
in interfaceRealFieldElement<Decimal64>
- Parameters:
x
- second argument of the arc tangent- Returns:
- atan2(this, x)
- Since:
- 3.2
-
cosh
Hyperbolic cosine operation.- Specified by:
cosh
in interfaceRealFieldElement<Decimal64>
- Returns:
- cosh(this)
- Since:
- 3.2
-
sinh
Hyperbolic sine operation.- Specified by:
sinh
in interfaceRealFieldElement<Decimal64>
- Returns:
- sinh(this)
- Since:
- 3.2
-
tanh
Hyperbolic tangent operation.- Specified by:
tanh
in interfaceRealFieldElement<Decimal64>
- Returns:
- tanh(this)
- Since:
- 3.2
-
acosh
Inverse hyperbolic cosine operation.- Specified by:
acosh
in interfaceRealFieldElement<Decimal64>
- Returns:
- acosh(this)
- Since:
- 3.2
-
asinh
Inverse hyperbolic sine operation.- Specified by:
asinh
in interfaceRealFieldElement<Decimal64>
- Returns:
- asin(this)
- Since:
- 3.2
-
atanh
Inverse hyperbolic tangent operation.- Specified by:
atanh
in interfaceRealFieldElement<Decimal64>
- Returns:
- atanh(this)
- Since:
- 3.2
-
linearCombination
Compute a linear combination.- Specified by:
linearCombination
in interfaceRealFieldElement<Decimal64>
- Parameters:
a
- Factors.b
- Factors.- Returns:
Σi ai bi
.- Throws:
DimensionMismatchException
- if arrays dimensions don't match- Since:
- 3.2
-
linearCombination
Compute a linear combination.- Specified by:
linearCombination
in interfaceRealFieldElement<Decimal64>
- Parameters:
a
- Factors.b
- Factors.- Returns:
Σi ai bi
.- Throws:
DimensionMismatchException
- if arrays dimensions don't match- Since:
- 3.2
-
linearCombination
Compute a linear combination.- Specified by:
linearCombination
in interfaceRealFieldElement<Decimal64>
- Parameters:
a1
- first factor of the first termb1
- second factor of the first terma2
- first factor of the second termb2
- second factor of the second term- Returns:
- a1×b1 + a2×b2
- Since:
- 3.2
- See Also:
-
linearCombination
Compute a linear combination.- Specified by:
linearCombination
in interfaceRealFieldElement<Decimal64>
- Parameters:
a1
- first factor of the first termb1
- second factor of the first terma2
- first factor of the second termb2
- second factor of the second term- Returns:
- a1×b1 + a2×b2
- Since:
- 3.2
- See Also:
-
linearCombination
public Decimal64 linearCombination(Decimal64 a1, Decimal64 b1, Decimal64 a2, Decimal64 b2, Decimal64 a3, Decimal64 b3) Compute a linear combination.- Specified by:
linearCombination
in interfaceRealFieldElement<Decimal64>
- Parameters:
a1
- first factor of the first termb1
- second factor of the first terma2
- first factor of the second termb2
- second factor of the second terma3
- first factor of the third termb3
- second factor of the third term- Returns:
- a1×b1 + a2×b2 + a3×b3
- Since:
- 3.2
- See Also:
-
linearCombination
public Decimal64 linearCombination(double a1, Decimal64 b1, double a2, Decimal64 b2, double a3, Decimal64 b3) Compute a linear combination.- Specified by:
linearCombination
in interfaceRealFieldElement<Decimal64>
- Parameters:
a1
- first factor of the first termb1
- second factor of the first terma2
- first factor of the second termb2
- second factor of the second terma3
- first factor of the third termb3
- second factor of the third term- Returns:
- a1×b1 + a2×b2 + a3×b3
- Since:
- 3.2
- See Also:
-
linearCombination
public Decimal64 linearCombination(Decimal64 a1, Decimal64 b1, Decimal64 a2, Decimal64 b2, Decimal64 a3, Decimal64 b3, Decimal64 a4, Decimal64 b4) Compute a linear combination.- Specified by:
linearCombination
in interfaceRealFieldElement<Decimal64>
- Parameters:
a1
- first factor of the first termb1
- second factor of the first terma2
- first factor of the second termb2
- second factor of the second terma3
- first factor of the third termb3
- second factor of the third terma4
- first factor of the third termb4
- second factor of the third term- Returns:
- a1×b1 + a2×b2 + a3×b3 + a4×b4
- Since:
- 3.2
- See Also:
-
linearCombination
public Decimal64 linearCombination(double a1, Decimal64 b1, double a2, Decimal64 b2, double a3, Decimal64 b3, double a4, Decimal64 b4) Compute a linear combination.- Specified by:
linearCombination
in interfaceRealFieldElement<Decimal64>
- Parameters:
a1
- first factor of the first termb1
- second factor of the first terma2
- first factor of the second termb2
- second factor of the second terma3
- first factor of the third termb3
- second factor of the third terma4
- first factor of the third termb4
- second factor of the third term- Returns:
- a1×b1 + a2×b2 + a3×b3 + a4×b4
- Since:
- 3.2
- See Also:
-