Hi,

On Sun, Sep 20, 2009 at 9:19 AM, Rick DeNatale <rick.denatale / gmail.com> wr=
ote:
>
> Actually in most languages which I've encountered, and that's quite a
> few. Mixed mode arithmetic has been implemented by having some kind of
> rules on how to 'overload' arithmetic operators based on the
> arguments, not by having different operator syntax.
>
> And those rules are usually based on doing conversions only when
> necessary so as to preserve what information can be preserved given
> the arguments,
>
> So, for example
>
> =A0 =A0integer op integer - normally produces an integer for all of the
> 'big four' + - * /
> =A0 =A0integer op float =A0 =A0- normally produces a float, as does float=
 op integer
>
> As new numeric types are added, in languages which either include them
> inherently or allow them to be added, this pattern is usually
> followed.

This is a distinctly different issue. Mixed-type arithmetic in Ruby is
handled by the #coerce protocol.

>>
>> As for which symbol to select, what about '/.' for real(a)/real(b).
>
> Well, first the problem we are talking about is Rationals, not Floats,
> and second, what happens as more numeric classes are introduced.

The mathn library aliases Fixnum and Bignum #quo to #/. By default
#quo returns a Float. Rational redefines #quo to produce a Rational
rather than a Float.

But what class of object is not the point. It could be Complex. The
point is that integers are not closed under division so you *must*
choose one of the options if you expect a value when dividing any two
integers.

The division operation is so fundamental that assumptions about it
should not change under your feet. Having a separate operator that
returns a different type when integral division would be undefined
allows both normal algorithms and mathy stuff to coexist nicely. In my
algorithms, I *never* want my integral division to suddenly return
something non-integer. In my math codes, I almost never want my
quotient truncated or rounded.

Cheers,
Brian