[#144] Another implementation of Bignum — "Dmitry Antipov" <dmitry.antipov@...>

Hello Ruby hackers,

15 messages 2002/06/06

Bignum bug

From: "Christoph" <chr_news@...>
Date: 2002-06-10 16:14:00 UTC
List: ruby-core #166
Hi,


the changes 1.43-1.44 and 1.31.2.12 back in 
October/November last year created a logical
bug (IMO of course;-). Before this change

---
10**400           > 0.0            # => true
10**400 + 10**400 > 0.0 + 10**400 
---

would raise a FloatDomainError, now we are getting

---
10**400           > 0.0            # => true
10**400 + 10**400 > 0.0 + 10**400  # => false
---

in other words ``+'' and ``>'' are in-compatible
(technically you could say that ``>'' is not an
admissible order with respect to ``+''). 
  

/Christoph



--- ruby/bignum.c	2001/10/29 05:07:17	1.43
+++ ruby/bignum.c	2001/10/30 08:43:25	1.44
@@ -3,7 +3,7 @@
   bignum.c -
 
   $Author: matz $
-  $Date: 2001/10/29 05:07:17 $
+  $Date: 2001/10/30 08:43:25 $
   created at: Fri Jun 10 00:48:55 JST 1994
 
   Copyright (C) 1993-2001 Yukihiro Matsumoto
@@ -561,7 +561,13 @@ rb_big_cmp(x, y)
 	break;
 
       case T_FLOAT:
-	y = dbl2big(RFLOAT(y)->value);
+        {
+	  double d = rb_big2dbl(x);
+
+	  if (d == RFLOAT(y)->value) return INT2FIX(0);
+	  if (d > RFLOAT(y)->value) return INT2FIX(1);
+	  if (d < RFLOAT(y)->value) return INT2FIX(-1);
+	}
 	break;
 
       default:


and


diff -u -p -r1.31.2.12 -r1.31.2.13
--- ruby/bignum.c	2001/08/24 06:36:14	1.31.2.12
+++ ruby/bignum.c	2001/10/29 05:04:40	1.31.2.13
@@ -3,7 +3,7 @@
   bignum.c -
 
   $Author: matz $
-  $Date: 2001/08/24 06:36:14 $
+  $Date: 2001/10/29 05:04:40 $
   created at: Fri Jun 10 00:48:55 JST 1994
 
   Copyright (C) 1993-2000 Yukihiro Matsumoto
@@ -591,8 +591,7 @@ rb_big_eq(x, y)
       case T_BIGNUM:
 	break;
       case T_FLOAT:
-	y = dbl2big(RFLOAT(y)->value);
-	break;
+	return (rb_big2dbl(x) == RFLOAT(y)->value)?Qtrue:Qfalse;
       default:
 	return Qfalse;
     }

In This Thread