C:\>set/a a=999999999999999999999/8
无效数字。数字精确度限为 32 位。
我在想被除数尾数上加41个0,不是位数更多?还可以计算?为什么?
无效数字。数字精确度限为 32 位。
我在想被除数尾数上加41个0,不是位数更多?还可以计算?为什么?
联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!
精华I
查看 43,154 回复 136
Originally posted by qwe1234567 at 2006-10-21 23:01:
我到是可以突破除数位数限制,方法正在构思中
Originally posted by qwe1234567 at 2006-10-21 23:20:
就是先除,在乘,在减
@echo off
cls
title 中国DOS联盟论坛 qwe1234567制作
color 17
setlocal enabledelayedexpansion
if not %1*==* (set num1=%1&if not %2*==* (set num2=%2&goto jmp) ELSE goto 错误)
:输入
set num1=
set num2=
echo 实 数 除 法 运 算 脚 本
echo.
echo 该脚本理论上可以对N位以内的实数进行除法运算
echo.
echo 注意: 除阿拉伯数字外, 第一位允许输入符号"-", 以及最多一个"."号,
echo 不允许输入其他字符。否则, 都将视为错误输入...
echo.
echo 中国DOS联盟论坛 qwe1234567制作
set/p num1=请输入被除数:
set/p num2=请输入除数:
:jmp
set fh1=
set fh2=
set fh=
if %num1%*==* goto 错误
if %num2%*==* goto 错误
if %num1:~0,1%==- set fh1=-&set num1=%num1:~1%
if %num2:~0,1%==- set fh2=-&set num2=%num2:~1%
if %fh1%*==-* (if %fh2%*==* set fh=-) else if %fh2%*==-* set fh=-
set err=0
echo %num1%|find ".">nul&&set num1=0%num1%0
call :去错 %num1% num1
echo %num2%|find ".">nul&&set num2=0%num2%0
call :去错 %num2% num2
if %err%==1 goto 错误
for /f "tokens=1* delims=." %%a in ("%num1%") do (set o1=%%a
set t1=%%b)
for /f "tokens=1* delims=." %%a in ("%num2%") do (set o2=%%a
set t2=%%b)
call :去首0 %o1%
set o1=%sw%
call :去首0 %o2%
set o2=%sw%
call :去尾0 %t1%
set t1=%sw%
call :去尾0 %t2%
set t2=%sw%
if not %t1%==0 (set o3=%o1%.%t1%) else set o3=%o1%
if not %t2%==0 (set o4=%o2%.%t2%) else set o4=%o2%
if %o4%==0 goto 错误
if %o3%==0 echo 计算结果是0÷%fh2%%o4%=0&goto 输入
call :计数 %t1%
set s1=%sw%
call :计数 %t2%
set s2=%sw%
If %s1% geq %s2% (set/a s3=s1-s2
call :加尾0 !s3! %t2%
set t2=!sw!
) ELSE (set/a s3=s2-s1
call :加尾0 !s3! %t1%
set t1=!sw!)
set tmp1=%o1%%t1%
set tmp2=%o2%%t2%
call :去首0 %tmp2%
set tmp2=%sw%
call :计数 %sw%
set s2=%sw%
call :去首0 %tmp1%
set tmp1=%sw%
call :计数 %sw%
set s1=%sw%
set/a zsw=s1-s2
call :去尾0 %tmp2%
set tmp2=%sw%
call :计数 %sw%
set s2=%sw%
if %sw% gtr 8 set/a s2=8-sw
set tmp1=%tmp1%0000000000000000000000000000000000000000
set tmp=!tmp1:~0,%sw%!
set sw1=!tmp1:~%sw%!
set jg=
set tmp1=%tmp2:~0,8%
set sw0=!tmp:~0,%s2%!
if %sw% LEQ 8 set/a s2+=1
:开始计算
set/a jg0=sw0/tmp1
:计算
if %jg0%==0 goto 结果
set a1=%tmp2:~-8%
set a2=%tmp2:~0,-8%
set a3=*
set a4=0
set ji=
:乘
if %a1:~0,1%==0 set a1=1%a1%&set a3=1
set/a ji0=jg0*a1+a4
if %a3%==1 set ji=%ji:~-8%
set a4=%ji0:~0,-8%
set ji=%ji0:~-8%%ji%
if %a4%.==. set a4=0
if %a2%.==. goto 减
set a1=%a2:~-8%
set a2=%a2:~0,-8%
goto 乘
:减
if not %a4%==0 set ji=%a4%%ji%
set a1=%tmp%
set jg1=0
set jg2=
:减法
set a2=%a1:~-9%
set a1=%a1:~0,-9%
if not %a1%.==. set a2=1%a2%
set a3=%ji:~-9%
call :去首0 %a3%
set a3=%sw%
set ji=%ji:~0,-9%
set/a jg5=a2-a3+jg1
set/a jg1=0%jg5:~0,-9%-1
if %a1%.==. (if %jg5:~0,1%==- (set jg1==-1) else set jg1=0)
:1
if not %a1%.==. if %jg5:~0,-8%.==. set jg5=0!jg5!&goto 1
set jg2=%jg5:~-9%%jg2%
if %a1%*==* (if %jg1%==-1 (set/a jg0-=1&goto 计算) ELSE set tmp=%jg2%&goto 结果)
goto 减法
:结果
if %sw1%.==. set jg=%jg%%jg0%&goto 显示
set tmp=%tmp%%sw1:~0,1%
call :去首0 %tmp%
set tmp=%sw%
set sw1=%sw1:~1%
set jg=%jg%%jg0%
set sw0=!tmp:~0,%s2%!
goto 开始计算
:显示
if not %jg:~0,1%==0 (set/a zsw+=1)
if %jg:~0,1%==0 set jg=%jg:~1%
if %zsw% gtr 0 goto jxs
for /l %%c in (0,-1,!zsw!) do set jg=0!jg!
set o1=%jg:~0,1%
set o2=%jg:~1%
goto xs
:jxs
set o1=!jg:~0,%zsw%!
set o2=!jg:~%zsw%!
:xs
call :去尾0 %o2%
set o2=%sw%
if %o2%==0 (set jg=%o1%) else set jg=%o1%.%o2%
echo 计算结果是:
echo %fh1%%o3%/%fh2%%o4%=%fh%%jg%
pause
goto :eof
:去首0
set sw=%1
:qs1
if %sw%==0 goto :eof
if %sw:~0,1%==0 set sw=!sw:~1!&goto qs1
goto :eof
:去尾0
set sw=%1
:qw1
if %sw%==0 goto :eof
if %sw:~-1%==0 set sw=!sw:~0,-1!&goto qw1
goto :eof
:计数
set sw=0
set sw1=%1
if %sw1%==0 set sw=1&goto :eof
:js1
if not %sw1%*==* set sw1=%sw1:~1%&set/a sw+=1&goto js1
goto :eof
:去错
echo %1|find ".">nul||set %2=%1.0
for /f "tokens=1* delims=." %%i in ("%1") do echo %%i%%j|findstr "^*$">nul||set err=1
goto :eof
:加尾0
set sw=%2
if %1==0 goto :eof
for /l %%c in (1,1,%1) do set sw=!sw!0
goto :eof
:错误
echo 你输入了非法字符或者除数是0!
echo 请重新输入...
goto 输入