Although the varied results of this make it clear that the phenomenon is
probably not a *planned* feature of Ruby, it could just be a consequence
of integer vs. float context.
Probably the designers of Ruby were not intending to emulate the
Gaussian integers! (I.e. complex numbers with only integral real and
imaginary parts.)
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.
Lesson: always specify complex literals with the trailing ".0" to force
them to be evaluated as floats!
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.
···
On Mon, Jun 7, 2010 at 9:38 PM, Andrew Duncan <andrew.duncan@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...
--
The best way to predict the future is to invent it.
-- Alan Kay
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.
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.
On Jun 7, 6:59 pm, Andrew Duncan <andrew.dun...@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.
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).