Backport #8958

Rational#to_d don't match documentation

Added by E.J. Finneran 7 months ago. Updated 4 months ago.

[ruby-core:<unknown>]
Status:Closed
Priority:Normal
Assignee:Tomoyuki Chikanaga

Description

The documentation states that Rational#to_d (added by BigDecimal) has an optional parameter to limit the precision. However, that parameter is not optional as implemented.

http://www.ruby-doc.org/stdlib-2.0.0/libdoc/bigdecimal/rdoc/Rational.html

╰─○ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x8664-darwin12.5.0]
╰─○ irb
2.0.0p247 :001 > require 'bigdecimal'
=> true
2.0.0p247 :002 > require 'bigdecimal/util'
=> true
2.0.0p247 :003 > 3.to
r.tod
ArgumentError: wrong number of arguments (0 for 1)
from /Users/ej/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/bigdecimal/util.rb:98:in to_d'
from (irb):3
from /Users/ej/.rvm/rubies/ruby-2.0.0-p247/bin/irb:16:in
'
2.0.0p247 :004 > 3.to
r.to_d(1)
=> #

Associated revisions

Revision 44314
Added by Tomoyuki Chikanaga 4 months ago

merge revision(s) 43669,43672,43678: [Backport #8958]

* ext/bigdecimal/lib/bigdecimal/util.rb: [DOC] Document the required
  +precision+ argument for Rational#to_d [Bug #8958]

* ext/bigdecimal/lib/bigdecimal/util.rb: [DOC] +precision+ is required

* ext/bigdecimal/lib/bigdecimal/util.rb: [DOC] remove example of
  Rational#to_d without argument. [Bug #8958]

History

#1 Updated by Zachary Scott 7 months ago

  • Status changed from Open to Assigned

It seems the documentation is wrong, the implementation is a required argument: https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/lib/bigdecimal/util.rb#L119

I have asked for feedback from murata-san to confirm this spec in BigDecimal.

Thank you for finding this bug!

#2 Updated by Zachary Scott 6 months ago

Still looking into this one E.J. thanks for your patience.

#3 Updated by Kenta Murata 6 months ago

I think this is a bug of Rational#to_d. I'll fix it.

#4 Updated by Marc-Andre Lafortune 5 months ago

@mrkn I'm not sure it would make sense to have a default precision here... Is there a default precision anywhere in the BigDecimal library?

#5 Updated by Kenta Murata 5 months ago

@marcandre Yes. We cannot determine a default precision for a rational number generally. I think I confused when I replied #3.

So this issue can be closed.

#6 Updated by Zachary Scott 5 months ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r43669.
E.J., thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • ext/bigdecimal/lib/bigdecimal/util.rb: [DOC] Document the required +precision+ argument for Rational#to_d [Bug #8958] -This line, and those below, will be ignored--

M ChangeLog
M ext/bigdecimal/lib/bigdecimal/util.rb

#7 Updated by Tomoyuki Chikanaga 5 months ago

  • Status changed from Closed to Assigned
  • Backport set to 1.9.3: DONTNEED, 2.0.0: REQUIRED

Hi,

There are still examples of Rational#to_d without arguments in documentation at call-seq section and sample code.

#8 Updated by Zachary Scott 5 months ago

  • Assignee changed from Zachary Scott to Tomoyuki Chikanaga

@nagachika good catch, i removed the incorrect call-seq in r43672: https://github.com/ruby/ruby/commit/62d3853

I will assign it to you for backporting, thanks!

#9 Updated by Tomoyuki Chikanaga 5 months ago

  • Status changed from Assigned to Closed

This issue was solved with changeset r43678.
E.J., thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • ext/bigdecimal/lib/bigdecimal/util.rb: [DOC] remove example of Rational#to_d without argument. [Bug #8958]

#10 Updated by Tomoyuki Chikanaga 4 months ago

  • Tracker changed from Bug to Backport
  • Project changed from ruby-trunk to Backport200
  • Category deleted (doc)
  • Status changed from Closed to Assigned

#11 Updated by Tomoyuki Chikanaga 4 months ago

  • Status changed from Assigned to Closed

This issue was solved with changeset r44314.
E.J., thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


merge revision(s) 43669,43672,43678: [Backport #8958]

* ext/bigdecimal/lib/bigdecimal/util.rb: [DOC] Document the required
  +precision+ argument for Rational#to_d [Bug #8958]

* ext/bigdecimal/lib/bigdecimal/util.rb: [DOC] +precision+ is required

* ext/bigdecimal/lib/bigdecimal/util.rb: [DOC] remove example of
  Rational#to_d without argument. [Bug #8958]

Also available in: Atom PDF