Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > BigDecimal from CVS

Reply
Thread Tools

BigDecimal from CVS

 
 
Holden Glova
Guest
Posts: n/a
 
      08-01-2003
-----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/KlFd0X8w8X71zPcRAl69AJ98vbnn9SF6rWyzylt2Z0yAfwj2yA CeNVI2
31bX/zk762+gWjrzTZ2Q6ig=
=XW9P
-----END PGP SIGNATURE-----


 
Reply With Quote
 
 
 
 
ts
Guest
Posts: n/a
 
      08-01-2003
>>>>> "H" == Holden Glova <> writes:

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

 
Reply With Quote
 
 
 
 
Holden Glova
Guest
Posts: n/a
 
      08-02-2003
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sat, 02 Aug 2003 00:41, ts wrote:
> >>>>> "H" == Holden Glova <> writes:

>
> 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-----


 
Reply With Quote
 
ts
Guest
Posts: n/a
 
      08-02-2003
>>>>> "H" == Holden Glova <> writes:

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 <>

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


Guy Decoux

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BigDecimal(String) vs. BigDecimal(double) [Floating-point arithmetics] Stanimir Stamenkov Java 4 07-18-2008 10:49 AM
Eclipse and CVS, Eclipse wipes out CVS directories xyzzy12@hotmail.com Java 1 08-31-2007 10:19 AM
Eclipse 3.2 and CVS - where and how to get and install CVS? ddog Java 3 08-04-2007 06:41 PM
BigDecimal to power of BigDecimal czarnysfetr@gmail.com Java 3 02-05-2007 02:49 PM
[ANN] Ruby CVS IRC bot, and Ruby CVS RSS feed David Ross Ruby 5 12-05-2004 03:48 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57