On Thu, Jun 03, 2004 at 07:25:41AM +0900, David A. Black wrote: > Hi -- > > On Thu, 3 Jun 2004, Michael Neumann wrote: > > > Hi, > > > > I know that introducing new syntax into Ruby is probably far from being > > accepted by matz.... > > > > Every now and then I accidentially pass an integer to a method and am > > surprised than I get a wrong result. The reason is that the method > > expected floats as arguments and not integers. These kind of bugs are > > very hard to find, IMHO. > > > > Imagine the following method: > > > > def meth(a, b) > > a / b > > end > > > > It works if a, b or both are floats, but not if both are integers. > > > > Instead you have to write: > > > > a.to_f / b > > > > or > > > > a / b.to_f > > > > or > > > > 1.0 * a / b > > > > ... > > > > My proposal is to add a /. operator, that treats both arguments as > > floats, so that > > > > 1 /. 2 # => 0.5 > > But you've still got a "have to write" case -- meaning, when you write > #meth, above, you still can't just write "a / b". So if the problem > is that you forget to write "a.to_f" instead of "a", you're still in > danger of forgetting to write "/." instead of "/". Sure, but when at the time of writing #meth, you think parameters a and b will always be floats (and of course you don't document it, because it's a quick hack :), you'll get in trouble later (e.g. meth(1,2) vs. meth(1.0, 2.0)). So you want use fdiv, as you expect the division to be a floating point division (and for me that's the usual case). Regards, Michael