cutil_math.h bugs? operator / bug in cutil_math.h

The following code can be found in cutil_math.h in the SDK:

inline __host__ __device__ float2 operator/(float s, float2 a)

{

    float inv = 1.0f / s;

    return a * inv;

}

which means that

float2 foo = 1.0f / make_float2(2.0f, 3.0f);

will result in (2.0f, 3.0f), whereas I would expect (1.0f / 2.0f, 1.0f / 3.0f).

I think that the code in cutil_math.h should be replaced by:

inline __host__ __device__ float2 operator/(float s, float2 a)

{

    return make_float2(s / a.x, s / a.y);

}

The same is true for float3 and float4 divisions.

Any thoughts?

this indeed seems to be suspicious. seems like arguments are in wrong places. had it been (float2 a, float s) the definition would be then more intuitive :-)

this is why in Java language there are no operators overloading ;-) only explicit method calls, this is extra work to type it’s name or to go and see the method definition, but there is no possibility to misinterpret operator meaning then!