SiPlus

Crazy way of getting a float's sign

Jan 13th, 2014
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.16 KB | None | 0 0
  1. float f = -0.0f;
  2. unsigned int b = *((unsigned int *)(&f));
  3. int em = b & 0x7fffffff;
  4. int sign = ((((b >> 31) ^ 1) << 1) - 1) * ((unsigned int)(em ^ -em) >> 31);
Advertisement
Add Comment
Please, Sign In to add comment