From: jzakiya on
On Jun 7, 6:59 pm, Andrew Duncan <andrew.dun...(a)sonos.com> wrote:
> As a mathematician, and compiler writer for the last twenty years or so,
> I am aware of that.
>
> Joel VanderWerf wrote:
> > Andrew Duncan wrote:
> >> But (as I now learn as I delve further into canonical Ruby syntax) it is
> >> a "feature" that 5/2 evaluates to 2 and not 2.5. So something of the
> >> sort is happening here.
>
> > Many languages, including C, do integer division that way.
>
> --
> Posted viahttp://www.ruby-forum.com/.

Using Ruby 1.8.7-p249 installed with rvm:

I get this:
-----------------------------------------
require 'complex'

Complex(1,1)**-1
=> Complex(0.5, -0.5)

1/Complex(1,1)
=> Complex(0, -1)
-----------------------------------------
But, when I use the 'mathn' lib I get:

require 'mathn'

Complex(1,1)**-1
=> Complex(1/2, -1/2)

1/Complex(1,1)
=> Complex(1/2, -1/2)
-----------------------------------------

So require the mathn library first for 1.8.7 to get correct results.

For 1.9.1 and 1.9.2 I also get correct results for both cases straight
out of the box.

From: Joel VanderWerf on
Andrew Duncan wrote:
> As a mathematician, and compiler writer for the last twenty years or so,
> I am aware of that.
>
> Joel VanderWerf wrote:
>> Andrew Duncan wrote:
>>> But (as I now learn as I delve further into canonical Ruby syntax) it is
>>> a "feature" that 5/2 evaluates to 2 and not 2.5. So something of the
>>> sort is happening here.
>> Many languages, including C, do integer division that way.

Sorry (*blush*). It's just a knee-jerk reaction to newcomers to this
list who start talking about a "feature" of ruby that cannot possibly be
correct and must be changed.

Again, I apologize for that (and for assuming you are a newb).

From: Robert Dober on
On Mon, Jun 7, 2010 at 9:38 PM, Andrew Duncan <andrew.duncan(a)sonos.com> wrote:
> I have ruby 1.8.7 (2009-06-08 patchlevel 173) [universal-darwin10.0]
>
> BTW, I hope that was 1/2 - 1/2i in your post...
That is how Irb shows them, why not provide a patch? We are spoiled,
aren't we? No offense intended I mean we are indeed *spoiled* by what
we get for free, and sometimes things are not perfect.
Cheers
R.


--
The best way to predict the future is to invent it.
-- Alan Kay