Skip to main content

Integer Operations

There are four supported signed integer datatypes, TINYINT (8 bits), SMALLINT (16 bits), INTEGER (32 bits), and BIGINT (64 bits). Each has an unsigned counterpart: TINYINT UNSIGNED, SMALLINT UNSIGNED, INTEGER UNSIGNED, and BIGINT UNSIGNED.

The legal operations are + (plus, unary and binary), - (minus, unary and binary), * (multiplication), / (division), % (modulus). Unary minus (negation) cannot be applied to unsigned values.

Modulus involving negative numbers happens as follows:

For: mod = x % y

  • if x >= 0 and y > 0 then: x - (floor(x / y) * y)
  • if x >= 0 and y < 0 then: x % abs(y)
  • if x < 0 and y > 0 then: - abs(x) % y
  • if x < 0 and y < 0 then: - abs(x) % abs(y)

Example:

mod = x % y
xymod
8 3 2
8 -3 2
-8 3 -2
-8 -3 -2

Casting a string to an integer type will produce a runtime error if the string cannot be interpreted as a number.

Division or modulus by zero cause a runtime error.

Operations that cause integer overflow or underflow (example: multiplication or division of minimum integer value by -1) produce run time errors.

Predefined functions on integer values

Predefined functions on integer values
FunctionDescription
ABS(value)return absolute value.
DIV_NULL(numerator, denominator)Like division, but returns NULL when the denominator is zero, or when the division overflows (example: dividing the minimum TINYINT value -128 by -1).
MOD(left, right)integer modulus. Same as left % right.
SEQUENCE(start, end)returns an array of integers from start to end (inclusive). If end < start, an empty array is returned. If any of the arguments are NULL, NULL is returned.

Operations not supported

Non-deterministic functions, such as RAND are currently not supported in DBSP.