diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/bigdecimal/bigdecimal.c | 22 | ||||
-rw-r--r-- | ext/bigdecimal/bigdecimal.h | 19 |
2 files changed, 25 insertions, 16 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 360a3e79d9..ba8777635f 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -86,23 +86,9 @@ static ID id_eq; #endif #ifndef RBIGNUM_ZERO_P -# define RBIGNUM_ZERO_P(x) (RBIGNUM_LEN(x) == 0 || \ - (RBIGNUM_DIGITS(x)[0] == 0 && \ - (RBIGNUM_LEN(x) == 1 || bigzero_p(x)))) +# define RBIGNUM_ZERO_P(x) rb_bigzero_p(x) #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 # define RRATIONAL_ZERO_P(x) (FIXNUM_P(RRATIONAL(x)->num) && \ FIX2LONG(RRATIONAL(x)->num) == 0) @@ -2130,7 +2116,11 @@ is_even(VALUE x) return (FIX2LONG(x) % 2) == 0; case T_BIGNUM: - return (RBIGNUM_DIGITS(x)[0] % 2) == 0; + { + unsigned long l; + rb_big_pack(x, &l, 1); + return l % 2 == 0; + } default: break; diff --git a/ext/bigdecimal/bigdecimal.h b/ext/bigdecimal/bigdecimal.h index ae32d5ffc5..a53ad47e81 100644 --- a/ext/bigdecimal/bigdecimal.h +++ b/ext/bigdecimal/bigdecimal.h @@ -19,6 +19,25 @@ #include "ruby/ruby.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) extern "C" { #if 0 |