Skip to content

Instantly share code, notes, and snippets.

@ashwin
Created June 7, 2012 07:19
Show Gist options
  • Save ashwin/2887145 to your computer and use it in GitHub Desktop.
Save ashwin/2887145 to your computer and use it in GitHub Desktop.
Reinterpret float as int in CUDA
// 1. Using union
__device__ int floatAsInt( float fval )
{
union FloatInt {
float f;
int i;
};
FloatInt fi;
fi.f = fval;
return fi.i;
}
// 2. Using pointer
ival = *( ( int* ) &fval );
// 3. Using CUDA intrinsic function
ival = __float_as_int( fval );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment