如何将浮点舍入到最接近的.001

时间:2013-04-10 19:07:02

标签: assembly floating-point x86 rounding

有人可以给我一些关于如何将浮点数舍入到汇编(MASM)中最近的.001的提示吗?我有2个整数。我需要将商显示为浮点数(num_1 / num_2)。我得到浮点算术部分工作,但我无法弄清楚如何舍入结果。非常感谢任何建议!

;calculate the quotient as a floating-point number
    fild    num_1
    fidiv   num_2
    roundps

    ;display the quotient as a floating-point number        
    call    WriteFloat
    call    CrLf

2 个答案:

答案 0 :(得分:1)

您可以将数字缩放1000,然后将其缩小,然后缩小。

答案 1 :(得分:1)

乘以1000(fmul),舍入为整数(frndint),然后除以1000(fdiv)。

roundps指令需要SSE4.1,仅适用于SSE或AVX寄存器,而不适用于FPU的寄存器。