Interface DatumMathFunctions

All Known Subinterfaces:
DatumExpressionRoot
All Known Implementing Classes:
DatumSamplesExpressionRoot

public interface DatumMathFunctions
API for datum-related math helper functions.
Since:
2.1
Version:
1.1
Author:
matt
  • Method Summary

    Modifier and Type
    Method
    Description
    default BigInteger
    and(Number n, Number mask)
    Apply a bitwise and operation to an integer number.
    default BigInteger
    andNot(Number n, Number mask)
    Apply a bitwise and operation to an integer number that has had a not operation applied.
    default Number
    avg(Collection<? extends Number> set)
    Compute the average (mean) of a group of numbers.
    default Number
    Round positive numbers away from zero and negative numbers towards zero, to the nearest integer.
    default Number
    ceil(Number n, Number significance)
    Round positive numbers away from zero and negative numbers towards zero, to the nearest integer multiple of a specific significance.
    default BigDecimal
    decimal(Object value)
    Return a BigDecimal for a given value.
    default Number
    Round a number towards zero to the nearest integer.
    default Number
    down(Number n, Number significance)
    Round a number towards zero to the nearest integer multiple of a specific significance.
    default Number
    Round positive numbers towards zero and negative numbers away from zero, to the nearest integer multiple of a specific significance.
    default Number
    floor(Number n, Number significance)
    Round positive numbers towards zero and negative numbers away from zero, to the nearest integer multiple of a specific significance.
    default BigInteger
    integer(Object value)
    Return a BigInteger for a given value.
    default Number
    max(Number n1, Number n2)
    Return the maximum between two number values.
    default Number
    max(Collection<? extends Number> set)
    Find the maximum value in a group of numbers.
    default Number
    min(Number n1, Number n2)
    Return the minimum between two number values.
    default Number
    min(Collection<? extends Number> set)
    Find the minimum value in a group of numbers.
    default Number
    mround(Number n, Number significance)
    Round a number to the nearest integer multiple of a specific significance.
    default Number
    narrow(Number n, Number digits)
    Narrow a number to the smallest possible number type that can exactly represent the given number.
    default Number
    Narrow a number to at minimum a 16-bit value that can exactly represent the given number.
    default Number
    Narrow a number to at minimum a 32-bit value that can exactly represent the given number.
    default Number
    Narrow a number to at minimum a 64-bit value that can exactly represent the given number.
    default Number
    Narrow a number to at minimum an 8-bit value that can exactly represent the given number.
    default BigInteger
    Apply a bitwise not operation to an integer number.
    default BigInteger
    or(Number n, Number mask)
    Apply a bitwise or operation to an integer number.
    default Number
    Round a number to the nearest integer.
    default Number
    round(Number n, Number digits)
    Round a number to a maximum number of decimal digits using the RoundingMode.HALF_UP mode.
    default Number
    roundDown(Number n, Number digits)
    Round a number towards zero to a maximum number of decimal digits.
    default Number
    roundUp(Number n, Number digits)
    Round a number away from zero to a maximum number of decimal digits.
    default BigInteger
    shiftLeft(Number n, Number count)
    Apply a bitwise left-shift operation to an integer number.
    default BigInteger
    Apply a bitwise right-shift operation to an integer number.
    default Number
    sum(Collection<? extends Number> set)
    Compute the sum a group of numbers.
    default boolean
    Test if a bit is set on an integer number.
    default Number
    Round a number towards zero to the nearest integer.
    default Number
    up(Number n, Number significance)
    Round a number towards zero to the nearest integer multiple of a specific significance.
    default BigInteger
    xor(Number n, Number mask)
    Apply a bitwise xor operation to an integer number.
  • Method Details

    • and

      default BigInteger and(Number n, Number mask)
      Apply a bitwise and operation to an integer number.
      Parameters:
      n - the integer number
      mask - the mask
      Returns:
      the result of (n & mask), or n as an integer if mask is null or null if n cannot be converted to an integer
      Since:
      1.1
    • not

      default BigInteger not(Number n)
      Apply a bitwise not operation to an integer number.
      Parameters:
      n - the integer number
      Returns:
      the result of (~n), or n as an integer or null if n cannot be converted to an integer
      Since:
      1.1
    • andNot

      default BigInteger andNot(Number n, Number mask)
      Apply a bitwise and operation to an integer number that has had a not operation applied.
      Parameters:
      n - the integer number
      mask - the mask
      Returns:
      the result of (n & ~mask), or n as an integer if mask is null or null if n cannot be converted to an integer
      Since:
      1.1
    • or

      default BigInteger or(Number n, Number mask)
      Apply a bitwise or operation to an integer number.
      Parameters:
      n - the integer number
      mask - the mask
      Returns:
      the result of (n | mask), or n as an integer if mask is null or null if n cannot be converted to an integer
      Since:
      1.1
    • xor

      default BigInteger xor(Number n, Number mask)
      Apply a bitwise xor operation to an integer number.
      Parameters:
      n - the integer number
      mask - the mask
      Returns:
      the result of (n ^ mask), or n as an integer if mask is null or null if n cannot be converted to an integer
      Since:
      1.1
    • shiftRight

      default BigInteger shiftRight(Number n, Number count)
      Apply a bitwise right-shift operation to an integer number.
      Parameters:
      n - the integer number
      count - the shift distance, in bits
      Returns:
      the result of (n >> count), or n as an integer if count is null or null if n cannot be converted to an integer
      Since:
      1.1
    • shiftLeft

      default BigInteger shiftLeft(Number n, Number count)
      Apply a bitwise left-shift operation to an integer number.
      Parameters:
      n - the integer number
      count - the shift distance, in bits
      Returns:
      the result of (n << count), or n as an integer if count is null or null if n cannot be converted to an integer
      Since:
      1.1
    • testBit

      default boolean testBit(Number n, Number bit)
      Test if a bit is set on an integer number.
      Parameters:
      n - the integer number
      bit - the bit to test
      Returns:
      the result of ((n & (1 << bit)) != 0), or n as an integer if bit is null or null if n cannot be converted to an integer
      Since:
      1.1
    • decimal

      default BigDecimal decimal(Object value)
      Return a BigDecimal for a given value.
      Parameters:
      value - the object to get as a BigDecimal
      Returns:
      the decimal instance, or null if value is null or cannot be parsed as a decimal
    • integer

      default BigInteger integer(Object value)
      Return a BigInteger for a given value.
      Parameters:
      value - the object to get as a BigInteger
      Returns:
      the integer instance, or null if value is null or cannot be parsed as an integer
      Since:
      1.1
    • min

      default Number min(Number n1, Number n2)
      Return the minimum between two number values.
      Parameters:
      n1 - the first number
      n2 - the second number
      Returns:
      the minimum number, or null if both arguments are null
    • max

      default Number max(Number n1, Number n2)
      Return the maximum between two number values.
      Parameters:
      n1 - the first number
      n2 - the second number
      Returns:
      the maximum number, or null if both arguments are null
    • ceil

      default Number ceil(Number n)
      Round positive numbers away from zero and negative numbers towards zero, to the nearest integer.
      Parameters:
      n - the number to round
      Returns:
      the rounded number, or null if n is null
    • ceil

      default Number ceil(Number n, Number significance)
      Round positive numbers away from zero and negative numbers towards zero, to the nearest integer multiple of a specific significance.
      Parameters:
      n - the number to round
      significance - the multiple factor to round to
      Returns:
      the rounded number, or null if n or significance are null
    • floor

      default Number floor(Number n)
      Round positive numbers towards zero and negative numbers away from zero, to the nearest integer multiple of a specific significance.
      Parameters:
      n - the number to round
      Returns:
      the rounded number, or null if n or significance are null
    • floor

      default Number floor(Number n, Number significance)
      Round positive numbers towards zero and negative numbers away from zero, to the nearest integer multiple of a specific significance.
      Parameters:
      n - the number to round
      significance - the multiple factor to round to
      Returns:
      the rounded number, or null if n or significance are null
    • up

      default Number up(Number n)
      Round a number towards zero to the nearest integer.

      This method is a shortcut for calling roundUp(n, 0).

      Parameters:
      n - the number to round
      Returns:
      the rounded number, or null if n is null
      See Also:
    • up

      default Number up(Number n, Number significance)
      Round a number towards zero to the nearest integer multiple of a specific significance.
      Parameters:
      n - the number to round
      significance - the multiple factor to round to
      Returns:
      the rounded number, or null if n or significance are null
    • down

      default Number down(Number n)
      Round a number towards zero to the nearest integer.

      This method is a shortcut for calling roundDown(n, 0).

      Parameters:
      n - the number to round
      Returns:
      the rounded number, or null if n is null
      See Also:
    • down

      default Number down(Number n, Number significance)
      Round a number towards zero to the nearest integer multiple of a specific significance.

      This method rounds using the RoundingMode.DOWN mode.

      Parameters:
      n - the number to round
      significance - the multiple factor to round to
      Returns:
      the rounded number, or null if n or significance are null
    • mround

      default Number mround(Number n, Number significance)
      Round a number to the nearest integer multiple of a specific significance.
      Parameters:
      n - the number to round
      significance - the multiple factor to round to
      Returns:
      the rounded number, or null if n or significance are null
    • round

      default Number round(Number n)
      Round a number to the nearest integer.

      This is a shortcut for calling round(n, 0).

      Parameters:
      n - the number to round
      Returns:
      the rounded number, or null if n is null
    • round

      default Number round(Number n, Number digits)
      Round a number to a maximum number of decimal digits using the RoundingMode.HALF_UP mode.
      Parameters:
      n - the number to round
      digits - the maximum number of decimal digits
      Returns:
      the rounded number, or null if n or digits is null
    • roundUp

      default Number roundUp(Number n, Number digits)
      Round a number away from zero to a maximum number of decimal digits.
      Parameters:
      n - the number to round
      digits - the maximum number of decimal digits
      Returns:
      the rounded number, or null if n or digits is null
    • roundDown

      default Number roundDown(Number n, Number digits)
      Round a number towards zero to a maximum number of decimal digits.
      Parameters:
      n - the number to round
      digits - the maximum number of decimal digits
      Returns:
      the rounded number, or null if n or digits is null
    • narrow

      default Number narrow(Number n, Number digits)
      Narrow a number to the smallest possible number type that can exactly represent the given number.

      If n cannot be narrowed then n is returned.

      Parameters:
      n - the number to narrow
      minBytePower - a minimum power-of-two byte size to narrow to; to; for example 1 would narrow to at most a Short, 2 to at most an Integer or Float, 3 to at most a Long or Double
      Returns:
      the (possibly) narrowed number, or null if n is null
      Since:
      1.1
    • narrow8

      default Number narrow8(Number n)
      Narrow a number to at minimum an 8-bit value that can exactly represent the given number.

      If n cannot be narrowed then n is returned.

      Parameters:
      n - the number to narrow
      Returns:
      the (possibly) narrowed number, or null if n is null
      Since:
      1.1
    • narrow16

      default Number narrow16(Number n)
      Narrow a number to at minimum a 16-bit value that can exactly represent the given number.

      If n cannot be narrowed then n is returned.

      Parameters:
      n - the number to narrow
      Returns:
      the (possibly) narrowed number, or null if n is null
      Since:
      1.1
    • narrow32

      default Number narrow32(Number n)
      Narrow a number to at minimum a 32-bit value that can exactly represent the given number.

      If n cannot be narrowed then n is returned.

      Parameters:
      n - the number to narrow
      Returns:
      the (possibly) narrowed number, or null if n is null
      Since:
      1.1
    • narrow64

      default Number narrow64(Number n)
      Narrow a number to at minimum a 64-bit value that can exactly represent the given number.

      If n cannot be narrowed then n is returned.

      Parameters:
      n - the number to narrow
      Returns:
      the (possibly) narrowed number, or null if n is null
      Since:
      1.1
    • sum

      default Number sum(Collection<? extends Number> set)
      Compute the sum a group of numbers.
      Parameters:
      set - the numbers to sum; if null then null will be returned
      Returns:
      the sum of set
    • avg

      default Number avg(Collection<? extends Number> set)
      Compute the average (mean) of a group of numbers.
      Parameters:
      set - the numbers to average; if null or empty then null will be returned
      Returns:
      the average of set
    • max

      default Number max(Collection<? extends Number> set)
      Find the maximum value in a group of numbers.
      Parameters:
      set - the numbers to find the maximum in; if null or empty then null will be returned
      Returns:
      the maximum of set
    • min

      default Number min(Collection<? extends Number> set)
      Find the minimum value in a group of numbers.
      Parameters:
      set - the numbers to find the minimum in; if null or empty then null will be returned
      Returns:
      the minimum of set