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-23 09:15
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Original] Real number addition and subtraction operation script! View 6,228 Replies 23
Floor 16 Posted 2006-10-12 23:50 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
The modification has been completed, and the error in subtraction has been resolved! Please test!
1111111111.1111111111-1111111111.1111111112=-0.0000000001
Floor 17 Posted 2006-10-13 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
Floor 18 Posted 2006-10-13 00:34 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
Yours is slower. When testing the same operation, yours takes more than thirty milliseconds, and mine takes about fifty milliseconds.

Your code performs operations on decimals and integers together, taking a shortcut in judgment. My original intention when writing was to fully simulate manual calculation. Therefore, the code is the most primitive way of calculation.

The variables used in my code are more, and the operations are more complex, which is also one of the reasons affecting the speed. The algorithm is the soul of the program, and the efficiency of solving the same problem will be different. Due to time constraints, the optimization and update of the code will be carried out later...

[ Last edited by pengfei on 2006-10-13 at 01:18 ]
Floor 19 Posted 2006-10-13 00:37 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
Actually, it's not practical to calculate the numerical range of N bits with the above script, because the storage space of environment variables is limited...
Floor 20 Posted 2006-10-13 01:27 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Floor 21 Posted 2006-10-13 02:00 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
Gaga~~~! I really can't bear to modify the code in the first paragraph of the first floor. Although the algorithm is the most primitive. But implementing such an algorithm with the three basic structures of batch processing to complete. I am a little complacent myself, hehe~ This is my hard work!!!

Still don't plan to modify it, either write a new code with a new algorithm.

Brothers, please help test the bugs in the code of the first paragraph of the first floor...
Floor 22 Posted 2007-02-23 06:20 ·  中国 广东 湛江 电信
高级用户
★★★
Credits 959
Posts 311
Joined 2006-04-11 14:08
20-year member
UID 53665
Gender Male
From 广东-LianJiang
Status Offline
After reading the old post, I think the algorithm in this post is worth learning from by everyone, so I'm bumping it up......
κχυμγνξοθπρωψιαδλεηφβτζσ┬╀┾┳┞┯┰┱┣┲┳╂╁│├┟┭┠这是什么??这就是我的人生
Floor 23 Posted 2008-11-04 01:04 ·  中国 广东 深圳 福田区 电信
新手上路
Credits 5
Posts 6
Joined 2008-11-02 15:33
17-year member
UID 129773
Gender Male
Status Offline
So you guys have already handled this matter. I also wanted to write a calculator myself, but I want to combine all of yours to make a mixed-operation calc. Is there any batch script that supports square roots?
Floor 24 Posted 2008-11-04 01:32 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Search more and you'll have it
@echo off
set a=2
set/p p=Please enter the number for square root (between 0~89999999)
set/p w=Please enter the number of decimal places to be precise (within 9)
:lp
set /a a=(p/a+a)/2,n=a*a,r=a,y=p-n
if %n% lss 0 goto lp
if %n% gtr %p% goto lp
if %n% equ %p% goto ok
if "%w%"=="" goto ok
set/a m=10,x=r*20,y*=100,b+=1
:lp1
set/a m-=1,s=(x+m)*m
if %s% gtr %y% goto lp1
if %w% neq 0 set/a y-=s,r=r*10+m,t=t*10+m,m=10,x=r*20,y*=100,w-=1&goto lp1
:ok
if not "%t%" == "" set a=%a%.%t%
echo The square root result of %p%: %a%
pause>nul
Forum Jump: