Commit 68eec493 authored by Edouard Gomez's avatar Edouard Gomez

noise tools: get rid of aliasing properly

parent e3e35f19
......@@ -11,6 +11,6 @@ noiseprofile: noiseprofile.c
$(CC) $(CFLAGS) noiseprofile.c -lm -o $@
floatdump: floatdump.c
$(CC) $(CFLAGS) -fno-strict-aliasing floatdump.c -o $@
$(CC) $(CFLAGS) floatdump.c -o $@
.PHONY: all clean
......@@ -4,12 +4,11 @@
int main(int argc, char *arg[])
{
float input;
fscanf(stdin, "%f", &input);
// silly bugger needs big endian floats, so swap:
uint32_t i = *(uint32_t *)&input;
i = ((i & 0xffff0000u) >> 16) | ((i & 0x0000ffffu) << 16);
i = ((i & 0xff00ff00u) >> 8) | ((i & 0x00ff00ffu) << 8);
fprintf(stdout, "%08X", i);
exit(0);
union { float f; uint32_t i;} input;
fscanf(stdin, "%f", &input.f);
input.i = ((input.i & 0xffff0000u) >> 16) | ((input.i & 0x0000ffffu) << 16);
input.i = ((input.i & 0xff00ff00u) >> 8) | ((input.i & 0x00ff00ffu) << 8);
fprintf(stdout, "%08X", input.i);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment