Class RealFloat32
- All Implemented Interfaces:
Serializable
,Comparable<RealFloat32>
,Field<RealFloat32>
,Ring<RealFloat32>
,Semiring<RealFloat32>
Represents an immutable real number backed by a 32-bit floating-point value.
This class wraps the primitive float
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 RealFloat32
The numerical value-1.0
.static final RealFloat32
The numerical value1.0
.static final RealFloat32
The numerical value representing pi (π), the ratio of the circumference of a circle to its diameter.static final RealFloat32
The numerical value representing the square root of three.static final RealFloat32
The numerical value representing the square root of two.static final RealFloat32
The numerical value10.0
.static final RealFloat32
The numerical value3.0
.static final RealFloat32
The numerical value2.0
.static final RealFloat32
The numerical value0.0
. -
Constructor Summary
ConstructorsConstructorDescriptionRealFloat32
(float value) Constructs a real 32-bit floating point number.RealFloat32
(RealFloat64 value) Constructs a real 32-bit floating point number by casting a real 64-bit floating point. -
Method Summary
Modifier and TypeMethodDescriptionadd
(double b) Sums an element of this field with a real number (associative and commutative).add
(RealFloat32 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
(RealFloat32 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.float
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
(RealFloat32 b) Multiplies two elements of this field (associative and commutative).multInv()
Computes the multiplicative inverse for an element of this field.static RealFloat32
prod
(RealFloat32... values) Computes the product of all data of specified array.static RealFloat32
round
(RealFloat32 n, int decimals) Rounds number to specified number of decimal places.static RealFloat32
sgn
(RealFloat32 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
(RealFloat32 b) Computes difference of two elements of this field.static RealFloat32
sum
(RealFloat32... values) Computes the sum of all data of specified array.toString()
Converts this field element to a string representation.static RealFloat32[]
wrapArray
(float... arr) Wraps a primitive float array as aRealFloat32
array.static RealFloat32[]
Wraps aFloat
array as aRealFloat32
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
-
RealFloat32
public RealFloat32(float value) Constructs a real 32-bit floating point number.- Parameters:
value
- Value of the 32-bit floating point number.
-
RealFloat32
Constructs a real 32-bit floating point number by casting a real 64-bit floating point.- Parameters:
value
- Value of the 32-bit floating point number.
-
-
Method Details
-
getValue
public float 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<RealFloat32>
- 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<RealFloat32>
- 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<RealFloat32>
- 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 if a + 0 = a for any a in the semiring.
- Specified by:
isZero
in interfaceSemiring<RealFloat32>
- 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 if a * 1 = a for any a in the semiring.
- Specified by:
isOne
in interfaceSemiring<RealFloat32>
- 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<RealFloat32>
- 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<RealFloat32>
- Returns:
- The multiplicative identity for this semiring.
-
div
Computes the quotient of two elements of this field.- Specified by:
div
in interfaceField<RealFloat32>
- 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<RealFloat32>
- 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<RealFloat32>
- 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<RealFloat32>
- 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<RealFloat32>
- 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<RealFloat32>
- 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<RealFloat32>
- Returns:
- The additive inverse for this field element.
-
mag
public double mag()Computes the magnitude of this field element.- Specified by:
mag
in interfaceRing<RealFloat32>
- Returns:
- The magnitude of this field element.
-
sqrt
Computes the square root of this field element.- Specified by:
sqrt
in interfaceField<RealFloat32>
- 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<RealFloat32>
- Specified by:
compareTo
in interfaceSemiring<RealFloat32>
- 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<RealFloat32>
- 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<RealFloat32>
- 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<RealFloat32>
- 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<RealFloat32>
- 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 float array as aRealFloat32
array.- Parameters:
arr
- Array to wrap.- Returns:
- A
RealFloat32
array containing the values ofarr
. Ifarr==null
thennull
will be returned.
-
wrapArray
Wraps aFloat
array as aRealFloat32
array.- Parameters:
arr
- Array to wrap.- Returns:
- A
RealFloat32
array containing the values ofarr
. Ifarr==null
thennull
will be returned.
-
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. - Throws:
IllegalArgumentException
- If decimals is less than zero.
-
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
RealFloat32
's and have equal values.
-
hashCode
-
toString
-