Sign function


What is the best way to implement sign function in CUDA ( which takes float as input and gives float as output. Here is probably the worst implementation as illustration:

float sign(float x)
if (x < 0.0f) return -1.0f;
if (x == 0.0f) return 0.0f;
if (x > 0.0f) return 1.0f;

CUDA supports both signbit() and copysignf() functions from math.h.

“The signbit() macro shall return a non-zero value if and only if the sign of its argument value is negative.”

And how would you do the 0 part fastest way possible?