中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-08 02:27
48,041 topics / 350,128 posts / today 3 new / 48,253 members
DOS批处理 & 脚本技术(批处理室) » Square Root (precision to 5 decimal places)
Printable Version  699 / 4
Floor1 dreamseed Posted 2008-04-05 16:51
初级用户 Posts 10 Credits 38 From GZ
The algorithm idea was proposed by terse. I expanded the feasible range.



[ Last edited by dreamseed on 2008-4-5 at 05:13 PM ]
Floor2 PPdos Posted 2008-04-05 17:08
高级用户 Posts 268 Credits 783
() - grouping
! ~ - - unary operators
* / % - arithmetic operators
+ - - arithmetic operators
<< >> - logical shifts
- bitwise "and"
^ - bitwise "xor"
| - bitwise "or"
= *= /= %= += -= - assignment
&= ^= |= <<= >>=
, - expression separator

Make use of logical operators
Floor3 dreamseed Posted 2008-04-05 17:12
初级用户 Posts 10 Credits 38 From GZ
Can you write out a concrete example?
Floor4 plp626 Posted 2008-04-05 18:04
银牌会员 Posts 1,020 Credits 2,278
Using batch files for math calculations, especially decimals, I really haven't studied that before,

Threads like this are just for fun, and can be kept around as a small utility function,

Let's study the algorithm
---------------------------
It's purely a computational mathematics problem, mainly the iterative formula: Xn+1=(Xn+A/Xn)/2 limit----->A^(1/2)

At the start, the OP sets X1 to 2, then in the :acr module iteratively computes the integer part of A^(1/2),

if %b% lss 0 goto acr is not redundant; it's there to prevent overflow into a negative number. I overlooked that

Also, setting X1 to n/2 can reduce the number of iterations,

As for the decimal part afterward, someone else can analyze it, I don't have the patience anymore

[ Last edited by plp626 on 2008-4-5 at 06:46 PM ]
Floor5 xtanbmy Posted 2008-04-07 19:02
初级用户 Posts 31 Credits 47
Let the next person take a look, thanks.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023