Union copy

"Luís "Luís
Wed Oct 23 09:48:20 PDT 2013


On Wednesday, 23 October 2013 at 16:27:56 UTC, Dicebot wrote:
> I have reproduces the case and it is payload for sure (did you 
> took endianness into account?)

Hmmm, how are you concluding that?

My assertion that the NaN payload was being correctly preserved 
was based on the following:

     union Foo
     {
         double d;
         long l;
     }

     void main()
     {
         Foo src;
         Foo dst1;
         Foo dst2;

         src.l = 0x7ff7a50200000000;
         dst1.l = src.l;
         dst2.d = src.d;

         writef("src.l:\t%x\n", src.l);
         writef("dst1.l:\t%x\n", dst1.l);
         writef("dst2.l:\t%x\n", dst2.l);
         writef("dst1.payload:\t%x\n", getNaNPayload(dst1.d));
         writef("dst2.payload:\t%x\n", getNaNPayload(dst2.d));
     }

Linux, 32-bit:

     $ dmd test.d && ./test
     src.l:     7ff7a50200000000
     dst1.l:   7ff7a50200000000  <- the binary representation
     dst2.l:   7fffa50200000000   <- is different
     dst1.payload:       3d2810    <- but the decoded payloads
     dst2.payload:       3d2810    <- seem to be equal


More information about the Digitalmars-d mailing list