c++ - 在Visual Studio中将64位 double 转换为字节数组形式的80位 double

标签 c++ visual-studio-2010 visual-c++ floating-point double

我正在寻找能够在 Visual Studio 中获取 64 位 double 并将其转换为 80-bit extended (IEEE-754) 的代码。双倍的。结果应该存储在 10 字节数组中(我想是小端格式)。原因是我需要将 80 位 double 发送到用 Borland c++ 编写的程序并要求此 double 。但我不知道如何做到这一点,因为我尝试过(基本上分别为 52 位和 11 位的尾数和指数,转换指数,使其在 15 位中偏移 16383,并将尾数填充到 64 位)没有'似乎有效。它是 this question 的倒数。 .

inline void ConvertDblToLongDbl(double dbl, unsigned char aCh[10])
{
__int64 ull= *(__int64*)(&dbl);
    *(unsigned short*)&aCh[8]= (unsigned short)((ull>>52&0x7FF+15360)|  //     exponent, from 11 bits to 15 bits
        ((ull&(__int64)1<<63)?0x8000:0));   // sign, the 16th bit
    ull= ull&0xFFFFFFFFFFFFF;
    *(__int64*)&aCh[0]= ull|0x8000000000000000;
}

谢谢,
中号

最佳答案

内联汇编将是最简单、最快的方法。像这样:

void ConvertDoubleToLongDouble(double value, unsigned char result[10]) {
    __asm {
        fld value;
        mov ebx, result;
        fstp tbyte ptr [ebx];
    }
}

关于c++ - 在Visual Studio中将64位 double 转换为字节数组形式的80位 double ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10327609/

相关文章:

c++ - printf ("... %c ...",'\0' ) 和家人——会发生什么?

C++ 11 线程 API : is there a free implementation for MSVC 2010?

使用 Visual Studio 2012 编译 C 应用程序

c++ - 复杂模型 : no solution

c++ - 在编译时将两个或多个不同大小的数组合并为一个数组

c++ -/MT 选项(MSVCR100.dll 依赖项的静态链接)不适用于 Visual Studio

c++ - C++ 计时的逻辑错误(使用 std::chrono)

c++ - 静态字段初始化顺序

c++ - Boost的lexical_cast从double到string的精度

c# - 在 c# Visual Studio 2010 中检索 Sharepoint 选择字段的值