Robert Klemme wrote: > David has said it all - here are some additional remarks. > > "Michael Neumann" <mneumann / ntecs.de> schrieb im Newsbeitrag > news:20040602165312.GA25813 / miya.intranet.ntecs.de... >>IMHO, even better would be if / would always mean floating point >>division and an extra // operator would mean integer division, but it's >>to late to change now (even for Ruby 2.0) :-) > > I strongly oppose that one: Operators are overloaded and if I have two > int's I want integer division, if I have to floats I want float division. > And I don't want that changed, because often code is written with integer > divisions in mind. All sorts of indexing calculations depend on int math. Then your code will break whenever it is used in a program that requires "mathn". You should always use div if you want integer division. The truth is that Ruby's / operator is broken. Any time a programmer uses a / operation, they intend the operation to be either a float divide or an int divide, not something that polymorphically switches its semantics based on the operands. Anytime you use / to mean int division, it will break if given floats (or someone required mathn). Anytime you use / to mean float division, it will break if given 2 ints. In a perfect world where backward compatibility wasn't an issue, I would make / always mean float division and // always mean int division. If I were to worry about backward compatibility, leave / as is (and never use it!). And then provide specific operators for int and float division. /. and // aren't too bad. div and fdiv (as methods, not operators) are not bad either. I recall in earlier threads on this topic that Matz was uncomfortable defining division of integers (exact values) so that it returns an inexact result. I think he was implying that a future ruby might return rationals for integer division. I think that makes sense. -- -- Jim Weirich jim / weirichhouse.org http://onestepback.org ----------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)