Class NumOperations

java.lang.Object
org.kink_lang.kink.internal.num.NumOperations

public final class NumOperations extends Object
Number operations used in Kink.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    getElemIndex(BigDecimal num, int size)
    Returns the exact int value of the num, if the num is a proper element index in the sequence which has the size size, otherwise returns -1.
    static int
    getElemIndex(Val val, int size)
    Returns the exact int value of the val, if the val is a NumVal and it represents a valid element index exactly in the sequence which has the size size, otherwise returns -1.
    static BigInteger
    Returns an exact BigInteger from the val, if the val is a NumVal and it represents an int number.
    Returns an exact int number from the val, if the val is a NumVal and it represents the exact int number.
    getExactLongBetween(Val val, long min, long max)
    Returns an exact long number from the val, if the val is a NumVal and it represents the exact long number between min and max.
    static int
    getPosIndex(BigDecimal num, int size)
    Returns the exact int value of the num, if the num is a proper pos index in the sequence which has the size size, otherwise returns -1.
    static int
    getPosIndex(Val val, int size)
    Returns the exact int value of the val, if the val is a NumVal and it represents a valid position index exactly in the sequence which has the size size, otherwise returns -1.
    static int
    Returns num.hash.
    static boolean
    isRangePair(BigDecimal from, BigDecimal to, int size)
    Returns whether from and to are proper range indexes of the sequence which has the size size.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • hash

      public static int hash(BigDecimal num)
      Returns num.hash.
      Parameters:
      num - the num to hash.
      Returns:
      the hash used in Kink.
    • getElemIndex

      public static int getElemIndex(BigDecimal num, int size)
      Returns the exact int value of the num, if the num is a proper element index in the sequence which has the size size, otherwise returns -1.
      Parameters:
      num - the num.
      size - the size of a sequence.
      Returns:
      the exact int value of the num, or -1.
    • getElemIndex

      public static int getElemIndex(Val val, int size)
      Returns the exact int value of the val, if the val is a NumVal and it represents a valid element index exactly in the sequence which has the size size, otherwise returns -1.
      Parameters:
      val - the val from which the index is extracted.
      size - the size of a sequence.
      Returns:
      the exact int number of the val, or -1.
    • getPosIndex

      public static int getPosIndex(BigDecimal num, int size)
      Returns the exact int value of the num, if the num is a proper pos index in the sequence which has the size size, otherwise returns -1.
      Parameters:
      num - the num.
      size - the size of a sequence.
      Returns:
      the exact int value of the num, or -1.
    • getPosIndex

      public static int getPosIndex(Val val, int size)
      Returns the exact int value of the val, if the val is a NumVal and it represents a valid position index exactly in the sequence which has the size size, otherwise returns -1.
      Parameters:
      val - the val from which the index is extracted.
      size - the size of a sequence.
      Returns:
      the exact int number of the val, or -1.
    • getExactInt

      public static OptionalInt getExactInt(Val val)
      Returns an exact int number from the val, if the val is a NumVal and it represents the exact int number.
      Parameters:
      val - the val from which the int number is extracted.
      Returns:
      the exact int number, or empty.
    • getExactLongBetween

      public static OptionalLong getExactLongBetween(Val val, long min, long max)
      Returns an exact long number from the val, if the val is a NumVal and it represents the exact long number between min and max.
      Parameters:
      val - the val the long number from which is extracted.
      min - the minimum of the range.
      max - the maximum of the range.
      Returns:
      the exact long number, or empty.
    • getExactBigInteger

      public static BigInteger getExactBigInteger(Val val)
      Returns an exact BigInteger from the val, if the val is a NumVal and it represents an int number.
      Parameters:
      val - the val from which the BigInteger is extracted.
      Returns:
      the exact BigInteger, or null.
    • isRangePair

      public static boolean isRangePair(BigDecimal from, BigDecimal to, int size)
      Returns whether from and to are proper range indexes of the sequence which has the size size.
      Parameters:
      from - the from index.
      to - the to index.
      size - the size of a sequence.
      Returns:
      true if from and to are proper range indexes.