If you only use I ++ as a counter, you can skip this post. This post is mainly written by the big data computation and money-related computation comrades. It may be wrong. You are welcome to criticize and point out this post.
In many cases, most college students use computers as large calculators after they take part in their work. Program, Such as double A = 12936/123546;, fine
When this result is only for entertainment, you just need to continue using it. However, a small error is a terrible number, and the calculation error is for calculation.
Machine is a common practice for computers that generally think of as synonymous with precision. Many times we realize that there will be errors, but we use high-precision types to make up for them.
However, in many cases, it is still not enough, because the error still exists, but we think it can be ignored.
Many calculations dealing with money should pay close attention to the impact of errors on computing. For example, a hacker once described a method in a novel and intruded into the banking system, he made an operation on the balance of each account. Due to the calculation error, each account has a few more cents, Which is insignificant for the bank, but he remitted a few cents of all his accounts into his account, so a millionaire was born, and there was no less money in each bank account. Of course, novels are novels, but they are enough to mention our attention to errors.
The reason for the error in the computer is actually very simple. The computer can only quickly move its two fingers to calculate, so in the computer, addition and subtraction are safe, but only for integers, the calculation of the two floating point numbers will cause the last few digits to have doubts due to the floating point number itself. When the two floating point numbers are added multiple times, the errors will accumulate, and then they will become larger and larger as the snowball, the error of the floating point addition and subtraction increases according to the linear type, and the multiplication and division become more dominant, increasing exponentially. For scores, only the 1/2, 1/4, 1/8, 1/16, and other 1/2 indexes in the computer are accurate. Therefore, it is best for calculation to convert all multiplication and division into equivalent addition and subtraction operations. So far ......