Class RealInt16

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

public class RealInt16 extends Object implements Ring<RealInt16>

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

This class wraps the primitive short type.

See Also:
  • Field Summary

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

    Constructors
    Constructor
    Description
    RealInt16(short value)
    Constructs a real 16-bit integer number.
  • Method Summary

    Modifier and Type
    Method
    Description
    Sums two elements of this ring (associative and commutative).
    Computes the additive inverse for an element of this ring.
    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.
    short
    Gets the value of this ring 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 ring (associative and commutative).
    static RealInt16
    Evaluates the signum or sign function on a ring element.
    Computes difference of two elements of this ring.
    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 RealInt16 NEGATIVE_ONE
      The numerical value -1.
    • ZERO

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

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

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

      public static final RealInt16 THREE
      The numerical value 3.
    • TEN

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

    • RealInt16

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

    • getValue

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

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

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

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

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

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

      public RealInt16 addInv()

      Computes the additive inverse for an element of this ring.

      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<RealInt16>
      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<RealInt16>
      Returns:
      The magnitude of this ring element.
    • sgn

      public static RealInt16 sgn(RealInt16 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:
      • Returns RealInt16.ZERO if a.getValue() == 0.
      • Returns RealInt16.ONE if a.getValue() > 0.
      • Returns RealInt16.NEGATIVE_ONE if a.getValue() < 0.
    • compareTo

      public int compareTo(RealInt16 b)
      Compares this element of the ordered ring with b.
      Specified by:
      compareTo in interface Comparable<RealInt16>
      Specified by:
      compareTo in interface Semiring<RealInt16>
      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<RealInt16>
      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 RealInt16'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.