BigDecimal from CVS

H

Holden Glova

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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

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

3. 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:in `new'
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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/KlFd0X8w8X71zPcRAl69AJ98vbnn9SF6rWyzylt2Z0yAfwj2yACeNVI2
31bX/zk762+gWjrzTZ2Q6ig=
=XW9P
-----END PGP SIGNATURE-----
 
T

ts

H> irb(main):002:0> require 'bigdecimal/util'
H> => true
H> irb(main):003:0> '111.333333'.to_d
H> 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
 
H

Holden Glova

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

H> irb(main):002:0> require 'bigdecimal/util'
H> => true
H> irb(main):003:0> '111.333333'.to_d
H> 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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/Kt+10X8w8X71zPcRArRGAJ97Vkwoq5fneg/D8Gyi5iZ1oPZp/wCeOlos
CshnPO+u9Z1seqG7vVyF1SM=
=SNCE
-----END PGP SIGNATURE-----
 
T

ts

H> Ok, thank you for pointing out my user error. What about the Float#to_d, is
H> 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 <[email protected]>

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


Guy Decoux
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top