Float values are wrong in union

jkpl via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 21 21:50:07 PDT 2016


On Monday, 22 August 2016 at 04:37:50 UTC, stunaep wrote:
> 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

Ok on linux, 0x7fb00000 is written, I tested under linux x86_64 
with latest dmd beta, ldc and also gdc.

Which compiler and version do you use ?
Which OS and archi ?


More information about the Digitalmars-d-learn mailing list