From: Austin Ziegler Date: 2002-12-28T13:52:42+09:00 Subject: Re: 1210 / 100 = 12? what? On Sat, 28 Dec 2002 13:23:24 +0900, Pe�a, Botp wrote: > Tom Sawyer [mailto:transami@transami.net] wrote: >> no i didn't realize that. i thought ruby would automatically >> change it to a float if need be, i.e. with divison, just as it >> changes to Bignum if need be. >> >> honestly i don't like it. now i have to go around adding .0's all >> over the place to make sure the math comes out right. and in some >> places i have to do things like multiple by 1.0 b/c certain >> values come from cgi script variables i have no control over. > (though I'm late in the thread) I'm in agreement. I like Ruby > since it's supposed to be _closer_ to our minds ;-) > When I scribble on a division, I should not be needing to append > ".0" :-( > Com'on, I thought we've passed thru 3GL langs (I admit I still > love fortran and c, but I have to grow :-)... This is one of the things where a statically typed language will do the "right" thing but a dynamically typed language won't. The #/ method returns a new reference to a Fixnum object, because only Fixnums are known as the receiver and message object. C et al. will silently and automatically convert the integers to floating point values. What I'd actually like to see (and in some ways, this is Perl wantarray envy) is this: (n, r) = 5 / 4 # n == 1, r == 1 In this way, I don't have to do: n = 5 / 4 r = 5 % 4 It may not be any more efficient, but it looks cleaner. Sort of. Perhaps something like this could be done: (n, r) = 5 // 4 # n == 1, r == 1 Introducing a new operator, #//. I generally prefer integer or fixed-point operations over floating point operations (greater accuracy at the cost of variable precision), so I find them less surprising. -austin -- Austin Ziegler, austin@halostatue.ca on 2002.12.27 at 23.42.40