Joke Collection Website - Cold jokes - Why is it unclear for Android phones to calculate 3.15 minus 3.14, which is equal to 0.999999?
Why is it unclear for Android phones to calculate 3.15 minus 3.14, which is equal to 0.999999?
This is a bug in this type of calculator.
"Our human arithmetic has ten numbers, from 0 to 9, which is the decimal system. In the computer world, there are only two numbers 0 and 1, which is the binary system." Xiao Zhu Said, this conversion process, in detail, is the method of dividing the integer part of a number by 2 to get the remainder; multiplying the decimal part by 2 to get the integer. Taking 14.52 as an example, the integer part is 14: 14/2=7 more than 0; 7/2=3 more than 1; 3/2=1 more than 1; 1/2=0 more than 1. Therefore, 14 is 1110 in binary. The decimal part is 0.52: 0.52×2=1.04 Integer 1 0.04×2=0.08 Integer 0 0.08×2=0.16 Integer 0 0.16×2=0.32 Integer 0 The decimal part is slightly different from the integer part. The decimal part is probably infinite, but For convenience, we only perform 4 operations. So, we get the decimal part result is 1000. Therefore, 14.52 is 1110.1000 in binary. By analogy, 14.49 is 1110.0111 in binary. In this way, 14.52-14.49 is 1110.1000-1110.0111=0.0001 through binary operation. Then, we convert it back to decimal (the formula for converting binary to decimal is: ABC.XYZ=A×2"2 B×2"1 C×2"0 X×2"-1 Y×2"-2 Z×2"-3. When calculating, replace A in the formula with the corresponding number , B, C and other symbols), the result obtained is 0.0625. Some attentive readers may have discovered that the results we obtained are actually very different from the real results, even worse than the Android calculator. Is our algorithm wrong? In fact, it is not, Xiao Zhu said, it is related to the number of times we perform operations on the decimal part. If we calculate it several times, the accuracy will be greatly improved. For example, the number 0.09999 obtained in the Android computer can basically be realized after we calculate the decimal part nearly 30 times.
■ This is not a bug unique to Android. Xiao Zhu said that we have mentioned before that this is almost unavoidable in today's computer field. But we can also avoid it through some technical means. For example, you can first enlarge a number with a decimal point, turn it into an integer for calculation, and then divide it by the corresponding number, and you will finally get an accurate result; or you can determine the number of digits to be accurate in advance, and then calculate to this digit. Afterwards, rounding is performed and the effect is the same. During the interview, the reporter found that this problem is not unique to Android calculators, including Baidu calculators and even calculators that come with the Windows operating system. This phenomenon also occurs. Zhu Ning said that those calculators that can get accurate results are probably optimized using the above method. "Normally, don't make a fuss if you encounter something, just treat it as a joke." He said.
When Java long handles subtraction, there will be endless subtraction! This has to do with Java! Maybe it was ignored during design, it is a low-level bug!
Similar ones include: 14.52-14.49=0.029999, not 0.03;
8.03-7.96=0.069999, etc.
- Related articles
- 1tb what stem is the far peak blue?
- Why is Shanghai food so sweet, but local people are not fat?
- Jokes of the sports meeting
- Li Yong was buried in the United States, and did not die of cancer. Why is there such a statement?
- The boss's funniest joke
- Examples of impolite speech and jokes
- How powerful is Tai Ji Chuan in actual combat?
- What social significance does Kong Yiji's gown contain?
- The plot introduction of Ode to Joy 2 Episode 37 introduces the plot content of Episode 37 of Ode to Joy 2
- The witty doctor's life episode 2, don't look at people with colored glasses.