BigDecimal from CVS

Discussion in 'Ruby' started by Holden Glova, Aug 1, 2003.

  1. Holden Glova

    Holden Glova Guest

    -----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-----
     
    Holden Glova, Aug 1, 2003
    #1
    1. Advertising

  2. Holden Glova

    ts Guest

    >>>>> "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
     
    ts, Aug 1, 2003
    #2
    1. Advertising

  3. Holden Glova

    Holden Glova Guest

    -----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-----
     
    Holden Glova, Aug 2, 2003
    #3
  4. Holden Glova

    ts Guest

    >>>>> "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
     
    ts, Aug 2, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    1,233
  2. ddog
    Replies:
    3
    Views:
    596
    Jason Whaley
    Aug 4, 2007
  3. Replies:
    1
    Views:
    602
    GArlington
    Aug 31, 2007
  4. Stanimir Stamenkov
    Replies:
    4
    Views:
    2,591
    Stanimir Stamenkov
    Jul 18, 2008
  5. David Ross
    Replies:
    5
    Views:
    155
    Nicholas Van Weerdenburg
    Dec 5, 2004
Loading...

Share This Page