[英]Converting 32-bit float to IEEE 80-bit
I'm trying to convert a 32-bit float into an extended precision 80-bit float. 我正在尝试将32位浮点数转换为扩展精度80位浮点数。 I'm using MSVC x86.
我正在使用MSVC x86。 I tried the following inline ASM code:
我尝试了以下内联ASM代码:
void Convert32To80(float *value, void *outValue)
{
__asm
{
fld float ptr [value];
fstp tbyte ptr [outValue];
}
}
Here, void *outValue
is a buffer that is large enough to hold 10 bytes. 在这里,
void *outValue
是一个足以容纳10个字节的缓冲区。 This looks right to me, but it's crashing when it's run. 这对我来说似乎不错,但是运行时却崩溃了。
Any help is appreciated! 任何帮助表示赞赏!
OK, this should do it: 好的,应该这样做:
void Convert32To80(float *value, void *outValue)
{
__asm
{
mov eax,dword ptr [value]
fld dword ptr [eax]
mov ecx,dword ptr [outValue]
fstp tbyte ptr [ecx]
}
}
All I did was wrote some C code to do the same, but for a float to double conversion, looked at the dissasembly and then modified as necessary. 我所做的只是写了一些C代码来执行相同的操作,但是为了进行浮点数到双精度的转换,漫不经心地看了一下,然后根据需要进行了修改。
Note that I am no expert with MSVC and I'm not 100% sure that I can use the EAX and ECX registers like that without saving/restoring them. 请注意,我不是MSVC的专家,我不是100%确定我可以像这样使用EAX和ECX寄存器而不保存/恢复它们。 Others may know more and offer corrections.
其他人可能会了解更多并提供更正。
Updated Note for posterity: Apparently, MSVC 2010 has no type for 80bit floating point types, so the obvious solution in C or C++ code along the lines of 后代更新说明:显然,MSVC 2010没有用于80位浮点类型的类型,因此,在C或C ++代码中,很明显的解决方案如下:
float inValue = 666.666f;
long double outValue = (long double)inValue;
does NOT work, and you are actually forced to directly use assembly language. 不起作用,实际上您被迫直接使用汇编语言。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.