casting vector types

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

casting vector types

Jochen Wilhelmy
Hi!

If I have float a; short b; then a = (float)b; works.
If I have float3 a; short3 b; then for a = (float3)b; I get the
following error:

error: C-style cast from vector 'short3' to vector 'float3' of different
size

Is this a bug or correct and if it is correct how do I cast from short3
to float3?

-Jochen

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: casting vector types

Mattias Holm
I do not think this is a bug, this has been default behaviour in GCC and
Clang for some time. IIRC, the rule is that vector casts are bitwise
conversions, and sizeof(float3) != sizeof(short3).

You should be able to do something like this (assuming you use the
ext_vector_extension):

typedef float __attribute__((ext_vector_type(3))) float3;
typedef short __attribute__((ext_vector_type(3))) short3;

float3 a;
short3 b;
a = (float3){(float)b.x, (float)b.y, (float)b.z};

/ Mattias

On 2010-10-10 00:37, Jochen Wilhelmy wrote:

> Hi!
>
> If I have float a; short b; then a = (float)b; works.
> If I have float3 a; short3 b; then for a = (float3)b; I get the
> following error:
>
> error: C-style cast from vector 'short3' to vector 'float3' of different
> size
>
> Is this a bug or correct and if it is correct how do I cast from short3
> to float3?
>
> -Jochen


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev