Originally posted by he200377 at 2006-10-16 02:10:
I thought of a fundamental way to solve it, hehe. Before calculating, make the numbers of decimal places the same, hehe, then the problem becomes much easier to solve
[ Last edited by he200377 on 2006-10-16 at 02:11 ]
Brother he200377, the code in your 81st-floor post must have taken quite a bit of thought, hehe~ not bad.
But it has major limitations when calculating floating-point numbers. Let me mention a few immature suggestions here; I'm not even sure whether my analysis is correct:
1. It generates the temporary file ver_.txt. As long as the variables are used a bit better, there is absolutely no need to generate a temporary file.
2. I looked at that subroutine for removing zeros. You used twenty lines, but actually it can be solved in just a few lines.
3. The biggest flaw is the 9.99/9 case you mentioned. Looking at your code, this point wasn't thought through completely. The error mainly lies in carrying when removing the decimal point from the divisor and dividend. In the final decimal carry handling, no matter what value %x_wei% has, you always carry in the form 0.xxx. The integer part was originally a positive integer, but when the decimal point is carried, the integer digits become fractional digits.
What you mentioned here about aligning the decimal places first and then calculating is also a good idea, but originally it could only calculate numbers within 9 digits, and this would make the calculation range even smaller. That's not a good solution.
I suggest that at the end you read out the decimal-point position of the result, and then carry according to %x_wei%. If the number of digits is not enough, then pad with zeros.
4. About what moderator qwe1234567 said: 3.2/0.32 and 0.32/0.032 cannot be calculated! When the integer part of the divisor is zero, the error is quite serious; it goes into an infinite loop when processing the decimal point at the end.
5. 0.123/123=0.002609756097 Here an error occurs while reading the dividend; the characters are reversed.
This algorithm is still not mature, and it has limitations. Most importantly, it cannot break through the digit-limit restriction.
But when handling integers, it can improve precision.
Brother, you still need to keep working hard. If you want to break through the digit limit, this algorithm cannot do it.
[
Last edited by pengfei on 2006-10-16 at 08:20 ]