BigDecimal Bugs

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

oinkoink+unet@rexx.com (Bret Jolly) wrote in message news:7e7131a1.0309021034.35e70d0f@posting.google.com

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

Sorry to follow up to myself, but…

I found the problem with -Infinity.
In the file ruby-1.8.0/ext/bigdecimal/bigdecimal.h,
the line:
#define SZ_NINF “+Infinity”
should be:
#define SZ_NINF “-Infinity”

                   Regards, Bret

oinkoink+unet@rexx.com (Bret Jolly) wrote in message news:7e7131a1.0309021034.35e70d0f@posting.google.com

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,

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

This looks like a bug in bigdecimal.c at line 2046.  This patch should

fix it:

— bigdecimal.c Fri Aug 1 02:08:43 2003
+++ bigdecimal.c.new Tue Sep 2 17:45:00 2003
@@ -2043,7 +2043,7 @@
return 0;
}
if(VpIsInf(a)) {

  •    VpSetInf(c,isw);
    
  •    VpSetInf(c,isw*VpGetSign(a));
       return 0;
    

    }

    I know you have already fixed the negative infinity display bug, but for
    completeness, here is the patch:

— bigdecimal.h Fri Aug 1 02:08:43 2003
+++ bigdecimal.h.new Tue Sep 2 17:45:00 2003
@@ -26,7 +26,7 @@
#define SZ_NaN “NaN”
#define SZ_INF “Infinity”
#define SZ_PINF “+Infinity”
-#define SZ_NINF “+Infinity”
+#define SZ_NINF “-Infinity”

/*

  • #define VP_EXPORT other than static to let VP_ routines
I hope this helps.

- Warren Brown
This looks like a bug in bigdecimal.c at line 2046.  This patch should

fix it:
Yes, these bugs have been fixed in the most recent CVS version.
http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/ext/bigdecimal/

I know you have already fixed the negative infinity display bug, but

for

completeness, here is the patch:
Thank you anyway!

shigeo@tinyforest.jp

···

----- Original Message -----
From: “Warren Brown” wkb@airmail.net
Subject: [PATCH] RE: BigDecimal Bugs

“Warren Brown” wkb@airmail.net wrote in message news:005301c371a4$0e40d150$670b88cf@warrenpc

Bret,
[bigdecimal patch]
I hope this helps.

Thanks, Warren! And thanks to Shigeo, who points out this
is now fixed in CVS.

            Regards, Bret