Sorry for being so happy-happy-joy-joy about Ruby lately, I’m still so excited with the new toy I can’t write about much else. I just read this on Guaracy Monteiro’s (mostly brazilian portuguese link, I’m loosely translating):
Well, I’m living in 2005. New languages are born daily, and most of them insist in some of the same mistakes. 3/2 is not equal to 1, but 3/2. I think I learned that in first grade.
Ok, there’s a long and heated argument behind all that, but hey, I started programming exactly because I wanted an easy way out of dull math homework like what we get on the first grade, and computers could do calculations so much better and faster than me when I was 8 (and they still can, last time I checked). But back in the QBasic days, I couldn’t teach the damn computer to figure out the fractions for me, and there was no answer labelled “0.444…” on those tests. So, as you can see, this topic brings back the memories of the first few times I became really frustrated at a computer, something that happens every couple of minutes nowadays. And Ruby just relieved some of that pain:
irb(main):001:0> 3/2
=> 1
irb(main):002:0> 3/2.0
=> 1.5
Well, so far, it’s still frustrating. Behold, the great mathn:
irb(main):003:0> require 'mathn'
=> true
irb(main):004:0> 3/2
=> 3/2
irb(main):005:0> 3/2.0
=> 1.5
irb(main):006:0> 3/2 - 2/2
=> 1/2
Rather odd to see the way basic math works differently after requiring a so innocent-looking module, especially for those used to static languages, but there’s a lot of power and flexibility behind that. I do like power and flexibility, if simplicity comes in the package, and in this case, it does.

B. K. Oxley (binkley) | 05-Apr-05 at 5:45 pm | Permalink
Does it support the full numeric tower ala Smalltalk?
Yuri Schimke | 05-Apr-05 at 11:04 pm | Permalink
Yeah, its a powerful thing. But dangerous when you decide to use it as part of your program, and its breaks the libraries you depend on.
I’m sure there are ways to fix that, like always use (3/2).to_i if you *really* want a int, but I would imagine these kind of “world-changers” are best left for irb sessions, rather than webapps.
Le blog » Maths en Ruby | 06-Apr-05 at 9:18 am | Permalink
[...] du non
Catégorie : Ruby — Nicolas Delsaux @ 10:05 Switch to none
Encore un superbe exemple de la puissance et de la flexibilité du Ruby. Là où tous les [...]
raichu | 10-Oct-05 at 5:16 pm | Permalink
and let uth not forget what the great language known ath lithp hath taught uth
atworksx » Blog Archive » Comment on How much is 3/2? by Computer Game News and Reviews | 19-Nov-07 at 9:09 pm | Permalink
[...] here to read Author Rory Love Comments [...]
atworksx » Blog Archive » Comment on How much is 3/2? by atworksx » Blog Archive » Comment … | 20-Nov-07 at 9:17 am | Permalink
[...] can read the full story here Author Levi Beck Comments [...]