Class RealFloat64

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

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

    • NEGATIVE_ONE

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

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

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

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

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

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

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

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

      public static final RealFloat64 PI
      The numerical value representing pi (π), the ratio of the circumference of a circle to its diameter.
  • Constructor Details

    • RealFloat64

      public RealFloat64(RealFloat32 value)
      Constructs a new RealFloat64 instance with the specified RealFloat32 value.
      Parameters:
      value - the RealFloat32 value to be converted and stored.
    • RealFloat64

      public RealFloat64(double value)
      Constructs a new RealFloat64 instance with the specified double value.
      Parameters:
      value - the double value to be stored.
  • Method Details

    • round

      public static RealFloat64 round(RealFloat64 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. If !Double.isFinite(n.value) then no rounding will be performed and an unmodified n 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

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

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

      public RealFloat64 mult(RealFloat64 b)
      Multiplies two elements of this field (associative and commutative).
      Specified by:
      mult in interface Semiring<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 if a + 0 = a for any a in the semiring.

      Specified by:
      isZero in interface Semiring<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 if a * 1 = a for any a in the semiring.

      Specified by:
      isOne in interface Semiring<RealFloat64>
      Returns:
      True if this value is a multiplicative identity for this semiring. Otherwise, false.
    • getZero

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

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

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

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

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

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

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

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

      public RealFloat64 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<RealFloat64>
      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<RealFloat64>
      Returns:
      The magnitude of this field element.
    • sqrt

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

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

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

      public static RealFloat64 prod(RealFloat64... 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 RealFloat64 sum(RealFloat64... 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 RealFloat64[] wrapArray(double... arr)
      Wraps a primitive double array as a RealFloat64 array.
      Parameters:
      arr - Array to wrap.
      Returns:
      A RealFloat64 array containing the values of arr. If arr==null then null will be returned.
    • wrapArray

      public static RealFloat64[] wrapArray(Double[] arr)
      Wraps a Double array as a RealFloat64 array.
      Parameters:
      arr - Array to wrap.
      Returns:
      A RealFloat64 array containing the values of arr. If arr==null then null will be returned.
    • 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 RealFloat64's and have equal values.
    • hashCode

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

      public String toString()
      Returns a string representation of this RealFloat64 instance.
      Overrides:
      toString in class Object
      Returns:
      a string representing the value of this instance.