China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-20 13:06
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Joint Participation] [Challenge Ideas] [Batch Processing Floating-Point Operations] DigestI View 41,141 Replies 136
Floor 106 Posted 2006-10-20 05:39 ·  中国 甘肃 兰州 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
C:\>set/a a=999999999999999999999/8
Invalid number. Numeric precision limited to 32 bits.

I'm wondering, adding 41 zeros to the tail of the dividend means even more digits, right? It can still calculate? Why?
Floor 107 Posted 2006-10-20 07:10 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Adding 41 zeros to the tail of the dividend is for outputting decimals. My script can handle dividends with thousands of digits. If you don't believe it, try it yourself
Floor 108 Posted 2006-10-21 00:43 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
I looked over moderator qwe1234567's code on the 102nd floor. It's written very well. It absorbed the best ideas from earlier posts, and changed brother he200377's repeated-calculation plan of adding zeros at the end to improve precision into dividing the divisor down to 9 digits and then taking it out one digit at a time for calculation. Because of that, it broke through the digit limit on the dividend. It also considers some details more thoroughly, such as carrying around the decimal point, etc. This is the crystallization of collective wisdom.

To break through the digit limit of the divisor, a more divergent line of thinking is needed. And I still haven't had the courage to implement that algorithm I fear so much. Maybe I really am a bit scared, scared that its efficiency will give you all a shock...

[ Last edited by pengfei on 2006-10-21 at 00:45 ]
Floor 109 Posted 2006-10-21 02:29 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Floor 110 Posted 2006-10-21 22:51 ·  中国 甘肃 张掖 临泽县 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
As for breaking through the divisor digit limit, I don't think there's any good method. I really can't think of one anymore
Floor 111 Posted 2006-10-21 23:01 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Floor 112 Posted 2006-10-21 23:09 ·  中国 甘肃 张掖 临泽县 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Originally posted by qwe1234567 at 2006-10-21 23:01:
I actually can break through the divisor digit limit, the method is still being worked out

Talk about the basic idea~ everyone can think about the method together, haha~
Floor 113 Posted 2006-10-21 23:13 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
Using a simulated array method?
Say it already~~~ :)))
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 114 Posted 2006-10-21 23:20 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Floor 115 Posted 2006-10-21 23:23 ·  中国 甘肃 张掖 临泽县 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Originally posted by qwe1234567 at 2006-10-21 23:20:
Just divide first, then multiply, then subtract

Still don't understand~
Floor 116 Posted 2006-10-22 07:07 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Floor 117 Posted 2006-10-22 08:34 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
OK, I'll look at your work. My algorithm does break through the digit limit, but the efficiency is too low.
Floor 118 Posted 2006-10-23 00:02 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
After several days of continuous testing and code optimization, I finally made a script that can perform division on N-digit real numbers. But the divisor had better stay within 16 digits, otherwise the waiting time gets too long; the more digits the divisor has, the longer the wait! Please test it....
Sigh, CMD's calculation speed is too slow....
@echo off
cls
title China DOS Union Forum made by 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 Real Number Division Script
echo.
echo In theory, this script can perform division on real numbers within N digits
echo.
echo Note: Other than Arabic numerals, the first character may be the "-" sign, and at most one "." is allowed,
echo no other characters are allowed. Otherwise, it will all be treated as invalid input...
echo.
echo China DOS Union Forum made by qwe1234567
set/p num1=Please enter the dividend:
set/p num2=Please enter the divisor:
: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 The result is 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 The result is:
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 You entered illegal characters, or the divisor is 0!
echo Please re-enter...
goto 输入
Floor 119 Posted 2006-10-23 00:03 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Floor 120 Posted 2006-10-23 03:50 ·  中国 甘肃 兰州 城关区 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Moderator qwe1234567, this one is much better written, haha, and it even has explanations, so it's not tiring to read~ bump
Forum Jump: