On Sep 10, 2013, at 9:09 PM, marcandre (Marc-Andre Lafortune) wrote:

>=20
> Issue #8883 has been updated by marcandre (Marc-Andre Lafortune).
>=20
>=20
> david_macmahon (David MacMahon) wrote:
>> While playing around with this, I see that integer Floats also have =
some special handling:
>=20
> Right. Floats are inexact while Integers & Rational are exact, and so =
are Complex with exact components. Rational(1/1) and 1 should yield the =
same mathematical result, but with floats that can be tricky.  For =
example there are infinitely many different bigdecimals that will map to =
1.0 (say 1.000....1 and 1.000...2 with enough zeros), but they don't =
behave exactly the same way, for example if you substract 1), so we =
can't freely map them.

That's all fine from a numerical/mathematical point of view, but it =
still seems like there is something missing from the duck typing:

$ ruby -e 'p (1/1.0).nan?'
false

$ ruby -r mathn -e 'p (1/1.1).nan?'
false

$ ruby -r mathn -e 'p (1/1.0).nan?'
-e:1:in `<main>': undefined method `nan?' for (1/1):Rational =
(NoMethodError)

Though admittedly this is getting a bit far from the OP.

>=20
>> Oddly though, this can result in non-reduced Rationals:
>>=20
>> $ ruby -r mathn -e 'p [2/2.0, 2/2.5]'
>> [(2/2), 0.8]
>=20
> Oh oh, that's a bug. It's not even related to 'mathn'. I opened a new =
issue about this: https://bugs.ruby-lang.org/issues/8894

Thanks!

Dave