# Thread: Relational Operators + Vectors: What's the deal?

1. ## Relational Operators + Vectors: What's the deal?

Why are the relational operators not allowed to operate on vectors?

2. ## Re: Relational Operators + Vectors: What's the deal?

I assume because they thought < should return a single bool, and couldn't see what that meant for a vector? What's wrong with the lessThan function?

3. ## Re: Relational Operators + Vectors: What's the deal?

Well, there's nothing wrong with the lessThan function. Just seems to me it'd be more convenient and consistent to be able to use operators instead. We have all the arithmetic binary operators, which operate component by component, and they all return a vector of the same length.

No big deal... thought maybe there might be a reason for this that might not be obvious (to me anyway).

4. ## Re: Relational Operators + Vectors: What's the deal?

May be because this is not useful.

5. ## Re: Relational Operators + Vectors: What's the deal?

Originally Posted by CG reference manual
Comparison operators may be applied to numeric vectors. Both operands must be vectors of the same size. The comparison operation is performed in elementwise fashion to produce a bool vector of the same size.
It is useful, I use in some of my shaders, usually like this

Code :
```if(any( float3(1,2,3) < float3(3,2,1)))
{
...
}```

6. ## Re: Relational Operators + Vectors: What's the deal?

Ok, what should such operator compare? Length? Or something like all(lessThen(x, y))? Or should it return a vector of bools?

7. ## Re: Relational Operators + Vectors: What's the deal?

I think he want to compare each vectors component.

If 2 vectors x and x' whose dimension is n:

x = (e1, e2,..., en)
x' = (e1', e2',..., en')

x < x' = (e1 < e1'?, e2 < e2'?, ..., en < en'?) which is vector whose dimension is n

But I am really curious to see a practical example of such operators in a shader.

8. ## Re: Relational Operators + Vectors: What's the deal?

e.g. point inside axis aligned bounding box test?
Code :
```float3 pos = ...;

if( any(float3(0) < pos || pos > float3(1)))
{