# Vector2int16

Not to be confused with:

• `datatype/Vector2`, a more precise and complete implementation for 2D vectors
• `datatype/Vector3int16`, a similar implementation for 3D vectors

Vector2int16 describes a vector in 2D space using a signed 16-bit integer for its components. It is similar to `datatype/Vector2` in that it allows for the same arithmetic operations; however it lacks commonly used vector functions.

For each component:

• The lower bound is -215, or -32,768
• The upper bound is 215 − 1, or 32,767

## Conversion to Vector2

Converting a Vector2int16 to a `Vector2` can be done by passing its components to `Vector2.new`:

``````local function ConvertVector2int16ToVector2(vector16)
return Vector2.new(vector16.X, vector16.Y)
end
``````

Don’t pass a Vector2int16 to `Vector2.new`: The `Vector2.new` constructor interprets a Vector2int16 as a 0 (zero) within its parameters without producing an error. This can lead to silent logic errors if you’re doing something like this:

``````Vector2.new(Vector2int16.new(1, 2, 3)) --> Vector2.new(0, 0, 0)
``````

In order to properly convert to Vector2, you must construct it component-wise as above.

## Constructors

 Vector2int16.new ( number x, ) Creates a new Vector2int16 given the x and y components. Non-integer components are rounded down. The components must fall within the range [-215, 215). If outside this range, integer overflow may occur. For example, providing 32,768 (equal to 215) as a component overflows the 16-bit integer, and so the component will be -32,768 (equal to -215) instead.

## Properties

 integer Vector2int16.X The x-coordinate, also accessible in its lower-case variant.
 integer Vector2int16.Y The y-coordinate, also accessible in its lower-case variant.

## Math Operations

 Vector2int16 Vector2int16 + Vector2int16 Returns a Vector2int16 whose components are the sum of the operands’ respective components.Equivalent to: `Vector2int16.new(lhs.X + rhs.X, lhs.Y + rhs.Y)` Be mindful of bounds with regards to the signed 16-bit integers used to store the components (described above).
 Vector2int16 Vector2int16 - Vector2int16 Returns a Vector2int16 whose components are the difference of the operands’ respective components.Equivalent to: `Vector2int16.new(lhs.X - rhs.X, lhs.Y - rhs.Y)` Be mindful of bounds with regards to the signed 16-bit integers used to store the components (described above).
 Vector2int16 Vector2int16 * Vector2int16 Returns a Vector2int16 whose components are the product of the operands’ respective components.Equivalent to: `Vector2int16.new(lhs.X * rhs.X, lhs.Y * rhs.Y)` Be mindful of bounds with regards to the signed 16-bit integers used to store the components (described above).
 Vector2int16 Vector2int16 * number Returns a Vector2int16 whose components are the product of the Vector2int16’s respective components and the number (factor). This operation is commutative. Equivalent to: `Vector2int16.new(lhs.X * factor, lhs.Y * factor)` Be mindful of bounds with regards to the signed 16-bit integers used to store the components (described above).
 Vector2int16 Vector2int16 / Vector2int16 Returns a Vector2int16 whose components are the quotient of the operands’ respective components.Equivalent to: `Vector2int16.new(lhs.X / rhs.X, lhs.Y / rhs.Y)` Be mindful that the signed 16-bit integers used to store the components cannot store fractional portions of the quotient. The results of the division will always be rounded down.
 Vector2int16 Vector2int16 / number Returns a Vector2int16 whose components are the quotient of the Vector2int16’s respective components and the number (divisor).Equivalent to: `Vector2int16.new(lhs.X / divisor, lhs.Y / divisor)` Be mindful that the signed 16-bit integers used to store the components cannot store fractional portions of the quotient. The results of the division will always be rounded toward zero.