From: MikkelFJ Date: 2001-07-29T21:29:40+09:00 Subject: [ruby-talk:18736] Re: Numbers classes.. Rational number? [was: Ruby as opposed to Python?] > 5 / 2 => Rational(5, 2) > 5.0 / 2 => Float(2.5) First to the earlier argument about "those who grew up with statically typed languages" I'd say: Those who grew up with algebra (not just 1 school year) will appreciate that integer division is indeed a very clean an meaningful operation. All integers within a limited domains size like 8 bit or 32 bit has a very strong mathematical background. Therefore, there is abselutely nothing wrong with the current behaviour, and it certainly would be missed for some purposes. Now Ruby doesn't have a fixed size domain because of BigInt, but the domain of integers is equally welldefined and you get directly to the n-bit world using modulo 2^n on the result of an operation (+,-,*,/). The next issue is when should you do automatic typeconversions? You can define integer division to not be closed operation (i.e. output domain being different from input domain). Then you get things like float or rational conversion. But Ruby actually performs less automatic conversion than you see in C++. Recall the 99 bottles thread where you had to have numbers substituted into a string, or alternative use .to_s. So why should Ruby behave different with respect to integer to real or rational numbers, when it doesn't even automatically convert integer to string? Of course converting integer to real of the division isn't much fun as the information has then been lost. This means that the division should know its target type, and that is a bit difficult in a type system as Rubys, especially when interpreted. what about Rational(5, 1) / Rational(2,1) -> Rational(5,2) 5 / 2 -> 2 5.0 / 2.0 -> 2.5 And then for pragmatic reasons define automatic conversion when there are mixed types: 5.0 / 2 -> 2.5 This is what Ruby does today - and actually I so no practical or mathematical reason to change it. However the latter example is dangerously close to operator overloading. Anyone can of cause do the same in their own operations. Perhaps a typematching library would be a nice substitute for operator overloading in Ruby? Somebody probably already wrote this. Mikkel