#include <stdio.h>
// defeat inline optimizations of 'a / b * b' to 'a'
extern double bodge(int base, int divisor) {
return static_cast<double>(base) / static_cast<double>(divisor);
}
int main() {
int errors = 0;
for (int b = 1; b < 100; ++b) {
for (int d = 1; d < 100; ++d) {
// b / d * d ... should == b
double res = bodge(b, d) * static_cast<double>(d);
// but it doesn't always
if (res != static_cast<double>(b))
++errors;
}
}
printf("errors: %d\n", errors);
}
ICAgICNpbmNsdWRlIDxzdGRpby5oPgoKICAgIC8vIGRlZmVhdCBpbmxpbmUgb3B0aW1pemF0aW9ucyBvZiAnYSAvIGIgKiBiJyB0byAnYScKICAgIGV4dGVybiBkb3VibGUgYm9kZ2UoaW50IGJhc2UsIGludCBkaXZpc29yKSB7CiAgICAgICAgcmV0dXJuIHN0YXRpY19jYXN0PGRvdWJsZT4oYmFzZSkgLyBzdGF0aWNfY2FzdDxkb3VibGU+KGRpdmlzb3IpOwogICAgfQoKICAgIGludCBtYWluKCkgewogICAgICAgIGludCBlcnJvcnMgPSAwOwogICAgICAgIGZvciAoaW50IGIgPSAxOyBiIDwgMTAwOyArK2IpIHsKICAgICAgICAgICAgZm9yIChpbnQgZCA9IDE7IGQgPCAxMDA7ICsrZCkgewogICAgICAgICAgICAgICAgLy8gYiAvIGQgKiBkIC4uLiBzaG91bGQgPT0gYgogICAgICAgICAgICAgICAgZG91YmxlIHJlcyA9IGJvZGdlKGIsIGQpICogc3RhdGljX2Nhc3Q8ZG91YmxlPihkKTsKICAgICAgICAgICAgICAgIC8vIGJ1dCBpdCBkb2Vzbid0IGFsd2F5cwogICAgICAgICAgICAgICAgaWYgKHJlcyAhPSBzdGF0aWNfY2FzdDxkb3VibGU+KGIpKQogICAgICAgICAgICAgICAgICAgICsrZXJyb3JzOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHByaW50ZigiZXJyb3JzOiAlZFxuIiwgZXJyb3JzKTsKICAgIH0K