![]() |
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:04 |
47,815 topics / 349,928 posts / today 0 new / 48,287 members |
| DOS批处理 & 脚本技术(批处理室) » [Discussion] Script + Algorithm = Rounding, Precise Division Operation (Seeking Essence) |
| Printable Version 20,052 / 32 |
| Floor16 bjsh | Posted 2007-04-02 03:35 |
| 银牌会员 Posts 621 Credits 2,000 | |
|
Slightly simplified the code
Brother flyinspace's words I need to think carefully [ Last edited by bjsh on 2007-4-1 at 02:53 PM ] |
|
| Floor17 flyinspace | Posted 2007-04-02 03:49 |
| 银牌会员 Posts 517 Credits 1,206 | |
|
Let's change the algorithm..
1. Get the result of dividend / divisor. 2. Get the remainder of dividend / divisor. 3. The dividend minus the remainder is the actual integer divisor. 3. If the remainder is 0, then the number is divisible. Prompt for divisibility, and then output several 0s. 4. If not 0, then actual integer divisor / divisor is the value of the actual integer part (this value must be accurate). 5. Get the number of digits of the divisor. Suppose it is 2 digits. The output decimal point is 7 digits. (Neither value can be greater than 10) 6. Use a loop to multiply the remainder by 10 (10 to the 9th power). 7. The result of 6 divided by the divisor (then use the rounding algorithm) (give a prompt) to output the decimal part. 8. Output the result: %integer part%.%decimal part% In this way, the precision is also satisfied. Your requirement is also met. How do you think, bjsh? |
|
| Floor18 bjsh | Posted 2007-04-02 04:06 |
| 银牌会员 Posts 621 Credits 2,000 | |
|
Brother flyinspace indeed gave me a reminder;
The system can only accurately calculate the ninth digit exactly; That is to say, the maximum accurate value is eight digits; So my previous algorithm is absolutely no problem for smaller numbers in terms of accuracy; For example, 18/7 But for large numbers like 100000/7, the accuracy is smaller than the former; it is also related to the system's maximum ability to calculate up to the ninth digit; So in this regard, I adopted Brother flyinspace's suggestion; First find the remainder; convert the large number into a small number; then use the remainder to continue dividing |
|
| Floor19 flyinspace | Posted 2007-04-02 04:10 |
| 银牌会员 Posts 517 Credits 1,206 | |
|
Hehe, if you think it's good, give me more points : )
Am I quite cheeky |
|
| Floor20 bjsh | Posted 2007-04-02 04:38 |
| 银牌会员 Posts 621 Credits 2,000 | |
|
I need to correct my previous statement.
System The digital precision limit is 32 bits. So the ninth digit is not guaranteed to be calculated; For example, set /a p=4000000000/7 C:\>set /a p=4000000000/7 -42138185 So the eighth digit is the one calculated precisely; Therefore, the final precision should be 7 digits |
|
| Floor21 flyinspace | Posted 2007-04-02 04:49 |
| 银牌会员 Posts 517 Credits 1,206 | |
|
It's just a problem with a long int. The precision is right here.
set /a p=400000000 % 7 set /a a=400000000 - % p% set /a integer_part=(400000000 - %a%) / 7 The above must be divisible. Why is it not accurate for 9 digits... |
|
| Floor22 bjsh | Posted 2007-04-02 04:53 |
| 银牌会员 Posts 621 Credits 2,000 | |
|
New code with precision 7
|
|
| Floor23 bjsh | Posted 2007-04-02 04:55 |
| 银牌会员 Posts 621 Credits 2,000 | |
|
Brother flyinspace,What you said makes sense!Through cyclic remainder;It may be of arbitrary precision
|
|
| Floor24 bjsh | Posted 2007-04-02 05:46 |
| 银牌会员 Posts 621 Credits 2,000 | |
|
Final code;
Precise to any digit
[ Last edited by bjsh on 2007-4-1 at 06:40 PM ] |
|
| Floor25 bjsh | Posted 2007-04-02 05:49 |
| 银牌会员 Posts 621 Credits 2,000 | |
|
The idea of this code is attributed to flyinspace. I originally wanted to give him ten points; unfortunately, the forum restricts it to only two points..
May all those who have read it fulfill my wish for me |
|
| Floor26 bjsh | Posted 2007-04-02 07:45 |
| 银牌会员 Posts 621 Credits 2,000 | |
|
The previous ones broke the lower limit;
The following one after modification, which cannot calculate higher than 10^9 times, broke both the upper and lower limits; Can calculate any number of digits; and can be precise to any number of digits; (it seems that for something too large like 1 million digits, it will prompt that the output line is too long)
[ Last edited by bjsh on 2007-11-22 at 10:30 PM ] |
|
| Floor27 bjsh | Posted 2007-04-02 08:01 |
| 银牌会员 Posts 621 Credits 2,000 | |
|
Unable to solve the problem where the divisor is greater than 10^9
[ Last edited by bjsh on 2007-4-1 at 08:53 PM ] |
|
| Floor28 flyinspace | Posted 2007-04-02 09:26 |
| 银牌会员 Posts 517 Credits 1,206 | |
Originally posted by bjsh at 2007-4-1 07:01 PM: |
|
| Floor29 bjsh | Posted 2007-04-02 09:49 |
| 银牌会员 Posts 621 Credits 2,000 | |
|
I made a mistake above;
It's impossible to solve the problem where the divisor is greater than 10^9; As for the dividend, the idea used in my last code is the same as flyinspace's; That code is applicable to any number of digits of the dividend [ Last edited by bjsh on 2007-4-1 at 08:51 PM ] |
|
| Floor30 nanhui112 | Posted 2008-01-28 16:28 |
| 初级用户 Posts 59 Credits 127 | |
|
;)Large number. I use cyclic interception to get numbers, but there are still problems. For example, 123456789123456. First take the first nine digits for calculation, then add zeros at the end, and then add the results. There is a problem with adding very large numbers, and the result is not very correct. There is a decimal problem. When magnified, there is a big difference in numbers. It seems that cmd is not suitable for calculation. I can only do this much~~~
----The previous ones are all experts. I will study hard and work harder: ) [ Last edited by nanhui112 on 2008-1-28 at 04:43 PM ] |
|
| Prev 1 2 3 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |