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-25 08:45
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Discussion]Feasibility Discussion on Using Batch Processing to Calculate Square Roots and Reciprocals View 1,615 Replies 3
Original Poster Posted 2006-10-15 09:25 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
In the Quake3 engine, there is such a "mars algorithm":


//
// Calculate the reciprocal of the square root of parameter x
//
float InvSqrt (float x)
{
float xhalf = 0.5f*x;
int i = *(int*)&x;
i = 0x5f3759df - (i >> 1); // Calculate the first approximate root
x = *(float*)&i;
x = x*(1.5f - xhalf*x*x); // Newton's iteration method
return x;
}


Personally, I think that set /a supports bit operations, and it should be possible to implement the reciprocal of the square root.

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 2 Posted 2006-10-15 09:40 ·  中国 四川 成都 移动
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
```
In the SET command, two new command-line switches are added:

SET /A expression
SET /P variable=

The /A command-line switch specifies that the string to the right of the equal sign is a numerical expression to be evaluated. This expression evaluator is simple and supports the following operations in decreasing order of precedence:

() - Grouping
! ~ - - Unary operators
* / % - Arithmetic operators
+ - - Arithmetic operators
<< >> - Logical shifts
- Bitwise "AND"
^ - Bitwise "XOR"
| - Bitwise "OR"
= *= /= %= += -= - Assignment
&= ^= |= <<= >>=
, - Expression separator
```
  Microsoft's explanations have always been vague. Except for being able to use arithmetic operators and assignment symbols proficiently, I have never understood the rest. Please explain if anyone has used it.

  In CMD, you can't directly calculate decimal multiplication; you still have to operate bit by bit. If you can understand how the set /a symbols are used, the problem of square roots is estimated to be solved easily.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 3 Posted 2006-10-15 11:08 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Floor 4 Posted 2006-10-16 00:08 ·  中国 甘肃 平凉 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Using set /a is too cumbersome, and division is anyway cumbersome

[ Last edited by he200377 on 2006-10-16 at 00:34 ]
Forum Jump: