Bool b1 = true; bool b2 = false; bool b3 = b1 && b2 // b3 = true AND false = false b3 = b1 b2 // b3 = true OR false = true Unlike short-circuit evaluation of &&, and?: in C, HLSL expressions never short-circuit an evaluation because they are vector operations. All sides of the expression are always evaluated. SURNATUREL, the new High Jewelry collection by Cartier. Rooted in reality and transforming it into the realm of the supernatural. Surpassing reality, Cartier opens the way to a nature reinvented: Surnaturel.
Expressions are sequences of variables and literals punctuated by operators. Operators determine how the variables and literals are combined, compared, selected, and so on. The operators include:
Operator Name | Operators |
Additive and Multiplicative Operators | +, -, *, /, % |
Array Operator | [i] |
Assignment Operators | =, +=, -=, *=, /=, %= |
Binary Casts | C rules for float and int, C rules or HLSL intrinsics for bool |
Bitwise Operators | ~, <<, >>, &, |, ^, <<=, >>=, &=, |=, ^= |
Boolean Math Operators | & &, ||, ?: |
Cast Operator | (type) |
Comma Operator | , |
Comparison Operators | <, >, , !=, <=, >= |
Prefix or Postfix Operators | ++, -- |
Structure Operator | . |
Unary Operators | !, -, + |
Many of the operators are per-component, which means that the operation is performed independently for each component of each variable. For example, a single component variable has one operation performed. On the other hand, a four-component variable has four operations performed, one for each component.
- Size of this PNG preview of this SVG file: 512 × 583 pixels. Other resolutions: 211 × 240 pixels 421 × 480 pixels 527 × 600 pixels 674 × 768 pixels 899 × 1,024 pixels.
- Browse computer hardware parts like 13GOA0B10M020-10, 13GOA0B1AP110-10, 13GOA0B2AP220-10, 13GOA0B6AP180-10, 13GOA0D10M020-1 manufactured by Asus.
All of the operators that do something to the value, such as + and *, work per component.
The comparison operators require a single component to work unless you use the all or any intrinsic function with a multiple-component variable. The following operation fails because the if statement requires a single bool but receives a bool4:
The following operations succeed:
The binary cast operators asfloat, asint, and so on work per component except for asdouble whose special rules are documented.
Selection operators like period, comma, and array brackets do not work per component.
Cast operators change the number of components. The following cast operations show their equivalence:
Additive and Multiplicative Operators
The additive and multiplicative operators are: +, -, *, /, %
The modulus operator returns the remainder of a division. This produces different results when using integers and floating-point numbers. Integer remainders that are fractional will be truncated.
The modulus operator truncates a fractional remainder when using integers.
The % operator is defined only in cases where either both sides are positive or both sides are negative. Unlike C, it also operates on floating-point data types, as well as integers.
Array Operator
The array member selection operator '[i]' selects one or more components in an array. It is a set of square brackets that contain a zero-based index.
The array operator can also be used to access a vector.
By adding an additional index, the array operator can also access a matrix.
The first index is the zero-based row index. The second index is the zero-based column index.
Assignment Operators
The assignment operators are: =, +=, -=, *=, /=
Variables can be assigned literal values:
A4 9200ddr B2 Zhen
Variables can also be assigned the result of a mathematical operation:
A variable can be used on either side of the equals sign:
Division for floating-point variables is as expected because decimal remainders are not a problem.
Be careful if you are using integers that may get divided, especially when truncation affects the result. This example is identical to the previous example, except for the data type. The truncation causes a very different result.
Binary Casts
Casting operation between int and float will convert the numeric value into the appropriate representations following C rules for truncating an int type. Casting a value from a float to an int and back to a float will result in a lossy conversion based on the precision of the target.
Binary casts may also be performed using Intrinsic Functions (DirectX HLSL), which reinterpret the bit representation of a number into the target data type.
Bitwise Operators
HLSL supports the following bitwise operators, which follow the same precedence as C with regard to other operators. The following table describes the operators.
Note
Bitwise operators require Shader Model 4_0 with Direct3D 10 and higher hardware.
Operator | Function |
~ | Logical Not |
<< | Left Shift |
>> | Right Shift |
& | Logical And |
| | Logical Or |
^ | Logical Xor |
<<= | Left Shift Equal |
>>= | Right Shift Equal |
&= | And Equal |
|= | Or Equal |
^= | Xor Equal |
Bitwise operators are defined to operate only on int and uint data types. Attempting to use bitwise operators on float, or struct data types will result in an error.
Boolean Math Operators
The Boolean math operators are: &&, ||, ?:
Unlike short-circuit evaluation of &&, ||, and ?: in C, HLSL expressions never short-circuit an evaluation because they are vector operations. All sides of the expression are always evaluated.
Boolean operators function on a per-component basis. This means that if you compare two vectors, the result is a vector containing the Boolean result of the comparison for each component.
For expressions that use Boolean operators, the size and component type of each variable are promoted to be the same before the operation occurs. The promoted type determines the resolution at which the operation takes place, as well as the result type of the expression. For example an int3 + float expression would be promoted to float3 + float3 for evaluation, and its result would be of type float3.
Cast Operator
An expression preceded by a type name in parenthesis is an explicit type cast. A type cast converts the original expression to the data type of the cast. In general, the simple data types can be cast to the more complex data types (with a promotion cast), but only some complex data types can be cast into simple data types (with a demotion cast).
Only right hand side type casting is legal. For example, expressions such as (int)myFloat = myInt;
are illegal. Use myFloat = (float)myInt;
instead.
The compiler also performs implicit type cast. For example, the following two expressions are equivalent:
Comma Operator
The comma operator (,) separates one or more expressions that are to be evaluated in order. The value of the last expression in the sequence is used as the value of the sequence.
Here is one case worth calling attention to. If the constructor type is accidentally left off the right side of the equals sign, the right side now contains four expressions, separated by three commas.
The comma operator evaluates an expression from left to right. This reduces the right hand side to:
HLSL uses scalar promotion in this case, so the result is as if this were written as follows:
In this instance, leaving off the float4 type from the right side is probably a mistake that the compiler is unable to detect because this is a valid statement.
Comparison Operators
The comparison operators are: <, >, , !=, <=, >=.
Compare values that are greater than (or less than) any scalar value:
Or, compare values equal to (or not equal to) any scalar value:
Or combine both and compare values that are greater than or equal to (or less than or equal to) any scalar value:
Each of these comparisons can be done with any scalar data type.
To use comparison operators with vector and matrix types, use the all or any intrinsic function.
This operation fails because the if statement requires a single bool but receives a bool4:
These operations succeed:
Prefix or Postfix Operators
The prefix and postfix operators are: ++, --. Prefix operators change the contents of the variable before the expression is evaluated. Postfix operators change the contents of the variable after the expression is evaluated.
In this case, a loop uses the contents of i to keep track of the loop count.
Because the postfix increment operator (++) is used, arrayOfFloats[i] is multiplied by 2 before i is incremented. This could be slightly rearranged to use the prefix increment operator. This one is harder to read, although both examples are equivalent.
Because the prefix operator (++) is used, arrayOfFloats[i+1 - 1] is multiplied by 2 after i is incremented.
The prefix decrement and postfix decrement operator (--) are applied in the same sequence as the increment operator. The difference is that decrement subtracts 1 instead of adding 1.
Structure Operator
The structure member selection operator (.) is a period. Given this structure:
It can be read like this:
Each member can be read or written with the structure operator:
Unary Operators
The unary operators are: !, -, +
Unary operators operate on a single operand.
Operator Precedence
When an expression contains more than one operator, operator precedence determines the order of evaluation. Operator precedence for HLSL follows the same precedence as C.
Remarks
Curly braces ({,}) start and end a statement block. When a statement block uses a single statement, the curly braces are optional.
A4 9200ddr B2 Zhou
Related topics
Original file (SVG file, nominally 512 × 583 pixels, file size: 154 KB)
ama
davade
Summary
Description | English: Location of Andhra Pradesh in India. | |
Date | ||
Source | File:India dark grey.svg | |
Author | फ़िलप्रो (Filpro) | |
Other versions |
|
Licensing
This file is licensed under the Creative CommonsAttribution-Share Alike 4.0 International license. | |
|
Captions
'}},'text/plain':{'en':{':'creator'}}},'{'value':{'entity-type':'property','numeric-id':2699,'id':'P2699'},'type':'wikibase-entityid'}':{'text/html':{'en':{':'URL</a>'}},'text/plain':{'en':{':'URL'}}},'{'value':'https://commons.wikimedia.org/wiki/user:%E0%A4%AB%E0%A4%BC%E0%A4%BF%E0%A4%B2%E0%A4%AA%E0%A5%8D%E0%A4%B0%E0%A5%8B','type':'string'}':{'text/html':{'en':{'P2699':'https://commons.wikimedia.org/wiki/user:%E0%A4%AB%E0%A4%BC%E0%A4%BF%E0%A4%B2%E0%A4%AA%E0%A5%8D%E0%A4%B0%E0%A5%8B</a>'}},'text/plain':{'en':{'P2699':'https://commons.wikimedia.org/wiki/user:%E0%A4%AB%E0%A4%BC%E0%A4%BF%E0%A4%B2%E0%A4%AA%E0%A5%8D%E0%A4%B0%E0%A5%8B'}}},'{'value':{'entity-type':'property','numeric-id':4174,'id':'P4174'},'type':'wikibase-entityid'}':{'text/html':{'en':{':'Wikimedia username</a>'}},'text/plain':{'en':{':'Wikimedia username'}}},'{'value':'u092bu093cu093fu0932u092au094du0930u094b','type':'string'}':{'text/html':{'en':{'P4174':'u092bu093cu093fu0932u092au094du0930u094b</a>'}},'text/plain':{'en':{'P4174':'u092bu093cu093fu0932u092au094du0930u094b'}}},'{'value':{'entity-type':'property','numeric-id':2093,'id':'P2093'},'type':'wikibase-entityid'}':{'text/html':{'en':{':'author name string</a>'}},'text/plain':{'en':{':'author name string'}}},'{'value':'u092bu093cu093fu0932u092au094du0930u094b (Filpro)','type':'string'}':{'text/html':{'en':{'P2093':'u092bu093cu093fu0932u092au094du0930u094b (Filpro)'}},'text/plain':{'en':{'P2093':'u092bu093cu093fu0932u092au094du0930u094b (Filpro)'}}}}'>File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment |
---|---|---|---|---|
current | 05:21, 31 October 2019 | 512 × 583 (154 KB) | फ़िलप्रो | Creation of Ladakh and Telangana-Andhra Pradesh border fix. |
13:53, 24 August 2019 | 1,476 × 1,680 (227 KB) | DeluxeVegan | Feel free to update the border alone, but India's size is disproportionate in that map | |
03:57, 8 April 2019 | 539 × 588 (12.8 MB) | Arjunaraoc | Updated with the changed border between Telangana and Andhra Pradesh. Using Survey of India State border shape files from https://indiamaps.gov.in/soiapp/ accessed 8 April 2019 | |
02:03, 5 January 2017 | 1,476 × 1,680 (227 KB) | फ़िलप्रो | Fixes. | |
01:06, 5 January 2017 | 1,476 × 1,680 (227 KB) | फ़िलप्रो | Fix Arunachal Pradesh-Nagaland border. | |
23:21, 22 September 2016 | 1,476 × 1,680 (227 KB) | फ़िलप्रो | colour scheme | |
17:53, 22 August 2016 | 1,594 × 1,868 (227 KB) | फ़िलप्रो | User created page with UploadWizard |
File usage
Global file usage
The following other wikis use this file:
- Usage on am.wikipedia.org
- Usage on awa.wikipedia.org
- Usage on azb.wikipedia.org
- Usage on el.wikivoyage.org
- Usage on fr.wikipedia.org
- Usage on he.wikipedia.org
- Usage on hi.wikipedia.org
- Usage on id.wikipedia.org
- Usage on ks.wikipedia.org
- Usage on lrc.wikipedia.org
- Usage on lv.wikipedia.org
- Usage on mai.wikipedia.org
- Usage on mk.wikipedia.org
- Usage on mn.wikipedia.org
- Usage on my.wikipedia.org
- Usage on ne.wikipedia.org
- Usage on oc.wikipedia.org
- Usage on sd.wikipedia.org
- Usage on simple.wikipedia.org
- Usage on ta.wikipedia.org
- Usage on te.wikipedia.org
- Usage on th.wikipedia.org
- Usage on tl.wikipedia.org
- Usage on uk.wikipedia.org
- Usage on vi.wikipedia.org
- Usage on zh.wikipedia.org