Sid*_*sef 2 assembly masm rounding fpu irvine32
我有我的数字 1.010101101,数字的类型是 REAL8,我尝试使用默认的舍入方法“四舍五入到最接近的偶数”,我看到了很多例子,它都是关于四舍五入和使用 frndint 但经过大量搜索我意识到这不是默认舍入我是对还是错?
如果是错误的,请您向我解释如何使用 MASM 程序集进行操作??
这是我的代码:
.686
.model flat,stdcall
.stack 4096
include irvine32.inc
include macros.inc
include floatio.inc
.data
R REAL8 1.010101101
.code
main proc
finit
call ShowFPUStack
fld R
call ShowFPUStack
frndint
call ShowFPUStack
exit
main endp
end main
Run Code Online (Sandbox Code Playgroud)
这是我的 FPU 堆栈
------ FPU Stack ------
------ FPU Stack ------
ST(0): +1.0101011E+000
------ FPU Stack ------
ST(0): +1.0000000E+000
Run Code Online (Sandbox Code Playgroud)
x87 FPU 在硬件中实现了四种舍入方法。那些是 :
The "Round to nearest (even)" method is used by default by the FPU, so there's a high chance you're already using it. The rounding mode is taken into account when the FPU is making calculations, and conversions between different floating-point formats (32, 64, and 80 bits in this case).
The rounding mode is controlled by the x87 Control Word. You can set the new value with the FLDCW instruction, or get the current value via FSTCW for verification. For more information about the instructions and the format of the word, please see 8.1.5 of the Intel Basic Architecture manual.
However, please do note that the control word is supposed to be controlled only by operating system software, not by applications themselves. If you choose to change the control word, make sure you restore it before quitting your program.
FRNDINT is used to round a floating-point value currently on top of the stack to the nearest integral value. With rounding to even, the result of rounding 1.010101101 will be 1. However, if you turn on rounding towards positive infinity, then the result will be 2.