Hi,
I’ve got a question regarding the built-in division operator /. Here is the code from the cutil_math.h:
[codebox]
inline host device float3 operator/(float3 a, float s)
{
float inv = 1.0f / s;
return a * inv;
}
inline host device float3 operator/(float s, float3 a)
{
float inv = 1.0f / s;
return a * inv;
}
[/codebox]
If you look at the order of arguments for the two functions, it is different in each case, but the function body is identical. This means, that writing 1.f / xyz (uses the second function) gives the same result as xyz / 1.f (the first function). xyz is a float3 variable. I was kind of upset when I found out this feature/bug that was causing my kernels to crash. I was hoping that 1.f / float3 will return a float3 vector of reciprocals, but instead it returns the original float3 vector divided by 1.f. Can someone clarify the reasons why it is implemented this way? I suppose it is not a bug as it appears in all division operators that are there for some time already, but I does not appear to be very intuitive.
It would also be nice if I could ‘override’ the built-in operator with my own, which would return make_float3( s / a.x, s / a.y, s / a.z ). Is this somehow possible?
Thanks
–jan