On Thursday, 5 March 2015 at 20:06:55 UTC, Taylor Hillegeist wrote:
On Thursday, 5 March 2015 at 20:03:09 UTC, Benjamin Thaut wrote:
Am 05.03.2015 um 21:00 schrieb Taylor Hillegeist:
How to I cast a Int to float without changing its binary representation?

int someValue = 5;
float sameBinary = *(cast(float*)cast(void*)&someValue);

ahh of course! lol :)

I think I read somewhere you don't want to use unions like this, but I think it is more because you generally don't want to reinterpret bits.

import std.stdio;
void main() {
        union Fi {
                float f;
                int i;
        }

        Fi fi;
        fi.i = 65;
        writeln(fi.f);
}

Reply via email to