Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rational support for %f in sprintf #2160

Closed
headius opened this Issue Nov 9, 2014 · 0 comments

Comments

Projects
None yet
3 participants
@headius
Copy link
Member

headius commented Nov 9, 2014

If I'm reading this right, %f in sprintf gained special handling of Rational values recently.

Here's the test we're failing from mri/ruby/test_sprintf.rb:

  def test_rational
    assert_match(/\A0\.10+\z/, sprintf("%.60f", 0.1r))
    assert_match(/\A0\.010+\z/, sprintf("%.60f", 0.01r))
    assert_match(/\A0\.0010+\z/, sprintf("%.60f", 0.001r))
    assert_match(/\A0\.3+\z/, sprintf("%.60f", 1/3r))
    assert_match(/\A1\.20+\z/, sprintf("%.60f", 1.2r))

    0.upto(9) do |len|
      -1.upto(9) do |prec|
        ['', '+', '-', ' ', '0', '+0', '-0', ' 0', '+ ', '- ', '+ 0', '- 0'].each do |flags|
          fmt = "%#{flags}#{len > 0 ? len : ''}#{prec >= 0 ? ".#{prec}" : ''}f"
          [0, 0.1, 0.01, 0.001, 1.001, 100.0, 100.001, 10000000000.0, 0.00000000001, 1/3r, 2/3r, 1.2r, 10r].each do |num|
            assert_equal(sprintf(fmt, num.to_f), sprintf(fmt, num.to_r), "sprintf(#{fmt.inspect}, #{num.inspect}.to_r)")
            assert_equal(sprintf(fmt, -num.to_f), sprintf(fmt, -num.to_r), "sprintf(#{fmt.inspect}, #{(-num).inspect}.to_r)") if num > 0
          end
        end
      end
    end
  end

The failure occurs in the fourth assert_match:

TestSprintf#test_rational [/Users/headius/projects/jruby/test/mri/ruby/test_sprintf.rb:155]:
Expected /\A0\.3+\z/ to match "0.333333333333333300000000000000000000000000000000000000000000".

There are three commits in MRI that have lines at or after this test: ruby/ruby@1d196e0, ruby/ruby@28dd616, and ruby/ruby@230b845. All three likely have changes we need to incorporate.

Run the test with `jruby test/mri/runner.rb ruby/test_sprintf.rb -n test_rational

@headius headius added the core label Nov 9, 2014

@headius headius added this to the JRuby 9.0.0.0 milestone Nov 9, 2014

headius added a commit that referenced this issue Nov 9, 2014

@headius headius added beginner and removed beginner labels Nov 9, 2014

@enebo enebo added the JRuby 9000 label Jul 14, 2015

@enebo enebo modified the milestone: JRuby 9.0.0.0 Jul 14, 2015

@kares kares added the beginner label Mar 2, 2018

@kares kares self-assigned this Jan 28, 2019

@kares kares removed the beginner label Jan 28, 2019

@enebo enebo closed this in #5584 Feb 11, 2019

@kares kares added this to the JRuby 9.2.7.0 milestone Feb 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.