Mathematically, 0.9 recurring can be shown to be equal to 1. This question however, is not about infinity, convergence, or the maths behind this.
The above assumption can be represented using doubles in C# with the following.
var oneOverNine = 1d / 9d;
var resultTimesNine = oneOverNine * 9d;
Using the code above, (resultTimesNine == 1d)
evaluates to true.
When using decimals instead, the evaluation yields false, yet, my question is not about the disparate precision of double and decimal.
Since no type has infinite precision, how and why does double maintain such an equality where decimal does not? What is happening literally 'between the lines' of code above, with regards to the manner in which the oneOverNine
variable is stored in memory?
= 1 — the sequence of terminating decimals 0.9, 0.99, 0.999, 0.9999, and so on, converges to 1, so the repeating decimal 0.9999... representing the limit of that sequence, is said to be equal to 1. The same idea works for any rational number with a repeating infinite decimal expansion. 0.333...
No, there is not a number between 1 and 0.9999 repeating. This is because they are equal.
We first let 0.9 (9 being repeated) be x . Since x is recurring in 1 decimal places, we multiply it by 10. Next, we subtract them. Lastly, we divide both sides by 9 to get x as a fraction.
ANSWER : 0.9999 is non terminating recurring,so it is a RATIONAL NUMBER.
It depends on the rounding used to get the closest representable value to 1/9. It could go either way. You can investigate the issue of representability at Rob Kennedy's useful page: http://pages.cs.wisc.edu/~rkennedy/exact-float
But don't think that somehow double is able to achieve exactness. It isn't. If you try with 2/9, 3/9 etc. you will find cases where the rounding goes the other way. The bottom line is that 1/9 is not exactly representable in binary floating point. And so rounding happens and your calculations are subject to rounding errors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With