From: Marc-Andre Lafortune Date: 2010-04-19T07:14:58+09:00 Subject: [ruby-core:29605] Re: [Feature #1408] 0.1.to_r not equal to (1/10) Hi Matthias, I hope my dissent will not sound too harsh. Let's call the set of numbers that can be represented exactly by floating numbers "S". S is dependant on your representation, which makes it very uninteresting, so let's assume we're dealing with IEEE 754 doubles. Doing any mathematical operation on members of S does not usually result in a real number member of S. Moreover, most of S that are < 1 need a very long decimal representation. Take the float number that approximates 1/10. Its exact decimal representation is: 0.1000000000000000055511151231257827021181583404541015625 (You can verify this with 0.1.to_r * 10**56 ) Arguing that 0.1.to_r should be 3602879701896397/36028797018963968 is the same as arguing that 0.1.to_s should outputs these 55 decimals. If S was important, if most inputs were actual members of S, that is the output we would need. But most inputs are not be members of S, and most results of calculations will not be members of S either. For these reasons, the set S is of little interest to anybody. What *is* interesting is the set of real numbers. Floating numbers are used to represent them *approximately*. To add to my voice, here are a couple of excerpts from the first links that come up on google (highlight mine): "In computing, floating point describes a system for representing numbers that would be too large or too small to be represented as integers. Numbers are in general represented *approximately* to a fixed number of significant digits and scaled using an exponent." http://en.wikipedia.org/wiki/Floating_point "Squeezing infinitely many real numbers into a finite number of bits requires an *approximate* representation.... Therefore the result of a floating-point calculation must often be rounded in order to fit back into its finite representation. This rounding error is the characteristic feature of floating-point computation." source: http://docs.sun.com/source/806-3568/ncg_goldberg.html Note that typing 0.1 in Ruby is a "calculation" which consists in finding the member of S closest to 1/10. Your final question was: how do I know that the value someone is talking about is 0.1 and not 0.1000000000000000055511151231257827021181583404541015625 (or equivalently 3602879701896397/36028797018963968) ? I call it common sense. Marc-Andr�