Share via


Short Vector Library

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

The Short Vector Library provides types similar to the Vector Type defined in HLSL. A short vector provides definitions that are useful for programming short vectors generically.

Operators

Any unary or binary operation which is overloadable and valid between two C++ numerical types is valid for the short vector types. For binary operators, the two vectors must have the same size and the result is a vector of the same size. The operators are described in the following table.

Binary operators

All types: +, -, *, /,

Integer types: %, ^, |, &, <<, >>

Relational operators

== and !=

Compound assignment operator

All types: +=, -=, *=, /=

Integer types: %=, ^=, |=, &=, <<=, >>=

Increment and decrement operators

Integer types only: ++, --, both prefix and postfix.

Bitwise NOT operator (~)

Integer types only.

Unary - operator

All types except unorm and uint types.

norm and unorm types

The norm and unorm types are scalar types that limit the range of float values, called clamping. These types can be explicitly constructed from other scalar types. In casting, the value is first cast to float then clamped to the respective region allowed by norm [-1.0…1.0] or unorm [0.0…1.0]. Casting from +/- infinity returns +=1. Casting from NaN is undefined. A norm can be implicitly constructed from a unorm and there is no loss of data. The implicit conversion operator to float is defined on these types. Binary operators are defined between these types and other built-in scalar types such as float and int: +, -, *, /, ==, !=, >, <, >=, <=. The compound assignment operators are also supported: +=, -=, *=, /=. The unary negation operator (-) is defined for norm types.

Swizzling Expressions

The Short Vector Library supports the vector_type.identifier accessor to access the components of a short vector. (Indexing of the vector is not supported.) The identifier, known as a swizzling expression, specifies the components of the vector. The expression can be an l-value or an r-value. Individual characters in indent may be: x,y,z,w,r,g,b,a,0,1. “x” means zeroth component, “y” means first, etc., and rgba is synonymous for xyzw. 0 and 1 return a constant 0 and 1. Single component accessors, such as “x”, “y”, etc., return a value type. Multi-component accessors return a short vector type. The following table shows some swizzling expressions and their indexed equivalents. (Note that indexing is not supported. The indexing is used for explanation purposes.)

Swizzling expression

Index expression

double4 va = myDouble2.y0x1;

double4 va(myDouble2[1], 0, myDouble2[0], 1);

double4 vb = myDouble4.xxww;

double4 vb(myDouble4[0], myDouble4[0], myDouble4[3], myDouble2[3]);

double4 vc = myDouble3.rgb1;

double4 vc(myDouble3[0], myDouble4[1], myDouble4[2], 1);

In This Section

double_2 Class

double_3 Class

double_4 Class

float_2 Class

float_3 Class

float_4 Class

int_2 Class

int_3 Class

int_4 Class

norm_2 Class

norm_3 Class

unorm_4 Class

short_vector Structure

short_vector_traits Structure

uint_2 Class

uint_3 Class

uint_4 Class

unorm_2 Class

unorm_3 Class

unorm_4 Class