Project

General

Profile

Actions

Backport #8958

closed

Rational#to_d don't match documentation

Added by ejfinneran (E.J. Finneran) over 10 years ago. Updated over 10 years ago.

Status:
Closed
[ruby-core:<unknown>]

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) [x86_64-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.to_d
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)
=> #BigDecimal:7ffc8c8afaa8,'0.3E1',9(36)

Updated by zzak (zzak _) over 10 years 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!

Updated by zzak (zzak _) over 10 years ago

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

Updated by mrkn (Kenta Murata) over 10 years ago

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

Updated by marcandre (Marc-Andre Lafortune) over 10 years ago

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

Updated by mrkn (Kenta Murata) over 10 years ago

@marcandre (Marc-Andre Lafortune) 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.

Actions #6

Updated by zzak (zzak _) over 10 years 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

Updated by nagachika (Tomoyuki Chikanaga) over 10 years 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.

Updated by zzak (zzak _) over 10 years ago

  • Assignee changed from zzak (zzak _) to nagachika (Tomoyuki Chikanaga)

@nagachika (Tomoyuki Chikanaga) 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!

Actions #9

Updated by nagachika (Tomoyuki Chikanaga) over 10 years 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]
Actions #10

Updated by nagachika (Tomoyuki Chikanaga) over 10 years ago

  • Tracker changed from Bug to Backport
  • Project changed from Ruby master to Backport200
  • Category deleted (doc)
  • Status changed from Closed to Assigned
Actions #11

Updated by nagachika (Tomoyuki Chikanaga) over 10 years 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]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0