Last active
February 6, 2019 15:42
-
-
Save nelhage/4611306ac5f02e4d0e10b68ae91de0a0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
#include <stdint.h> | |
static float rt(float x) { | |
volatile double g = static_cast<double>(x); | |
return static_cast<float>(g); | |
} | |
int main() { | |
for (uint32_t i = 0; i != (uint32_t)-1; ++i) { | |
float f = *(reinterpret_cast<float*>(&i)); | |
float g = rt(f); | |
uint32_t o = *(reinterpret_cast<uint32_t*>(&g)); | |
if (isnan(f) ? !isnan(g) : f != g) { | |
fprintf(stderr, | |
"BAD: %08x (%f) -> %08x (%f)\n", | |
i, f, o, g); | |
} | |
if ((i & 0xffffff) == 0) { | |
fprintf(stderr, "%08x...\n", i); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment