M9 1a8 8 0 1 0 0 16A8 8 0 0 0 9 1zm. M9 1a8 8 0 1 0 0 16A8 8 0 0 0 9 1zM8 15. Why can’t decimal numbers be represented exactly 0x97 in binary option binary?
There have been several questions posted to SO about floating-point representation. For example, the decimal number 0. I understand the principles behind floating-point representation. What I don’t understand is why, from a mathematical perspective, are the numbers to the right of the decimal point any more “special” that the ones to the left? 0 has an exact binary representation because the integral portion of any number is always exact. All I did was move the decimal one place and suddenly I’ve gone from Exactopia to Inexactville.
Mathematically, there should be no intrinsic difference between the two numbers — they’re just numbers. By contrast, if I move the decimal one place in the other direction to produce the number 610, I’m still in Exactopia. But as soon as the decimal crosses some threshold, the numbers are no longer exact. Edit: to clarify, I want to stay away from discussion about industry-standard representations, such as IEEE, and stick with what I believe is the mathematically “pure” way. The positions increase indefinitely to the left and to the right. You might find this helpful to understand exactly what’s going on inside a floating point nubmber: Anatomy of a floating point number.
How would you represent that, using negative powers of 2? Jon Skeet answers the question in your body very well. One thing that is missing is that you actually ask two different questions. The title question is “why can’t decimal numbers be represented exactly in binary? The answer is, they can be. Between your title and body you conflate the idea of “binary” and the idea of a “floating point representation. There’s several systems that have exact decimal representation.
It works pretty much like you describe. The SQL decimal type is one example. LISP languages have it built in. There are several commercial and opensource libraries for using exact decimal calculations. Decimal numbers can be represented exactly, if you have enough space – just not by floating binary point numbers. The reason you can’t represent 0.
1 as a binary floating point number is for exactly the same reason. The problem is that 3 is a prime number which isn’t a factor of 10. That’s not an issue when you want to multiply a number by 3: you can always multiply by an integer without running into problems. 1 is usually used as the simplest example of an exact decimal number which can’t be represented exactly in binary floating point, arguably 0. 5 – and 5 is the prime that causes problems between decimal and binary.
Side note to deal with the problem of finite representations: Some floating decimal point types have a fixed size like System. This is an entirely separate point to the main one of this answer, however. That’s a damn fine example sir! Humanity is screwed by having more than 2 fingers in total. Yeah, there are 10 kinds of people in the world – those who understand binary and those who don’t.
Delete would look awkward with just two fingers. The numbers represented by the decimal representation 1 and the decimal representation 0. The reason for the imprecision is the nature of number bases. 3 is exactly represented by 0. The values that can be finitely represented depend on the number of unique prime factors of the base, so base 30 can represent more fractions than base 2 or base 10.
The inaccuracy there is because a few billion values are spread across a much greater range. So if you have 23 bits for the significand, you can only represent about 8. Then an 8-bit exponent provides 256 options for distributing those values. This scheme allows the most precise decimals to occur near 0, so you can almost represent 0. It’s not at all unrelated to floating point representation. The base you choose for your floating point defines which numbers can be exactly represented.