fork(3) download
  1. #include <stdio.h>
  2.  
  3. // defeat inline optimizations of 'a / b * b' to 'a'
  4. extern double bodge(int base, int divisor) {
  5. return static_cast<double>(base) / static_cast<double>(divisor);
  6. }
  7.  
  8. int main() {
  9. int errors = 0;
  10. for (int b = 1; b < 100; ++b) {
  11. for (int d = 1; d < 100; ++d) {
  12. // b / d * d ... should == b
  13. double res = bodge(b, d) * static_cast<double>(d);
  14. // but it doesn't always
  15. if (res != static_cast<double>(b))
  16. ++errors;
  17. }
  18. }
  19. printf("errors: %d\n", errors);
  20. }
  21.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
errors: 599