Project

General

Profile

Actions

Bug #13104

closed

mathn.rb affects Rational literals

Added by nobu (Nobuyoshi Nakada) over 7 years ago. Updated over 4 years ago.

Status:
Closed
Target version:
-
[ruby-core:78976]

Description

Without mathn:

$ ruby -e 'p 1.0r'
(1/1)

With mathn:

$ ruby -rmathn -e 'p 1.0r'
1

Is this intentional?

https://github.com/ruby/ruby/compare/trunk...nobu:bug/rational-literal-mathn

Updated by shyouhei (Shyouhei Urabe) over 7 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 nobu (Nobuyoshi Nakada) over 7 years ago

  • Subject changed from math.rb affects Rational literals to mathn.rb affects Rational literals

Just "don't use math"?

Updated by stomar (Marcus Stollsteimer) about 7 years ago

Seems to be triggered by ext/mathn/rational/rational.c and ext/mathn/complex/complex.c, which activate "canonicalization" in rational.c and complex.c.

$ 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).

Updated by naruse (Yui NARUSE) over 6 years ago

  • Target version deleted (2.5)

mathn is out of scope from release engineering.

Updated by jeremyevans0 (Jeremy Evans) over 4 years ago

  • Status changed from Assigned to Closed

mathn was removed in Ruby 2.5.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0