问题描述
在MSVC win32/win64中从扩展精度浮点数(80位值,在某些编译器中也称为long double
)到双精度(64位)转换的最可移植,最正确"的方法是什么? /p>
MSVC当前(截至2010年)假定long double
是double
的同义词.
我可能可以在内联汇编中编写fld
/fstp
汇编程序对,但是内联汇编不适用于MSVC中的win64代码.我是否需要将此汇编代码移动到单独的.asm文件?真的是这样,没有好的解决方法吗?
这只是在x86代码中完成的...
.686P
.XMM
_TEXT SEGMENT
EXTRN __fltused:DWORD
PUBLIC _cvt80to64
PUBLIC _cvt64to80
_cvt80to64 PROC
mov eax, dword ptr [esp+4]
fld TBYTE PTR [eax]
ret 0
_cvt80to64 ENDP
_cvt64to80 PROC
mov eax, DWORD PTR [esp+12]
fld QWORD PTR [esp+4]
fstp TBYTE PTR [eax]
ret 0
_cvt64to80 ENDP
ENDIF
_TEXT ENDS
END
What is the most portable and "right" way to do conversion from extended precision float (80-bit value, also known as long double
in some compilers) to double (64-bit) in MSVC win32/win64?
MSVC currently (as of 2010) assumes that long double
is double
synonym.
I could probably write fld
/fstp
assembler pair in inline asm, but inline asm is not available for win64 code in MSVC. Do I need to move this assembler code to separate .asm file? Is that really so there are no good solution?
Just did this in x86 code...
.686P
.XMM
_TEXT SEGMENT
EXTRN __fltused:DWORD
PUBLIC _cvt80to64
PUBLIC _cvt64to80
_cvt80to64 PROC
mov eax, dword ptr [esp+4]
fld TBYTE PTR [eax]
ret 0
_cvt80to64 ENDP
_cvt64to80 PROC
mov eax, DWORD PTR [esp+12]
fld QWORD PTR [esp+4]
fstp TBYTE PTR [eax]
ret 0
_cvt64to80 ENDP
ENDIF
_TEXT ENDS
END
这篇关于在MSVC中将扩展的精度浮点数(80位)转换为双精度(64位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!