![]() |
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-10 15:18 |
47,811 topics / 349,897 posts / today 0 new / 48,255 members |
| DOS批处理 & 脚本技术(批处理室) » [Original] Real number addition and subtraction operation script! |
| Printable Version 6,537 / 23 |
| Floor1 pengfei | Posted 2006-10-06 23:42 |
| 银牌会员 Posts 485 Credits 1,218 From 湖南.娄底 | |
|
The real number addition and subtraction operation script has been updated, and the functions are more powerful.
1. Can perform various addition and subtraction operations, such as: (X+Y, X-Y, -X+Y, -X-Y). 2. Added detection of incorrect input. 3. The operands are not limited by the number of digits, and theoretically can operate in the range of N digits. It can replace a calculator for addition and subtraction operations, but is not limited by the number of digits. This is the greatest advantage of this script. Due to time constraints, a comprehensive test has not been carried out. Please point out the insufficient places, and everyone can discuss and study together~~~! Today is Mid-Autumn Festival. I wish all friends in the alliance a happy Mid-Autumn Festival, progress in study, and be happy every day~~~! I give you a gift "Floating Point Number Addition and Subtraction Operation Script". The code has just been written, and there are still many不足之处. Everyone can discuss together! There was a fatal defect in the previous code, which has now been corrected. Please test... Related Discussions: [Join in together][Challenge ideas][Batch processing floating-point operation] About the base system problem when dealing with numbers! [ Last edited by namejm on 2006-10-19 at 00:39 ] Attachments 浮点数加减运算脚本.rar (1.49 KiB) 无限制实数加减运算脚本.rar (2.21 KiB) |
|
| Floor2 bg | Posted 2006-10-07 01:51 |
| 初级用户 Posts 34 Credits 118 | |
| Floor3 不得不爱 | Posted 2006-10-07 03:40 |
| 超级版主 Posts 2,044 Credits 5,310 From 四川南充 | |
|
It should be able to calculate to 9 decimal places.
[ Last edited by qwe1234567 on 2006-10-7 at 03:48 ] |
|
| Floor4 pengfei | Posted 2006-10-07 04:25 |
| 银牌会员 Posts 485 Credits 1,218 From 湖南.娄底 | |
|
No, 9 digits will overflow...
[ Last edited by pengfei on 2006-10-7 at 06:17 ] |
|
| Floor5 pengfei | Posted 2006-10-07 06:25 |
| 银牌会员 Posts 485 Credits 1,218 From 湖南.娄底 | |
|
Found a strange phenomenon...
|
|
| Floor6 不得不爱 | Posted 2006-10-07 06:37 |
| 超级版主 Posts 2,044 Credits 5,310 From 四川南充 | |
|
1: My code can calculate up to 9 decimal places. It should be a problem with the method. I add 1 to the first decimal place only when the first decimal place is 0, while yours adds 1 to the first digit of all decimal places, so your code has one fewer decimal place!
2: There is a problem with the subtraction operation of floating - point numbers: Look at the following errors: 5.69 - 65.654 = - 59.6371 53.698 - 654.95 = - 600.16585 |
|
| Floor7 pengfei | Posted 2006-10-07 07:04 |
| 银牌会员 Posts 485 Credits 1,218 From 湖南.娄底 | |
|
It turned out that the execution order was wrong, and the code has been corrected.
5.69 - 65.654 = -59.964 53.698 - 654.95 = -601.252 The version owner's code is to add 1 if it is zero for analysis. At that time, I also wanted to adopt this method, but it was a little more troublesome. So I didn't use this scheme. And in that scheme, when the first digit of the decimal part is zero, it can only perform 8 - decimal - digit operation, not all can perform 9 - decimal - digit operation. So I think it is simpler to add 1 whether it is zero or not, and one less judgment is needed later. The explanation will also have fewer words ^_^ [ Last edited by pengfei on 2006-10-7 at 07:10 ] |
|
| Floor8 不得不爱 | Posted 2006-10-07 08:11 |
| 超级版主 Posts 2,044 Credits 5,310 From 四川南充 | |
|
That scheme can still perform operations with 9 decimal places even when the first decimal digit is zero
|
|
| Floor9 pengfei | Posted 2006-10-07 08:18 |
| 银牌会员 Posts 485 Credits 1,218 From 湖南.娄底 | |
|
It is indeed like this. And in my code, if the first decimal digit is zero, it can perform operations on 9-digit numbers; if it is not zero, it can only perform operations on 8-digit numbers.
|
|
| Floor10 electronixtar | Posted 2006-10-08 05:25 |
| 铂金会员 Posts 2,672 Credits 7,493 | |
|
Suggest pengfei to write a bat math library, and then later everyone can directly include it when writing bats, ^_^
|
|
| Floor11 不得不爱 | Posted 2006-10-08 05:57 |
| 超级版主 Posts 2,044 Credits 5,310 From 四川南充 | |
Originally posted by pengfei at 2006-10-7 06:25: |
|
| Floor12 pengfei | Posted 2006-10-12 08:17 |
| 银牌会员 Posts 485 Credits 1,218 From 湖南.娄底 | |
|
It seems to be directly related to the data type of CMD. The data storage type during set /a operation should be long integer. And 22... + 11... exceeds its maximum storage space, so it overflows, and the carried bit fills the sign bit. Thus, a negative number appears.
While 22.. - 11... does not reach the maximum storage capacity. Therefore, it executes normally. [ Last edited by pengfei on 2006-10-12 at 08:28 ] |
|
| Floor13 pengfei | Posted 2006-10-12 08:27 |
| 银牌会员 Posts 485 Credits 1,218 From 湖南.娄底 | |
|
The real number operation script has been updated in the first paragraph of the first floor. The function is more powerful, and various addition and subtraction operations can be realized without any restrictions!
Welcome everyone to test... |
|
| Floor14 不得不爱 | Posted 2006-10-12 21:27 |
| 超级版主 Posts 2,044 Credits 5,310 From 四川南充 | |
|
I also add one!
[ Last edited by qwe1234567 on 2006-10-13 at 01:11 ] Attachments 实数加减运算脚本.rar (1.17 KiB) |
|
| Floor15 pengfei | Posted 2006-10-12 23:01 |
| 银牌会员 Posts 485 Credits 1,218 From 湖南.娄底 | |
|
Please enter the first decimal: 1111111111.1111111111
Please enter the second decimal: -1111111111.1111111112 The calculation result is: 1111111111.1111111111 - 1111111111.1111111112 = 9999999999.9999999999 Looking at it, the code of moderator qwe1234567 is still pretty good. You took a shortcut when performing various addition and subtraction operations, and this shortcut will have a fatal error. In addition, the control on the format output is not strict enough. My code uses more callable functions to implement various addition and subtraction operations, completely simulating real manual calculations. [ Last edited by pengfei on 2006-10-12 at 23:10 ] |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |