fork(2) download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3.  
  4. uint8_t func(uint32_t num, uint8_t shl) {
  5. return shl * (1 - ((num-(1<<shl)) >> 31));
  6. }
  7.  
  8. uint8_t func0(uint32_t num, uint8_t shl)
  9. {
  10. if (num >= (1 << shl))
  11. {
  12. return shl;
  13. }
  14. else
  15. {
  16. return 0;
  17. }
  18. }
  19.  
  20. int main(void) {
  21. int cnt = 0;
  22. for (uint16_t num = 0 ; num != 256 ; num++) {
  23. for (uint8_t s = 0 ; s != 8 ; s++) {
  24. int a = func0(num, s);
  25. int b = func(num, s);
  26. if (a != b) {
  27. printf("num=%d shl=%d comparison:%d func:%d\n", num, s, a, b);
  28. cnt++;
  29. }
  30. }
  31. }
  32. printf("Number of differences: %d\n", cnt);
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 10320KB
stdin
Standard input is empty
stdout
Number of differences: 0