cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

Fr4nz
Journeyman III

Error when using "==" operator on uint4 variable

Let's suppose we have this code:

uint4 var;

instructions....

if(var == 0)

.....



compiler gives me this error:

error: expression must have arithmetic or pointer type
              if(var == 0)


Nothing changes if I do an explicit cast, (uint4), over 0 or I use (0,0,0,0) instead of 0.

I think this is not correct, because section 6.3.e of OpenCL specs says that the "==" operator should work also on vector types and if the operand types doesn't match, an implicit conversion will be done on one of the operands.

Same problem applies for "!=" operator.

 

 

0 Likes
4 Replies
omkaranathan
Adept I

Its not the operator, but the usage of  if condition which is causing the problem here.

As the error message says, if condition requires the arguments to be arithmetic, enum, or pointer type.

You can use any() or all() function, if the resultant conditional expression is a vector.


0 Likes

Originally posted by: omkaranathan Its not the operator, but the usage of  if condition which is causing the problem here.

 

As the error message says, if condition requires the arguments to be arithmetic, enum, or pointer type.

 

You can use any() or all() function, if the resultant conditional expression is a vector.

 

 

Uhm, I don't think this point is clear to me: why if I use an int/uint variable it's all ok, but if I use a vector type then it's not? Shouldn't be both "arithmetic types"?

And if not, then how I can test if a vectorized variable has all components equal to zero? any() and all() doesn't give me this information...

0 Likes

if you use == operator with uint4 data type you get four bool result and you mus specify logical operator between them.

0 Likes

Uhm, I don't think this point is clear to me: why if I use an int/uint variable it's all ok, but if I use a vector type then it's not? Shouldn't be both "arithmetic types"?

 

And if not, then how I can test if a vectorized variable has all components equal to zero? any() and all() doesn't give me this information...



Write something like-

if(all(var==(uint4)(0)))

0 Likes