Class RealFloat32

java.lang.Object
org.flag4j.algebraic_structures.RealFloat32
All Implemented Interfaces:
Serializable, Comparable<RealFloat32>, Field<RealFloat32>, Ring<RealFloat32>, Semiring<RealFloat32>

public class RealFloat32 extends Object implements Field<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 Details

    • NEGATIVE_ONE

      public static final RealFloat32 NEGATIVE_ONE
      The numerical value -1.0.
    • ZERO

      public static final RealFloat32 ZERO
      The numerical value 0.0.
    • ONE

      public static final RealFloat32 ONE
      The numerical value 1.0.
    • TWO

      public static final RealFloat32 TWO
      The numerical value 2.0.
    • THREE

      public static final RealFloat32 THREE
      The numerical value 3.0.
    • TEN

      public static final RealFloat32 TEN
      The numerical value 10.0.
    • ROOT_TWO

      public static final RealFloat32 ROOT_TWO
      The numerical value representing the square root of two.
    • ROOT_THREE

      public static final RealFloat32 ROOT_THREE
      The numerical value representing the square root of three.
    • PI

      public static final RealFloat32 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

      public RealFloat32(RealFloat64 value)
      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

      public RealFloat32 add(RealFloat32 b)
      Sums two elements of this field (associative and commutative).
      Specified by:
      add in interface Semiring<RealFloat32>
      Parameters:
      b - Second field element in sum.
      Returns:
      The sum of this element and b.
    • sub

      public RealFloat32 sub(RealFloat32 b)
      Computes difference of two elements of this field.
      Specified by:
      sub in interface Ring<RealFloat32>
      Parameters:
      b - Second field element in difference.
      Returns:
      The difference of this field element and b.
    • mult

      public RealFloat32 mult(RealFloat32 b)
      Multiplies two elements of this field (associative and commutative).
      Specified by:
      mult in interface Semiring<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 interface Semiring<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 interface Semiring<RealFloat32>
      Returns:
      True if this value is a multiplicative identity for this semiring. Otherwise, false.
    • getZero

      public RealFloat32 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 interface Semiring<RealFloat32>
      Returns:
      The additive identity for this semiring.
    • getOne

      public RealFloat32 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 interface Semiring<RealFloat32>
      Returns:
      The multiplicative identity for this semiring.
    • div

      public RealFloat32 div(RealFloat32 b)
      Computes the quotient of two elements of this field.
      Specified by:
      div in interface Field<RealFloat32>
      Parameters:
      b - Second field element in quotient.
      Returns:
      The quotient of this field element and b.
    • add

      public RealFloat32 add(double b)
      Sums an element of this field with a real number (associative and commutative).
      Specified by:
      add in interface Field<RealFloat32>
      Parameters:
      b - Real element in sum.
      Returns:
      The sum of this element and b.
    • sub

      public RealFloat32 sub(double b)
      Computes difference of an element of this field and a real number.
      Specified by:
      sub in interface Field<RealFloat32>
      Parameters:
      b - Real value in difference.
      Returns:
      The difference of this ring element and b.
    • mult

      public RealFloat32 mult(double b)
      Multiplies an element of this field with a real number (associative and commutative).
      Specified by:
      mult in interface Field<RealFloat32>
      Parameters:
      b - Real number in product.
      Returns:
      The product of this field element and b.
    • div

      public RealFloat32 div(double b)
      Computes the quotient of an element of this field and a real number.
      Specified by:
      div in interface Field<RealFloat32>
      Parameters:
      b - Real number in quotient.
      Returns:
      The quotient of this field element and b.
    • multInv

      public RealFloat32 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 interface Field<RealFloat32>
      Returns:
      The multiplicative inverse for this field element.
    • addInv

      public RealFloat32 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 interface Ring<RealFloat32>
      Returns:
      The additive inverse for this field element.
    • mag

      public double mag()
      Computes the magnitude of this field element.
      Specified by:
      mag in interface Ring<RealFloat32>
      Returns:
      The magnitude of this field element.
    • sqrt

      public RealFloat32 sqrt()
      Computes the square root of this field element.
      Specified by:
      sqrt in interface Field<RealFloat32>
      Returns:
      The square root of this field element.
    • sgn

      public static RealFloat32 sgn(RealFloat32 a)
      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

      public int compareTo(RealFloat32 b)
      Compares this element of the ordered field with b.
      Specified by:
      compareTo in interface Comparable<RealFloat32>
      Specified by:
      compareTo in interface Semiring<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 than b.
    • doubleValue

      public double doubleValue()
      Converts this semiring value to an equivalent double value.
      Specified by:
      doubleValue in interface Semiring<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 interface Field<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 interface Field<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 interface Field<RealFloat32>
      Returns:
      True if this field element is NaN in magnitude. False otherwise (i.e. finite, NaN, etc.).
    • prod

      public static RealFloat32 prod(RealFloat32... values)
      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

      public static RealFloat32 sum(RealFloat32... values)
      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

      public static RealFloat32[] wrapArray(float... arr)
      Wraps a primitive float array as a RealFloat32 array.
      Parameters:
      arr - Array to wrap.
      Returns:
      A RealFloat32 array containing the values of arr. If arr==null then null will be returned.
    • wrapArray

      public static RealFloat32[] wrapArray(Float... arr)
      Wraps a Float array as a RealFloat32 array.
      Parameters:
      arr - Array to wrap.
      Returns:
      A RealFloat32 array containing the values of arr. If arr==null then null will be returned.
    • round

      public static RealFloat32 round(RealFloat32 n, int decimals)
      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

      public boolean equals(Object b)
      Checks if an object is equal to this Field element.
      Overrides:
      equals in class Object
      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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Converts this field element to a string representation.
      Overrides:
      toString in class Object
      Returns:
      A string representation of this field element.