C ++ NaN byte representation changes during assignment

When trying to assign NaN to a variable on an x64 processor

*dest = *(float*)&sourceNaN; 

Where

 unsigned char sourceNaN[] = {00,00, 0xa0, 0x7f}; 

The floating-point commands fld and fstp (visible during disassembly) change 0xa0 bytes to 0xe0. Thus, the receiver has an extra bit. Can someone explain why this is happening? This is a windows application.

Assembly language code:

 005C9B9C mov eax,dword ptr [ebp+10h] 005C9B9F fld dword ptr [ebp-80h] 005C9BA2 fstp dword ptr [eax] 
+6
source share
1 answer

0x7fa00000 is a NaN signal ("sNaN"). 0x7fe00000 is a silent NaN ("qNaN"). I have not heard about this behavior in x86, but in ARM sNaNs are converted to qNaN when used in operations, as well as when the FP exception fails (which is usually ignored). Looks like the same thing is happening here.

The good news is that they are both NaNs. Unless you specifically rely on alarm behavior, everything is going right.

+7
source

Source: https://habr.com/ru/post/979014/


All Articles