From: jweirich@... Date: 2001-07-30T20:32:45+09:00 Subject: [ruby-talk:18799] Re: Ruby as opposed to Python? >>>>> "Florian" == Florian G Pflug writes: Florian> On Mon, Jul 30, 2001 at 01:02:54PM +0900, Paul Prescod wrote: >> > If you write a function, which depends on 1/2 being 0.5, why >> > don't you just write a.to_f / b.to_f? >> Yes, that's a workaround. Florian> Or just stating what the programmer _really_ wants.... Most of the time, the choice of truncating vs non-truncating behavior is made by the programmer writing the formula or algorithm involving the division. If this is true, then the current behavior where the type of division is chosen by the input arguments forces each and every use of the division operator to use the workaround (e.g. use to_f, to_i, or floor as appropriate). This seems to be unnecessarily error prone. Since the most of the uses of "/" require additional work to clarify whether truncating or non-truncating division is required, the suggestion is to have the "/" operator always do non-truncating division and have a different operator (or method) always to truncating division. Python chose "//" as the truncating operator. There are a number of other options. IIRC, Pascal used "/" for the non-truncating division operator and "DIV" as the truncating one. The above analysis is flawed if there are a lot of algorithms that require the behavior of "/" (truncating vs non-truncating) to depend upon the type of input argument. Personally, I can't think of a single example where that type of operand dependent behavior for "/" is useful. Changing the definition of "/" will be painful and will probably break some code. Matz has already indicated that "/" may return rational in the future, so that pain may be coming no matter what. Well, until that time, I know I'm going to be careful using division in my programs. -- -- Jim Weirich jweirich@one.net http://w3.one.net/~jweirich --------------------------------------------------------------------- "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)