[ create a new paste ] login | about

Link: http://codepad.org/lpiYReQF    [ raw code | output | fork ]

AaronMiller - C, pasted on Sep 16:
#include <stdio.h>

int IntSign(int a) {
  return (1 | (a>>31));
}
float FloatSign(float a) {
  return (float)(1 | (((int)a)>>31));
}

int main(int argc, char **argv) {
  float fA, fB;
  int iA, iB;

  iA = 23;
  iB = -42;

  fA = 23.25f;
  fB = -43.725f;

  printf("sign of %d, %d: %d, %d\n", iA, iB, IntSign(iA), IntSign(iB));
  printf("sign of %f, %f: %f, %f\n", fA, fB, FloatSign(fA), FloatSign(fB));

  return 0;
}


Output:
1
2
sign of 23, -42: 1, -1
sign of 23.250000, -43.724998: 1.000000, -1.000000


Create a new paste based on this one


Comments: