Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 31st, 2012  |  syntax: None  |  size: 0.60 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Convert 64-bit double to 80-bit double in byte array form in visual studio
  2. inline void ConvertDblToLongDbl(double dbl, unsigned char aCh[10])
  3. {
  4. __int64 ull= *(__int64*)(&dbl);
  5.     *(unsigned short*)&aCh[8]= (unsigned short)((ull>>52&0x7FF+15360)|  //     exponent, from 11 bits to 15 bits
  6.         ((ull&(__int64)1<<63)?0x8000:0));   // sign, the 16th bit
  7.     ull= ull&0xFFFFFFFFFFFFF;
  8.     *(__int64*)&aCh[0]= ull|0x8000000000000000;
  9. }
  10.        
  11. void ConvertDoubleToLongDouble(double value, unsigned char result[10]) {
  12.     __asm {
  13.         fld value;
  14.         mov ebx, result;
  15.         fstp tbyte ptr [ebx];
  16.     }
  17. }