Any type casting for sort int.

Hi All,

Is any alternate type casting for int as we have __float_as_int in CUDA for int from float.
But it is giving some garbage results.

suppose int a = int(600/500); then I got the a value is 1.
but when I use int a = float_as_int (600/500); then I got 15463728 (some garbage value).

why is it so?


__float_as_int does not convert values. It leaves the bit pattern unchanged and reinterprets those bits as an integer. Since float and int have very different representations, the results will be “strange”. See page 90 of the programming guide. And

Hi Jamie K,

Thanks for reply.That’s makes things more understandable .

Could you send the complete name of programming guide where i will get more informations?

Once again lot of thanks


He is referrring to the “Programming guide” that comes with CUDA installation.

Check out the “doc” sub-directory of your CUDA install directory,

Hi All,

I want to reduce or remove type casting in CUDA program.

[b] for(a = 0; a<640 ; ++a)

       i = int(Array[a] + 0.5f);[/b]

Is any way to reduce the overhead of typecasting ?