Skip to content

Instantly share code, notes, and snippets.

@nelhage
Last active February 6, 2019 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nelhage/4611306ac5f02e4d0e10b68ae91de0a0 to your computer and use it in GitHub Desktop.
Save nelhage/4611306ac5f02e4d0e10b68ae91de0a0 to your computer and use it in GitHub Desktop.
#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