BigDecimal Bugs

Discussion in 'Ruby' started by Bret Jolly, Sep 2, 2003.

  1. Bret Jolly

    Bret Jolly Guest

    I can't get BigDecimal to generate a -Infinity,
    using the same tricks that used to work with BigFloat.

    irb(main):001:0> require 'bigdecimal'
    true
    irb(main):002:0> c = BigDecimal.new("1")/BigDecimal.new("0")
    #<BigDecimal:400cc144,'Infinity',4(24)>
    irb(main):003:0> c = -c
    #<BigDecimal:400c43e0,'+Infinity',4(12)>
    irb(main):004:0> c = BigDecimal.new("-1")/BigDecimal.new("0")
    #<BigDecimal:400b64d4,'+Infinity',4(24)>
    irb(main):005:0> c = BigDecimal.new("1")/BigDecimal.new("-0")
    #<BigDecimal:4008b924,'+Infinity',4(24)>

    BigDecimal also does not compare with Float, though it
    does apparently compare with Integer.

    irb(main):006:0> c = BigDecimal.new("3.0")
    #<BigDecimal:40109508,'0.3E1',4(8)>
    irb(main):007:0> c < 7
    true
    irb(main):008:0> c < 7.0
    false

    This is the BigDecimal class that comes with Ruby 1.8.0

    Regards, Bret
     
    Bret Jolly, Sep 2, 2003
    #1
    1. Advertising

  2. Bret Jolly

    Bret Jolly Guest

    (Bret Jolly) wrote in message news:<>...
    > I can't get BigDecimal to generate a -Infinity,
    > using the same tricks that used to work with BigFloat.


    Following up to myself yet again (*blush*):

    Even after correcting bigdecimal.h so that
    #define SZ_NINF "+Infinity"
    becomes
    #define SZ_NINF "-Infinity"
    I get peculiar behavior.

    irb(main):001:0> require 'bigdecimal'
    true
    irb(main):002:0> a = BigDecimal.new("1")/BigDecimal.new("0")
    #<BigDecimal:400cc144,'Infinity',4(24)>
    irb(main):003:0> b = -a
    #<BigDecimal:400c43e0,'-Infinity',4(12)>
    irb(main):004:0> c = -b
    #<BigDecimal:400bc528,'-Infinity',4(12)>
    irb(main):005:0> a == b
    false
    irb(main):006:0> b == c # ?!!
    true
     
    Bret Jolly, Sep 2, 2003
    #2
    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. Forrest Hump
    Replies:
    4
    Views:
    24,290
    Mark Meyer
    Aug 22, 2003
  2. Cory Musselman

    Problems with XMLEncoder and BigDecimal

    Cory Musselman, Oct 30, 2003, in forum: Java
    Replies:
    0
    Views:
    2,259
    Cory Musselman
    Oct 30, 2003
  3. Replies:
    3
    Views:
    1,233
  4. Stanimir Stamenkov
    Replies:
    4
    Views:
    2,591
    Stanimir Stamenkov
    Jul 18, 2008
  5. Josef 'Jupp' Schugt

    Still use 'ruby-bugs' for Ruby bugs?

    Josef 'Jupp' Schugt, Nov 4, 2004, in forum: Ruby
    Replies:
    2
    Views:
    163
    Tom Copeland
    Nov 4, 2004
Loading...

Share This Page