mathn.rb affects Rational literals
$ ruby -e 'p 1.0r' (1/1)
$ ruby -rmathn -e 'p 1.0r' 1
Is this intentional?
Updated by shyouhei (Shyouhei Urabe) about 3 years ago
We looked at this issue at yesterday's developer meeting.
The intension was not made clear, but we confirmed that mathn's global side-effects are the nature of that library. Maybe requiring it implies your willing to accept such surprising behaviour.
Updated by stomar (Marcus Stollsteimer) almost 3 years ago
Seems to be triggered by
ext/mathn/complex/complex.c, which activate "canonicalization" in
$ ruby -r mathn/rational -e 'p Rational(2/1)' 2 $ ruby -r mathn/complex -e 'p Complex("3+0i")' 3
I suppose the reasoning behind the behavior was that in mathematics generally the simplest representation of a number is used, and n/1 = n.
But what are the plans for
mathn anyway? -- It seems to be deprecated since 2.2 (#10169).