* ext/bigdecimal: Workaround fix for bigdecimal test failures caused

by [ruby-dev:47413] [Feature #8509]

* ext/bigdecimal/bigdecimal.h (BDIGIT): Make it independent from the
  definition for bignum.c.
  (SIZEOF_BDIGITS): Ditto.
  (BDIGIT_DBL): Ditto.
  (BDIGIT_DBL_SIGNED): Ditto.
  (PRI_BDIGIT_PREFIX): Undefine the definition.
  (PRI_BDIGIT_DBL_PREFIX): Ditto.

* ext/bigdecimal/bigdecimal.c (RBIGNUM_ZERO_P): Use rb_bigzero_p.
  (bigzero_p): Removed.
  (is_even): Use rb_big_pack.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41502 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2013-06-20 15:42:23 +00:00
parent a0d42f0354
commit a461f2f8bb
3 changed files with 42 additions and 16 deletions

View File

@ -1,3 +1,20 @@
Fri Jun 21 00:37:31 2013 Tanaka Akira <akr@fsij.org>
* ext/bigdecimal: Workaround fix for bigdecimal test failures caused
by [ruby-dev:47413] [Feature #8509]
* ext/bigdecimal/bigdecimal.h (BDIGIT): Make it independent from the
definition for bignum.c.
(SIZEOF_BDIGITS): Ditto.
(BDIGIT_DBL): Ditto.
(BDIGIT_DBL_SIGNED): Ditto.
(PRI_BDIGIT_PREFIX): Undefine the definition.
(PRI_BDIGIT_DBL_PREFIX): Ditto.
* ext/bigdecimal/bigdecimal.c (RBIGNUM_ZERO_P): Use rb_bigzero_p.
(bigzero_p): Removed.
(is_even): Use rb_big_pack.
Thu Jun 20 22:52:42 2013 Tanaka Akira <akr@fsij.org> Thu Jun 20 22:52:42 2013 Tanaka Akira <akr@fsij.org>
* bignum.c (bigmul1_toom3): Don't call bignorm twice. * bignum.c (bigmul1_toom3): Don't call bignorm twice.

View File

@ -86,23 +86,9 @@ static ID id_eq;
#endif #endif
#ifndef RBIGNUM_ZERO_P #ifndef RBIGNUM_ZERO_P
# define RBIGNUM_ZERO_P(x) (RBIGNUM_LEN(x) == 0 || \ # define RBIGNUM_ZERO_P(x) rb_bigzero_p(x)
(RBIGNUM_DIGITS(x)[0] == 0 && \
(RBIGNUM_LEN(x) == 1 || bigzero_p(x))))
#endif #endif
static inline int
bigzero_p(VALUE x)
{
long i;
BDIGIT *ds = RBIGNUM_DIGITS(x);
for (i = RBIGNUM_LEN(x) - 1; 0 <= i; i--) {
if (ds[i]) return 0;
}
return 1;
}
#ifndef RRATIONAL_ZERO_P #ifndef RRATIONAL_ZERO_P
# define RRATIONAL_ZERO_P(x) (FIXNUM_P(RRATIONAL(x)->num) && \ # define RRATIONAL_ZERO_P(x) (FIXNUM_P(RRATIONAL(x)->num) && \
FIX2LONG(RRATIONAL(x)->num) == 0) FIX2LONG(RRATIONAL(x)->num) == 0)
@ -2130,7 +2116,11 @@ is_even(VALUE x)
return (FIX2LONG(x) % 2) == 0; return (FIX2LONG(x) % 2) == 0;
case T_BIGNUM: case T_BIGNUM:
return (RBIGNUM_DIGITS(x)[0] % 2) == 0; {
unsigned long l;
rb_big_pack(x, &l, 1);
return l % 2 == 0;
}
default: default:
break; break;

View File

@ -19,6 +19,25 @@
#include "ruby/ruby.h" #include "ruby/ruby.h"
#include <float.h> #include <float.h>
#undef BDIGIT
#undef SIZEOF_BDIGITS
#undef BDIGIT_DBL
#undef BDIGIT_DBL_SIGNED
#undef PRI_BDIGIT_PREFIX
#undef PRI_BDIGIT_DBL_PREFIX
#ifdef HAVE_INT64_T
# define BDIGIT uint32_t
# define BDIGIT_DBL uint64_t
# define BDIGIT_DBL_SIGNED int64_t
# define SIZEOF_BDIGITS 4
#else
# define BDIGIT uint16_t
# define BDIGIT_DBL uint32_t
# define BDIGIT_DBL_SIGNED int32_t
# define SIZEOF_BDIGITS 2
#endif
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" { extern "C" {
#if 0 #if 0