Class RealInt32

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

public class RealInt32 extends Object implements Ring<RealInt32>

A real number backed by a 32-bit integer number. Immutable.

This class wraps the primitive int type.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final RealInt32
    The numerical value -1.
    static final RealInt32
    The numerical value 1.
    static final RealInt32
    The numerical value 10.
    static final RealInt32
    The numerical value 4.
    static final RealInt32
    The numerical value 2.
    static final RealInt32
    The numerical value 0.
  • Constructor Summary

    Constructors
    Constructor
    Description
    RealInt32(int value)
    Constructs a real 32-bit floating point number.
    Constructs a real 32-bit integer number from a RealInt16.
  • Method Summary

    Modifier and Type
    Method
    Description
    Sums two elements of this field (associative and commutative).
    Computes the additive inverse for an element of this field.
    int
    Compares this element of the ordered ring with b.
    double
    Converts this semiring value to an equivalent double value.
    boolean
    Checks if an object is equal to this ring element.
    Gets the multiplicative identity for this semiring.
    float
    Gets the value of this field element.
    Gets the additive identity for this semiring.
    int
     
    boolean
    Checks if this value is a multiplicative identity for this semiring.
    boolean
    Checks if this value is an additive identity for this semiring.
    double
    mag()
    Computes the magnitude of this ring element.
    Multiplies two elements of this field (associative and commutative).
    static RealInt32
    Evaluates the signum or sign function on a ring element.
    Computes difference of two elements of this field.
    Converts this ring element to a string representation.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.flag4j.algebraic_structures.Ring

    abs, conj
  • Field Details

    • NEGATIVE_ONE

      public static final RealInt32 NEGATIVE_ONE
      The numerical value -1.
    • ZERO

      public static final RealInt32 ZERO
      The numerical value 0.
    • ONE

      public static final RealInt32 ONE
      The numerical value 1.
    • TWO

      public static final RealInt32 TWO
      The numerical value 2.
    • THREE

      public static final RealInt32 THREE
      The numerical value 4.
    • TEN

      public static final RealInt32 TEN
      The numerical value 10.
  • Constructor Details

    • RealInt32

      public RealInt32(int value)
      Constructs a real 32-bit floating point number.
      Parameters:
      value - Value of the integer number.
    • RealInt32

      public RealInt32(RealInt16 value)
      Constructs a real 32-bit integer number from a RealInt16.
      Parameters:
      value - Value of the 32-bit integer number.
  • Method Details

    • getValue

      public float getValue()
      Gets the value of this field element.
      Returns:
      The value of this field element.
    • add

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

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

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

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

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

      public RealInt32 addInv()

      Computes the additive inverse for an element of this field.

      An element -x is an additive inverse for a filed element x if -x + x = 0 where 0 is the additive identity.

      Specified by:
      addInv in interface Ring<RealInt32>
      Returns:
      The additive inverse for this ring element.
    • mag

      public double mag()
      Computes the magnitude of this ring element.
      Specified by:
      mag in interface Ring<RealInt32>
      Returns:
      The magnitude of this ring element.
    • sgn

      public static RealInt32 sgn(RealInt32 a)
      Evaluates the signum or sign function on a ring element.
      Parameters:
      a - Value to evaluate signum function on.
      Returns:
      The output of the signum function evaluated on a.
    • compareTo

      public int compareTo(RealInt32 b)
      Compares this element of the ordered ring with b.
      Specified by:
      compareTo in interface Comparable<RealInt32>
      Specified by:
      compareTo in interface Semiring<RealInt32>
      Parameters:
      b - Second element of the ordered ring.
      Returns:
      An int value:
      • 0 if this ring element is equal to b.
      • invalid input: '<' 0 if this ring element is less than b.
      • > 0 if this ring element is greater than b.
      • Hence, this method returns zero if and only if the two ring elements are equal, a negative value if and only the ring element it was called on is less than b and positive if and only if the ring 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<RealInt32>
      Returns:
      A double value equivalent to this semiring element.
    • equals

      public boolean equals(Object b)
      Checks if an object is equal to this ring element.
      Overrides:
      equals in class Object
      Parameters:
      b - Object to compare to this ring element.
      Returns:
      True if the objects are the same or are both RealInt32's and have equal values.
    • hashCode

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

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