BigDecimal Bugs

B

Bret Jolly

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
 
B

Bret Jolly

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
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top