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,142 Replies 136
Floor 61 Posted 2006-10-11 04:17 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
It turned out to be caused by calculating 9 digits at a time. It has already been changed to calculating 1 digit at a time, please check!
The calculation result of the code in the 47th-floor post is:
0.9999999999999999999999999999999999999999999999999999999999999 +0.7777777777777
7 =1.17777777777777699999999999999999999999999999999999999999999999
Floor 62 Posted 2006-10-11 08:24 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
As for the problems pointed out by moderator qwe1234567, they all fall into the category of invalid input, while there is absolutely no problem with the script's arithmetic itself...

Because of time, the invalid-input checking will be improved later~~~!
Floor 63 Posted 2006-10-11 08:56 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Which one of 0.9999999999999999999999999999999999999999999999999999999999999 and 0.77777777777777 is invalid input?
Floor 64 Posted 2006-10-11 08:58 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
0.9+0.7=1.16
0.99+0.77=1.176
0.99+0.7=1.169
0.999 +0.77 =1.1769 Is this invalid input?

[ Last edited by qwe1234567 on 2006-10-11 at 09:03 ]
Floor 65 Posted 2006-10-11 09:13 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
sorry, I meant the case of entering two decimal points.

Because of time, I didn't get around to testing it. The problem you mentioned has already been solved, and the updated code is in the 47th-floor post...
Floor 66 Posted 2006-10-11 09:37 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
I took a look. Your code is 3.53K, and after compression it's 1.23K. My code is 2.11K, and after compression it's 834bytes
Floor 67 Posted 2006-10-11 09:46 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
Mm, the variable names in your code are simple ones like j0, jq1, etc., and compound statements are all written on one line.

As for what I wrote, the variable names use some English words, and every command in all compound statements starts on a new line with two spaces in front (I'm already used to it; the code looks better this way). I don't really like using pipe commands to stitch commands together. This creates a lot of spaces; although my English words aren't used very well, it's still so the names reflect the meaning.

[ Last edited by pengfei on 2006-10-11 at 09:57 ]
Floor 68 Posted 2006-10-12 08:30 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
An even more powerful addition/subtraction arithmetic script has been completed, please test it...

http://www.cn-dos.net/forum/viewthread.php?tid=23611&fpage=1
Floor 69 Posted 2006-10-12 21:35 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Floor 70 Posted 2006-10-13 01:38 ·  中国 甘肃 平凉 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
What I thought of after thinking all evening yesterday was basically just padding and such. Next time I'll go take a good look at the code
Floor 71 Posted 2006-10-13 02:42 ·  中国 北京 东城区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
If the carrying principle of Chinese abacus calculation is used, then estimating multiplication and division with any number of digits shouldn't be a problem either~:)
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
jvive +2 2008-04-03 11:29
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 72 Posted 2006-10-13 06:49 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
  Because CMD is limited in function, when doing division, it directly discards the fractional part of integer-division results, and it also cannot handle decimal division, so using CMD to do division should be approached with great caution.

  The method of doing multiplication digit by digit is workable. In fact, addition already contains part of the functionality needed for multiplication. If you're interested, you can expand on the addition code.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 73 Posted 2006-10-13 08:02 ·  中国 甘肃 平凉 电信
金牌会员
★★★★
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 namejm at 2006-10-13 06:49:
  Because CMD is limited in function, when doing division, it directly discards the fractional part of integer-division results, and it also cannot handle decimal division, so using CMD to do division should be approached with great ca...

In principle it can be done. The power has been out at my place these past few days. In a few days I'll post addition for numbers within 1000 and multiplication for within 10 numbers, hehe. I've basically already worked out the basic ideas
Floor 74 Posted 2006-10-13 08:16 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
Implementing multiplication is completely feasible. A few days ago I already finished the simplest multiplication script, but if the numbers involved have many digits then the code becomes rather complicated.

Because of other reasons I haven't made further changes yet. When I have time I'll definitely write a good one...
Floor 75 Posted 2006-10-13 23:38 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
I worked overtime last night to improve the multiplication script. It can calculate integers and floating-point numbers, and works for all kinds of cases. Because it involves a large amount of digit-extraction operations, the efficiency isn't very high, so I'll optimize it properly when I have time.

Everyone is welcome to test it...


@echo off
if not %1*==* set M=%1 & set N=%2 & goto jmp
:input
cls
set M=
set N=
set /p M= input primary number :
set /p N=input number two number :
:jmp
set sign=
if "%M:~0,1%"=="-" (
if "%N:~0,1%"=="-" (
set M=%M:~1%
set N=%N:~1%
goto begin
)
)
if "%M:~0,1%"=="-" (
set M=%M:~1%
set sign=-
goto begin
)
if "%N:~0,1%"=="-" (
set N=%N:~1%
set sign=-
)
:begin
echo %M% | find "." >nul || set M=%M%.0
echo %N% | find "." >nul || set N=%N%.0
if "%M:~-1%"=="." set M=%M%0
if "%N:~-1%"=="." set N=%N%0
if "%M:~0,1%"=="." set M=0%M%
if "%N:~0,1%"=="." set N=0%N%
call :jerque "%M%"
call :jerque "%N%"
setlocal enabledelayedexpansion
for /f "tokens=1,2 delims=." %%i in ("%M%") do (
set X=%%i
set X_=%%j
)
for /f "tokens=1,2 delims=." %%i in ("%N%") do (
set Y=%%i
set Y_=%%j
)
call :front %X%
set X=%front_%
call :front %Y%
set Y=%front_%
call :rear %X_%
set X_=%rear_%
call :rear %Y_%
set Y_=%rear_%
call :count %X_%
set jlxs=%count_%
call :count %Y_%
set /a jlxs=%count_%+%jlxs%
set son=@%Y%%Y_%
set result=0
set append=
:boss
if not "%son:~-1%"=="@" (
set xx=!son:~-1!
set son=!son:~0,-1!
call :under
call :plus
set result=!ll!
set append=0!append!
goto boss
)
if "%jlxs%"=="0" goto end
set result=!result:~0,-%jlxs%!.!result:~-%jlxs%!
call :rear %result%
set result=%rear_%
if "%result:~-1%"=="." set result=%result:~0,-1%
if "%result:~0,1%"=="." set result=0%result%
:end
cls
echo ============
echo 运算结果^^^!
echo ============
echo.
echo.
echo %M%*%N%=%sign%%result%
pause >nul
exit

:plus
set weave=%single:~0,-1%%weave:~0,-1%
call :count %weave%%append%
set num1=%count_%
call :count %result%
set num2=%count_%
set /a num=%num1%-%num2%
call :join %num% %result%
set result=%join_%
set lx=@%weave%%append%
set ly=@%result%
set ln=0
set ll=
:plus_
set /a lz=%lx:~-1%+%ly:~-1%+%ln%
set/a ln=0%lz:~0,-1%
set ll=%lz:~-1%%ll%
set lx=%lx:~0,-1%
set ly=%ly:~0,-1%
if "%lx%"=="@" (
if "%ln%"=="1" (
set ll=1%ll%
goto :eof
) else (
goto :eof
)
)
goto plus_
:under
set father=@%X%%X_%
set single=0
set weave=
:under_
set note=%single:~0,-1%
if "%note%"=="" set note=0
set weave=%single:~-1%%weave%
if not "%father:~-1%"=="@" (
set yy=!father:~-1!
set /a yy=!yy!
set father=!father:~0,-1!
call :op
)
goto :eof
:op
set part=!xx!
set part_=!yy!
set /a single=%part%*%part_%+!note!
goto under_
:front
set front_=%1
:front1
if "%front_:~0,1%"=="0" (
set front_=%front_:~1%
goto front1
)
goto :eof
:rear
set rear_=%1
:rear1
if "!rear_:~-1!"=="0" (
set rear_=!rear_:~0,-1!
goto rear1
)
goto :eof
:count
set count2=%1@
set count_=0
:count1
if not "!count2:~0,1!"=="@" (
set /a count_+=1
set count2=!count2:~1!
goto count1
)
goto :eof
:join
set margin=%1
set join_=%2
:join1
if not "%margin%"=="0" (
set /a margin-=1
set join_=0!join_!
goto join1
)
goto :eof
:jerque
for /f "tokens=1* delims=." %%i in (%1) do (
echo %%i%%j|findstr "^*$">nul || goto error
)
goto :eof
:error
cls
echo ======================
echo 运算数不符合要求^^!
echo ======================
echo.
echo.
echo 请按任意键重新输入...
pause >nul
goto input


[ Last edited by pengfei on 2006-10-15 at 09:35 ]
Attachments
无限制乘法运算脚本.rar (1.25 KiB, Credits to download 1 pts, Downloads: 20)
‹ Prev 1 3 4 5 6 7 10 Next ›
Forum Jump: