Class RealFloat64
- All Implemented Interfaces:
Serializable
,Comparable<RealFloat64>
,Field<RealFloat64>
,Ring<RealFloat64>
,Semiring<RealFloat64>
Represents an immutable real number backed by a 64-bit floating-point value.
This class wraps the primitive double
type and provides arithmetic operations
consistent with a mathematical field. It implements the Field
interface,
allowing it to be used in generic algorithms that operate on field elements.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final RealFloat64
The numerical value-1.0
.static final RealFloat64
The numerical value1.0
.static final RealFloat64
The numerical value representing pi (π), the ratio of the circumference of a circle to its diameter.static final RealFloat64
The numerical value representing the square root of three.static final RealFloat64
The numerical value representing the square root of two.static final RealFloat64
The numerical value10.0
.static final RealFloat64
The numerical value3.0
.static final RealFloat64
The numerical value2.0
.static final RealFloat64
The numerical value0.0
. -
Constructor Summary
ConstructorsConstructorDescriptionRealFloat64
(double value) Constructs a newRealFloat64
instance with the specified double value.RealFloat64
(RealFloat32 value) Constructs a newRealFloat64
instance with the specifiedRealFloat32
value. -
Method Summary
Modifier and TypeMethodDescriptionadd
(double b) Sums an element of this field with a real number (associative and commutative).add
(RealFloat64 b) Sums two elements of this field (associative and commutative).addInv()
Computes the additive inverse for an element of this field.int
Compares this element of the ordered field withb
.div
(double b) Computes the quotient of an element of this field and a real number.div
(RealFloat64 b) Computes the quotient of two elements of this field.double
Converts this semiring value to an equivalent double value.boolean
Checks if an object is equal to this Field element.getOne()
Gets the multiplicative identity for this semiring.double
getValue()
Gets the value of this field element.getZero()
Gets the additive identity for this semiring.int
hashCode()
boolean
isFinite()
Checks if this field element is finite in magnitude.boolean
Checks if this field element is infinite in magnitude.boolean
isNaN()
Checks if this field element is NaN in magnitude.boolean
isOne()
Checks if this value is a multiplicative identity for this semiring.boolean
isZero()
Checks if this value is an additive identity for this semiring.double
mag()
Computes the magnitude of this field element.mult
(double b) Multiplies an element of this field with a real number (associative and commutative).mult
(RealFloat64 b) Multiplies two elements of this field (associative and commutative).multInv()
Computes the multiplicative inverse for an element of this field.static RealFloat64
prod
(RealFloat64... values) Computes the product of all data of specified array.static RealFloat64
round
(RealFloat64 n, int decimals) Rounds number to specified number of decimal places.static RealFloat64
sgn
(RealFloat64 a) Evaluates the signum or sign function on a field element.sqrt()
Computes the square root of this field element.sub
(double b) Computes difference of an element of this field and a real number.sub
(RealFloat64 b) Computes difference of two elements of this field.static RealFloat64
sum
(RealFloat64... values) Computes the sum of all data of specified array.toString()
Returns a string representation of thisRealFloat64
instance.static RealFloat64[]
wrapArray
(double... arr) Wraps a primitive double array as aRealFloat64
array.static RealFloat64[]
Wraps aDouble
array as aRealFloat64
array.
-
Field Details
-
NEGATIVE_ONE
The numerical value-1.0
. -
ZERO
The numerical value0.0
. -
ONE
The numerical value1.0
. -
TWO
The numerical value2.0
. -
THREE
The numerical value3.0
. -
TEN
The numerical value10.0
. -
ROOT_TWO
The numerical value representing the square root of two. -
ROOT_THREE
The numerical value representing the square root of three. -
PI
The numerical value representing pi (π), the ratio of the circumference of a circle to its diameter.
-
-
Constructor Details
-
RealFloat64
Constructs a newRealFloat64
instance with the specifiedRealFloat32
value.- Parameters:
value
- theRealFloat32
value to be converted and stored.
-
RealFloat64
public RealFloat64(double value) Constructs a newRealFloat64
instance with the specified double value.- Parameters:
value
- the double value to be stored.
-
-
Method Details
-
round
Rounds number to specified number of decimal places.- Parameters:
n
- Number to round.decimals
- Number of decimals to round to.- Returns:
- The number
n
rounded to the specified number of decimals. If !Double.isFinite(n.value) then no rounding will be performed and an unmodifiedn
will be returned. - Throws:
IllegalArgumentException
- If decimals is less than zero.
-
getValue
public double getValue()Gets the value of this field element.- Returns:
- The value of this field element.
-
add
Sums two elements of this field (associative and commutative).- Specified by:
add
in interfaceSemiring<RealFloat64>
- Parameters:
b
- Second field element in sum.- Returns:
- The sum of this element and
b
.
-
sub
Computes difference of two elements of this field.- Specified by:
sub
in interfaceRing<RealFloat64>
- Parameters:
b
- Second field element in difference.- Returns:
- The difference of this field element and
b
.
-
mult
Multiplies two elements of this field (associative and commutative).- Specified by:
mult
in interfaceSemiring<RealFloat64>
- Parameters:
b
- Second field element in product.- Returns:
- The product of this field element and
b
.
-
isZero
public boolean isZero()Checks if this value is an additive identity for this semiring.
An element
0
is an additive identity ifa + 0 = a
for anya
in the semiring.- Specified by:
isZero
in interfaceSemiring<RealFloat64>
- Returns:
- True if this value is an additive identity for this semiring. Otherwise, false.
-
isOne
public boolean isOne()Checks if this value is a multiplicative identity for this semiring.
An element
1
is a multiplicative identity ifa * 1 = a
for anya
in the semiring.- Specified by:
isOne
in interfaceSemiring<RealFloat64>
- Returns:
- True if this value is a multiplicative identity for this semiring. Otherwise, false.
-
getZero
Gets the additive identity for this semiring.
An element 0 is an additive identity if a + 0 = a for any a in the semiring.
- Specified by:
getZero
in interfaceSemiring<RealFloat64>
- Returns:
- The additive identity for this semiring.
-
getOne
Gets the multiplicative identity for this semiring.
An element 1 is a multiplicative identity if a * 1 = a for any a in the semiring.
- Specified by:
getOne
in interfaceSemiring<RealFloat64>
- Returns:
- The multiplicative identity for this semiring.
-
div
Computes the quotient of two elements of this field.- Specified by:
div
in interfaceField<RealFloat64>
- Parameters:
b
- Second field element in quotient.- Returns:
- The quotient of this field element and
b
.
-
add
Sums an element of this field with a real number (associative and commutative).- Specified by:
add
in interfaceField<RealFloat64>
- Parameters:
b
- Real element in sum.- Returns:
- The sum of this element and
b
.
-
sub
Computes difference of an element of this field and a real number.- Specified by:
sub
in interfaceField<RealFloat64>
- Parameters:
b
- Real value in difference.- Returns:
- The difference of this ring element and
b
.
-
mult
Multiplies an element of this field with a real number (associative and commutative).- Specified by:
mult
in interfaceField<RealFloat64>
- Parameters:
b
- Real number in product.- Returns:
- The product of this field element and
b
.
-
div
Computes the quotient of an element of this field and a real number.- Specified by:
div
in interfaceField<RealFloat64>
- Parameters:
b
- Real number in quotient.- Returns:
- The quotient of this field element and
b
.
-
multInv
Computes the multiplicative inverse for an element of this field.
An element x-1 is a multiplicative inverse for a field element x if x-1*x = 1 where 1 is the multiplicative identity.
- Specified by:
multInv
in interfaceField<RealFloat64>
- Returns:
- The multiplicative inverse for this field element.
-
addInv
Computes the additive inverse for an element of this field.
An element -x is an additive inverse for a field element x if -x + x = 0 where 0 is the additive identity.
- Specified by:
addInv
in interfaceRing<RealFloat64>
- Returns:
- The additive inverse for this field element.
-
mag
public double mag()Computes the magnitude of this field element.- Specified by:
mag
in interfaceRing<RealFloat64>
- Returns:
- The magnitude of this field element.
-
sqrt
Computes the square root of this field element.- Specified by:
sqrt
in interfaceField<RealFloat64>
- Returns:
- The square root of this field element.
-
sgn
Evaluates the signum or sign function on a field element.- Parameters:
a
- Value to evaluate signum function on.- Returns:
- The output of the signum function evaluated on
a
.
-
compareTo
Compares this element of the ordered field withb
.- Specified by:
compareTo
in interfaceComparable<RealFloat64>
- Specified by:
compareTo
in interfaceSemiring<RealFloat64>
- Parameters:
b
- Second element of the ordered field.- Returns:
- An int value:
- 0 if this field element is equal to
b
. - invalid input: '<' 0 if this field element is less than
b
. - > 0 if this field element is greater than
b
.
Hence, this method returns zero if and only if the two field elements are equal, a negative value if and only the field
element it was called on is less than
b
and positive if and only if the field element it was called on is greater thanb
. - 0 if this field element is equal to
-
doubleValue
public double doubleValue()Converts this semiring value to an equivalent double value.- Specified by:
doubleValue
in interfaceSemiring<RealFloat64>
- Returns:
- A double value equivalent to this semiring element.
-
isFinite
public boolean isFinite()Checks if this field element is finite in magnitude.- Specified by:
isFinite
in interfaceField<RealFloat64>
- Returns:
- True if this field element is finite in magnitude. False otherwise (i.e. infinite, NaN etc.).
-
isInfinite
public boolean isInfinite()Checks if this field element is infinite in magnitude.- Specified by:
isInfinite
in interfaceField<RealFloat64>
- Returns:
- True if this field element is infinite in magnitude. False otherwise (i.e. finite, NaN, etc.).
-
isNaN
public boolean isNaN()Checks if this field element is NaN in magnitude.- Specified by:
isNaN
in interfaceField<RealFloat64>
- Returns:
- True if this field element is NaN in magnitude. False otherwise (i.e. finite, NaN, etc.).
-
prod
Computes the product of all data of specified array.- Parameters:
values
- Values to compute product of.- Returns:
- The product of all values in
values
.
-
sum
Computes the sum of all data of specified array.- Parameters:
values
- Values to compute product of.- Returns:
- The sum of all values in
values
.
-
wrapArray
Wraps a primitive double array as aRealFloat64
array.- Parameters:
arr
- Array to wrap.- Returns:
- A
RealFloat64
array containing the values ofarr
. Ifarr==null
thennull
will be returned.
-
wrapArray
Wraps aDouble
array as aRealFloat64
array.- Parameters:
arr
- Array to wrap.- Returns:
- A
RealFloat64
array containing the values ofarr
. Ifarr==null
thennull
will be returned.
-
equals
Checks if an object is equal to this Field element.- Overrides:
equals
in classObject
- Parameters:
b
- Object to compare to this Field element.- Returns:
- True if the objects are the same or are both
RealFloat64
's and have equal values.
-
hashCode
-
toString
-