|
From: | Lars Christian Jensen |
Subject: | Re: int/float binary conversion |
Date: | Tue, 13 Sep 2005 12:08:48 +0200 |
On Tue, 13 Sep 2005, Lars Christian Jensen wrote:
The program below prints "f1 = 4.500000, i = 0x08048484, f2 = 0.000000", when compiled with c++ (GCC) 4.0.1 20050727 (Red Hat 4.0.1-5).
Sorry, I forgot the options: -O2 -march=i686
This don't looks like un-defined behaviour to me, but the same program outputs "f1 = 4.500000, i = 0x40900000, f2 = 4.500000", when compiled with other compilers.#include <cstdio> int main() { float f1 = 4.5; int i = *((int*)&f1); float f2 = *((float*)&i); printf("f1 = %f, i = 0x%08x, f2 = %f\n", f1, i, f2); return 0; } -- Lars Christian Jensen
[Prev in Thread] | Current Thread | [Next in Thread] |