BigDecimal from CVS

Hello,

I just got the CVS version of Ruby installed and was pleasantly surprised to
see a BigDecimal class. I started playing with it in irb and came up against
some confusion.

  1. The comment at the top of RUBY_HOME/bigdecimal/util.rb says the following:

Float#

to_d … to BigDecimal

Yet the code says it returns a BigFloat
class Float < Numeric
def to_d
BigFloat::new(selt.to_s)
end
end

  1. Also, is this a typo?
    class Float < Numeric
    def to_d
    BigFloat::new(selt.to_s) <— should be self?
    end
    end

  2. I thought I could use String#to_d as the file comment suggests:

String#

to_d … to BigDecimal

Yet when I do this in irb it gives me an error:
irb(main):002:0> require ‘bigdecimal/util’
=> true
irb(main):003:0> ‘111.333333’.to_d
ArgumentError: wrong number of arguments(1 for 0)
from /usr/lib/ruby/1.8/bigdecimal/util.rb:29:in initialize' from /usr/lib/ruby/1.8/bigdecimal/util.rb:29:innew’
from /usr/lib/ruby/1.8/bigdecimal/util.rb:29:in `to_d’
from (irb):3
User error here on my part?

Thanks in advance for any responses.


Signed,
Holden Glova

irb(main):002:0> require 'bigdecimal/util'
=> true
irb(main):003:0> '111.333333'.to_d
ArgumentError: wrong number of arguments(1 for 0)

svg% ruby -rbigdecimal -rbigdecimal/util -e 'p "111.333333".to_d'
#<BigDecimal:40097ef0,'0.1113333330 0E3',12(16)>
svg%

svg% ruby -rbigdecimal -e 'p BigDecimal.new("111.333333")'
#<BigDecimal:40099944,'0.1113333330 0E3',12(16)>
svg%

svg% ruby -rbigdecimal -e 'p BigDecimal("111.333333")'
#<BigDecimal:40099958,'0.1113333330 0E3',12(16)>
svg%

Guy Decoux

Ok, thank you for pointing out my user error. What about the Float#to_d, is
that supposed to be BigFloat::new(selt.to_s) ?


Signed,
Holden Glova

···

On Sat, 02 Aug 2003 00:41, ts wrote:

irb(main):002:0> require ‘bigdecimal/util’
=> true
irb(main):003:0> ‘111.333333’.to_d
ArgumentError: wrong number of arguments(1 for 0)

svg% ruby -rbigdecimal -rbigdecimal/util -e ‘p “111.333333”.to_d’
#<BigDecimal:40097ef0,‘0.1113333330 0E3’,12(16)>
svg%

svg% ruby -rbigdecimal -e ‘p BigDecimal.new(“111.333333”)’
#<BigDecimal:40099944,‘0.1113333330 0E3’,12(16)>
svg%

svg% ruby -rbigdecimal -e ‘p BigDecimal(“111.333333”)’
#<BigDecimal:40099958,‘0.1113333330 0E3’,12(16)>
svg%

Guy Decoux

Ok, thank you for pointing out my user error. What about the Float#to_d, is
that supposed to be BigFloat::new(selt.to_s) ?

Well selt is probably a typo, now for BigFloat

···

Wed Apr 17 23:55:34 2002 Akinori MUSHA <knu@iDaemons.org>

        * ext/Setup*, ext/bigfloat/*: Back out the import of BigFloat in
          favor of its forthcoming successor, BigDecimal.

Guy Decoux

selt may be a fypo … like BigTloaf

···

“ts” decoux@moulon.inra.fr wrote:

that supposed to be BigFloat::new(selt.to_s) ?

Well selt is probably a typo, now for BigFloat