Skip to content
HactarCE edited this page May 1, 2020 · 3 revisions

Types

Note that all types in NDCA have value semantics, which means that modifying a value in one variable does not have an effect on any other variables. Moving a value from one variable to another will always copy it, which may have an impact on performance if the value is large. Future optimizations may help.

Integer

View methods

Integers are represented using 64-bit signed two's complement. This means that the minimum value is -9223372036854775808 and the maximum value is 9223372036854775807.

Integers are also used to represent booleans values, like in the C programming language; 0 is "falsey" and any other number is "truthy." See Boolean logic for more info.

Integer arithmetic

Integers support the following arithmetic operations (assuming a and b are integers):

  • a + b — addition
  • a - b — subtraction
  • a * b — multiplication
  • a / b — division (rounds toward zero)
  • a % b — remainder
  • a ** b — exponentiation
  • -a — negation

And the following bitwise operations (assuming a and b are integers):

  • a & b — bitwise AND
  • a | b — bitwise OR
  • a ^ b — bitwise XOR
  • a >> b — bitshift right (arithmetic/signed)
  • a >>> b — bitshift right (logical/unsigned)
  • a << b — bitshift left
  • ~a — bitwise complement

NOTE: In the future, the behavior of / and % with negative numbers may be changed.

Integer comparisons

Integers support the following comparisons (assuming a and b are integers):

  • a == b — Does a equal b?
  • a != b — Does a not equal b?
  • a < b — Is a less than b?
  • a > b — Is a greater than b?
  • a <= b — Is a less than or equal to b?
  • a >= b — Is a greater than or equal to b?

Comparisons always result in 1 if true and 0 if false.

Boolean operations

Integers support the following boolean operations:

  • a and b — logical AND
  • a or b — logical OR ("inclusive or")
  • a xor b — logical XOR ("exclusive or")
  • not a — logical NOT

Cell state

View methods

Cell states are represented using unsigned 32-bit integers

Vector

View methods

A vector is a sequence of integers of a fixed length. Vectors have a minimum length of 1 and a maximum length of 6. A vector can be constructed using square brackets containing comma-delimited integer components. For example, [3, -1, 0] is a vector of length 3 with the three components 3, -1, and 0. Vectors can also be constructed using vec() and its variants.

Vector arithmetic

Vectors support all the same arithmetic and bitwise operations as integers by applying them componentwise. For example, [1, 2, 3] + [10, 20, 30] results in [11, 22, 33].

For most operations, when an operation is applied between vectors of different lengths, the shorter vector is first extended using 0. For example, [1, 2] + [10, 20, 30] results in [11, 22, 30]. For multiplication (*) and bitwise AND (&), however, the longer vector is truncated to the length of the shorter one, since the extra components would be zero anyway. So [1, 2, 3] * [1, 2] results in [1, 4], not [1, 4, 0].

Vector comparisons

Vectors support all the same comparisons as integers, by applying them componentwise. When comparing vectors, the shorter vector is first extended using 0. A comparison between vectors compares all components, and is true only if that comparison is true for all components. For example [-1, 0] < [0, 1] is true because -1 < 1 and 0 < 1 are both true. [-1, 1] < [0, 1], however, is false because 0 < 0 is false.

Clone this wiki locally