> A variant of the float to string conversion that tries to preserve all the > binary information would certainly be useful, but not as the default to_s > method. ¨Βθαισυξμεσσ ωοτθιξτθατ> > irb> .1 - 3.0 > -0.8999999999999999 > > would not be "surprising"! well, at least annoying) At least users would be able to understand this: >> 2.1 - 3.0 => -0.9 >> (2.1-3.0) == -0.9 => false Since it would become >> 2.1 - 3.0 => -0.8999999999999 >> (2.1-3.0) == -0.9 => false I'd prefer the second--at least I'm reminded as to what's going on and don't have to constantly pester ruby talk with questions like "is this normal?" :) However, this would seem surprising >> 0.9 => 0.90000000000000002 It seems slightly more annoying and verbose but more honest. That being said, as someone above mentioned, the current float default output is to "prettify" by stripping the ending few bits [I guess]. Perhaps we should keep this around as a new method name. Like to_human_string or something [?] > One very elegant fix would be to invent a DecimalFloat type. ¨Βχουμθαφε > limited precision, as Floats do, but 0.1 would be represented precisely, as > we finger counting humans expect it to be. ¨Β§φξεφεσεεξ τθισ ινπμενεξτε> in any other language. ¨Βχουμβε γοομ εψπεςινεξτ That would be way cool. Something that elegantly "became" BigDecimal whenever it hit possible loss of precision. My guess is that this would be almost immediately for almost everything, though :) Ex: >> 0.5.class => Float >> 0.9.class => BigDecimal > > What most numerical methods folks do in practice, is to define equality of > floats over an epsilon interval that is context dependent. ¨Βο¬ ιζ ωο> insist on counting dollars with Floats, any values equal to within 1/2 a > penny (or 0.005 dollars) might be considered "equal" for all practical > purposes. ¨Βτιμμιτ§σ παιξ το θαφε το σπεγιζτθεπσιμοαμτθτινε> Here's one way to avoid that: > > require 'delegate' > class Money < DelegateClass(Float) > ¨Βπσιμοξ °®°°> > ¨Βεζ Ό½οτθε> ¨Βιζσεμζ οτθε> ¨Βετυς± ιζ διζζ Επσιμο> ¨Βετυςιζ διζζ Επσιμοξ > > ¨Βξδ > > ¨Βεζ ιξιτιαμιϊε δομμας> ¨Βυπες δομμαςσ®τοίζ > ¨Βξδ > end That would be an option. By default use an epsilon of some quantity. The only problem with this is the one you pointed out--...who can determine a default epsilon? I'm thinking that for now making the default string output be one s.t. some_float == eval("#{some_float}") would be good [and possibly retaining the 'human readable' through some other name, not even to be used with inspect, just something not existing]. Thoughts? -=r