Floating point division in a batch file

后端 未结 8 923
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-27 21:48

I need to do a floating-point division in a dos batch.

I didn\'t find a way to do it. Something like this :

SET /A Res=10/3

returns

8条回答
  •  醉话见心
    2020-11-27 22:13

    I recently came across this batch file to compute an approximation of Pi. There is a DivideByInteger label that might be useful to you: Stupid-Coding-Tricks-A-Batch-of-Pi

    It uses a set of MaxQuadIndex variables, each containing a four-digit number (quadruple), in order to store the entire result. The code allows division by an integer between 1 and 10000, inclusive.

    :DivideByInteger
        if defined PiDebug echo.DivideByInteger %1 %2
        set /a DBI_Carry = 0
        for /L %%i in (!MaxQuadIndex!, -1, 0) do (
            set /a DBI_Digit = DBI_Carry*10000 + %1_%%i
            set /a DBI_Carry = DBI_Digit %% %2
            set /a %1_%%i = DBI_Digit / %2
        )
        goto :EOF
    

    A Print label is also available…

提交回复
热议问题