中国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-10-24 09:02
47,815 topics / 349,928 posts / today 0 new / 48,287 members
DOS批处理 & 脚本技术(批处理室) » [Joint Participation] [Challenge Ideas] [Batch Processing Floating-Point Operations]
Printable Version  47,109 / 136
Floor121 不得不爱 Posted 2006-10-23 03:55
超级版主 Posts 2,044 Credits 5,310 From 四川南充
Hehe, it's not explanations, it's just that Chinese labels were used. With Chinese labels, even explanations can be omitted!
Floor122 vkill Posted 2006-10-23 03:57
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
Originally posted by qwe1234567 at 2006-10-23 03:55:
Hehe, it's not explanations, it's just that Chinese labels were used. With Chinese labels, even explanations can be omitted!

Chinese works too, huh. Haven't tried it yet, not sure how many Chinese characters are supported at most
Floor123 不得不爱 Posted 2006-10-23 04:18
超级版主 Posts 2,044 Credits 5,310 From 四川南充
This is also my first time using Chinese labels. I think there probably isn't a limit on the number
Floor124 不得不爱 Posted 2006-10-23 04:19
超级版主 Posts 2,044 Credits 5,310 From 四川南充
Also, variables can be Chinese too
Floor125 vkill Posted 2006-10-23 04:31
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
Originally posted by qwe1234567 at 2006-10-23 04:18:
This is also my first time using Chinese labels. I think there probably isn't a limit on the number

Letters are 8, so I think there should be one. Test it and see
Floor126 vkill Posted 2006-10-23 04:35
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
Turns out there really is no limit, hehe~ I'll use Chinese for labels from now on
Floor127 不得不爱 Posted 2006-10-23 04:43
超级版主 Posts 2,044 Credits 5,310 From 四川南充
I tried it. In CMD, letters aren't limited to just 8 either (I guess there isn't much of a limit, or maybe it's 255). You can test it with the following code
@echo off
:abcdefghi
set /p a=Please enter:
if %a%.==5. (goto abcdefghi) else goto abcdefghi1
:abcdefghi1
echo %a%
pause
Floor128 xycoordinate Posted 2007-03-04 23:15
中级用户 Posts 228 Credits 493 From 安徽
Originally posted by namejm at 2006-10-4 21:08:
 So far, everyone has already found two methods for calculating floating-point numbers under CMD:

  Method 1: Calculate the integer part and the fractional part separately. The process is: the integer parts can just be added directly; the fractional part is a bit more troublesome: if the numbers of digits after the decimal point are not the same, then use the one with the most digits as the standard, pad zeros onto the fractional part of the other number, and then perform integer addition on the fractional parts; if the number of digits in the sum exceeds the longest original fractional length, then carry 1 to the integer part, and the highest digit of the fractional part must be reduced by 1 accordingly;

  Method 2: Recombine the integer part and fractional part into a new number, then perform addition on the new number, and finally insert the decimal point back into its original position;

  The respective advantages and disadvantages of the two methods:

  Method 1: Advantage: the range of floating-point numbers it can handle is very large; as long as the result of the addition is between (2^32-1.2^32-1) and -(2^32-1.2^32-1), it can handle it; disadvantage: most problems appear in the fractional part, for example, if the highest digit of the fractional part is 08 or 09, errors may occur, and these two cases need separate handling; if the digit length of the fractional sum exceeds the longest original length, then the integer part must be incremented by 1 and the highest fractional digit must be decremented by 1; if this is extended to addition of three or more floating-point numbers, the carry problem becomes even more complicated;

  Method 2: Advantage: there is no need to separately handle the 08 and 09 cases, and no need to consider carry problems (after reading pengfei's analysis below, I found that this description is a bit problematic; for details please refer to the explanation below); disadvantage: the range of floating-point numbers it can handle is relatively small; it only succeeds when the range of the new value formed by removing the decimal point from the sum is between (2^32-1.2^32-1) and -(2^32-1.2^32-1).


Excellent!!!!

Most decimals used in daily life are "amounts of money", with only 2 decimal places, so "Method 2" is better!

This thread gave me a lot of inspiration, thanks everyone!!!



[ Last edited by xycoordinate on 2007-3-4 at 10:51 AM ]
Floor129 6622186 Posted 2007-03-10 08:17
高级用户 Posts 411 Credits 894
If this could be changed into a command-line version (when using it, enter the filename and the corresponding parameters), that would be great.
Floor130 6622186 Posted 2007-03-10 09:02
高级用户 Posts 411 Credits 894
Labels can also use Chinese, learned something!
Floor131 netbenton Posted 2009-04-05 12:29
银牌会员 Posts 752 Credits 1,916 From 广西


[ Last edited by netbenton on 2009-4-5 at 10:30 ]
Floor132 czl1378 Posted 2009-04-05 14:46
初级用户 Posts 114 Credits 161
The one on the 4th floor is like a heavenly book...
But why go so deep into floating-point operations? I haven't seen many batch files that actually need floating-point calculations. You experts really are too bored.
Floor133 netbenton Posted 2009-04-07 09:01
银牌会员 Posts 752 Credits 1,916 From 广西
Floor134 mmh1 Posted 2009-04-09 00:12
初级用户 Posts 24 Credits 20
What does this line mean??
if "%number1:~0,1%"=="." set number1=0%number1%
Floor135 xrw Posted 2009-05-23 17:47
新手上路 Posts 5 Credits 5
What does this line mean??
if "%number1:~0,1%"=="." set number1=0%number1%
Prev  1 … 6 7 8 9 10  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023