Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <float.h>
- int main(int, char**)
- {
- {
- size_t match[2] = {};
- for (unsigned i = 0; i != ~0; ++i)
- {
- float a = *(float*)(&i);
- match[(1.f / a) * a == 1.f] += 1;
- }
- fprintf(stderr, "na %zu, ma %zu, ra %f\n", match[0], match[1], (double)match[0] / (match[0] + match[1]));
- }
- {
- size_t match[2] = {};
- for (float a = -1.f; a < 1.f; a += FLT_EPSILON)
- {
- match[(1.f / a) * a == 1.f] += 1;
- }
- fprintf(stderr, "na %zu, ma %zu, ra %f\n", match[0], match[1], (double)match[0] / (match[0] + match[1]));
- }
- }
- :!g++ -O2 check_float.cpp && ./a.out
- na 692211593, ma 3602755702, ra 0.161168
- na 2574161, ma 14203055, ra 0.153432
- :!g++ -O2 -ffast-math check_float.cpp && ./a.out
- na 682391430, ma 3612575865, ra 0.158882
- na 2574160, ma 14203056, ra 0.153432
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement