fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define SR32(value, shift) ((value) >> ((shift) & 0x1f))
  5. #define USR32(value, shift) ((int32_t) (((uint32_t) (value)) >> ((shift) & 0x1f)))
  6.  
  7. float signum(float x)
  8. {
  9. return (float)(1 + (((*(int32_t*)&x) >> 31) << 1));
  10. }
  11.  
  12. int32_t signum2(int32_t i)
  13. {
  14. return SR32(i, 31) | USR32(-i, 31);
  15. }
  16.  
  17. int main() {
  18. std::cout << signum(0) << std::endl;
  19. std::cout << signum2(0) << std::endl;
  20. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
1
0