Sign

From Odwiki

Jump to: navigation, search

Simple, but useful. And for some reason, VEX doesn't have it. The macro versions may or may not perform faster (the optimizer may inline the funtion versions anyway; not sure).

#define SIGN(v)   (float)( v < 0. ? -1. : 1. )
#define SIGNI(v)  (int)( v < 0 ? -1 : 1 ) 

float sign(float v)  { return v<0.?-1.0:1.0; }
int   signI(int v)   { return v<0?-1:1; }
© 2009 od[force].net | advertise