中国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 10:13
47,815 topics / 349,928 posts / today 0 new / 48,288 members
DOS批处理 & 脚本技术(批处理室) » [Joint Participation] [Challenge Ideas] [Batch Processing Floating-Point Operations]
Printable Version  47,112 / 136
Floor46 pengfei Posted 2006-10-09 05:10
银牌会员 Posts 485 Credits 1,218 From 湖南.娄底
Moderator qwe1234567’s scheme on the 43rd floor of removing leading zeros in the decimal part before calculating is very good. When carrying in the decimal part, it plays with character interception very nicely. Well played. ^_^

The code where both decimals and integers can calculate 9 digits has been updated in the first section on the 4th floor.

Added the function of judging erroneous input. For example:
1. If the entered operand contains characters other than Arabic numerals, it will prompt you to enter again.
2. If the decimal and integer digit counts exceed the script calculation range, it will also ask you to enter again.

With this script, as long as you can see the final calculation result, it should be correct!

Looking forward to everyone testing out problems not yet considered...
Floor47 pengfei Posted 2006-10-09 20:24
银牌会员 Posts 485 Credits 1,218 From 湖南.娄底
Finally solved the limitation of floating-point calculation on the number of character digits. In theory it can calculate a value range of N digits.

Algorithm:
1. Take the two input calculation values, use the . sign as the reference, and pad zeros toward both ends to align them (before this, useless zeros have already been removed). Assign the decimal and integer parts to different variables respectively.
2. First calculate the decimal part: add the last digit of the first number and the last digit of the second number. Then assign the last digit of the calculation result to result variable 1. If the calculation result has two digits, automatically add 1 when calculating the next higher digit. Loop like this until all digits of the decimal part have been calculated. This obtains the operand of the decimal part.
2. Calculation of the integer part is the same as that of the decimal part. Obtain result variable 2.
3. Result variable 1, result variable 2. Add a . sign between them and you get the accurate calculation result...

Everyone is welcome to test...



[ Last edited by pengfei on 2006-10-11 at 09:07 ]

Attachments
实数加法运算脚本.rar (1.23 KiB)
Floor48 NaturalJ0 Posted 2006-10-09 20:57
银牌会员 Posts 533 Credits 1,181
I looked at your description; I haven’t looked carefully at the code yet, so don’t take offense if I’m wrong. = =b
I think the integer part and decimal part do not need to be separated. At the beginning you have already aligned all the digit positions, and the zeros that should be padded have also been padded. The number of decimal digits is also clear. Just remove the decimal point directly, handle it as an integer, then add the decimal point back after processing, and finally remove the extra zeros at the end.
Floor49 pengfei Posted 2006-10-09 21:44
银牌会员 Posts 485 Credits 1,218 From 湖南.娄底
RE:NaturlJ0

I separated the decimal and integer parts in consideration of the formatted output problem. If the decimal part is zero, then do not output 0 and the dot.
Floor50 namejm Posted 2006-10-10 09:12
荣誉版主 Posts 1,737 Credits 5,226 From 成都
  I’ll also post a section of code. It does addition digit by digit; in theory it can process N-digit values. A slight pity is that the input checking is not very strict.


[ Last edited by namejm on 2006-10-10 at 09:32 ]
Floor51 pengfei Posted 2006-10-10 09:48
银牌会员 Posts 485 Credits 1,218 From 湖南.娄底
Brother namejm’s is not bad either. ^_^

The code on the 47th floor has corrected the problem with the final carry. Many thanks to brother namejm for the reminder.

Everyone is welcome to test...
Floor52 redtek Posted 2006-10-10 20:43
金牌会员 Posts 1,147 Credits 2,902
I suggest submitting the code to some internationally famous DOS batch discussion website (I don't know which site it is),
and marking the code with www.cn-dos.net as well as the words China and 中国~:)

In the future, innovative, improved, and practical stuff should also be posted on world-famous batch discussion websites (English sites), so that these creations of wisdom carry the imprint of China~:)
Floor53 pengfei Posted 2006-10-10 22:50
银牌会员 Posts 485 Credits 1,218 From 湖南.娄底
Actually batch files are the same as other high-level languages: algorithms are the soul, and innovation is the driving force. And the idea of structured programming is a principle we must stick to.

The three basic structures (sequence structure, selection structure, loop structure) can solve any complex problem.

When you understand this structured design approach more deeply, writing code becomes very easy.
Floor54 electronixtar Posted 2006-10-11 01:21
铂金会员 Posts 2,672 Credits 7,493
Totally in awe~~
Floor55 namejm Posted 2006-10-11 01:26
荣誉版主 Posts 1,737 Credits 5,226 From 成都
  Up to now, everyone's code can only handle non-negative floating-point numbers. The next step should be to think about how to handle pure negative numbers and mixed positive/negative cases, so that the code can truly handle all floating-point numbers.
Floor56 pengfei Posted 2006-10-11 01:33
银牌会员 Posts 485 Credits 1,218 From 湖南.娄底
After testing, the code in my 47th-floor post and moderator namejm's code no longer have any problems.

This problem has been solved perfectly. Not only can it handle floating-point operations, it also solves the digit-limit restriction of batch arithmetic (I found many calculators have digit limits; the calculator that comes with Windows can only calculate 31 digits. Looks like our script can really play to its strengths in this area, haha~~~!)

I was just thinking of merging this unlimited addition/subtraction code; the code is being written ing... It will be posted in my real-number arithmetic script thread!
Floor57 vkill Posted 2006-10-11 02:09
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
Impressive, impressive~~
Floor58 不得不爱 Posted 2006-10-11 02:46
超级版主 Posts 2,044 Credits 5,310 From 四川南充
Finally solved the character-digit limit on floating-point arithmetic; in theory it can calculate values in an N-digit range.
Extract the integer and fractional parts of the two numbers separately
Pad the fractional part with 0s on the low end so that the digits of the two numbers line up
Starting from the lowest fractional digit, calculate the sum of the two numbers one digit at a time; if it exceeds 9, carry 1 to the next higher digit, until the highest integer digit
(The calculation in the 47th-floor post gives an error for decimals with 2 decimal points,
32165.464.1654 +1321.654.31654 =33487.1118
The calculation in the 50th-floor post also gives an error when the first character is a decimal point,
Please enter the first number:.31654
Please enter the second number:1.31654
Operand missing.
The syntax of the command is incorrect.)
Neither of those two problems exists in this code. The code in the 47th-floor and 50th-floor posts still needs improvement.


[ Last edited by qwe1234567 on 2006-10-11 at 09:33 ]

Attachments
实数计算脚本.rar (834 bytes)
Floor59 不得不爱 Posted 2006-10-11 02:47
超级版主 Posts 2,044 Credits 5,310 From 四川南充
Originally posted by pengfei at 2006-10-11 01:33:
After testing, the code in my 47th-floor post and moderator namejm's code no longer have any problems.

This problem has been solved perfectly. Not only can it handle floating-point operations, it also solves the digit-limit restriction of batch arithmetic (发砮..

Both of your code versions still have some problems! Look at mine!
Floor60 vkill Posted 2006-10-11 02:52
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
Originally posted by qwe1234567 at 2006-10-11 02:46:
Finally solved the character-digit limit on floating-point arithmetic; in theory it can calculate values in an N-digit range.
Extract the integer and fractional parts of the two numbers separately
Pad the fractional part with 0s on the low end so that the two numbers ...

The calculation result is:
0.9999999999999999999999999999999999999999999999999999999999999+0.77777777777777
7=177.7777769777777769999999999999999999999999999999999999999999999
Press any key to continue . . .
???
Prev  1 2 3 4 5 6 7 … 10  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023