Float values are wrong in union
stunaep via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Aug 21 21:37:50 PDT 2016
I made a union to convert between int bits and floats, but the
values are coming out wrong sometimes. This is working without
issue in other languages so I'm really stumped. Here's an example:
>union test { int i; float f; }
>test t = { i : 0x7fb00000};
>float t2 = t.f;//int bits 0x7fb00000 as float
>test t3 = { f : t2 };
>writefln("%x", t3.i);//prints 7ff00000 NOT 0x7fb00000
More information about the Digitalmars-d-learn
mailing list