# BigDecimal Bugs

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

1. ### Bret JollyGuest

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

2. ### Bret JollyGuest

(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