diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-23 16:05:15 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-23 16:05:15 +0000 |
commit | 6225d547d51cbeee9c10dc927b6b12a4a3e01199 (patch) | |
tree | 8c26748ccd1b820f1470dca316c093afb731f083 /bignum.c | |
parent | ad6d79e7cbff79fbf8b813a87aa9c4dc397472c8 (diff) | |
download | ruby-6225d547d51cbeee9c10dc927b6b12a4a3e01199.tar.gz |
* bignum.c (BIGUP): Use LSHIFTX and avoid cast to consider the type
of x is bigger than BDIGIT_DBL.
(big2ulong): Use unsigned long to store the result.
(big2ull): Use unsigned LONG_LONG to store the result.
(bigand_int): Use long for num to avoid data loss.
(bigor_int): Ditto.
(bigxor_int): Ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41588 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r-- | bignum.c | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -55,7 +55,7 @@ static VALUE big_three = Qnil; #if defined(HAVE_LONG_LONG) && SIZEOF_LONG_LONG >= SIZEOF_BDIGITS # define DIGSPERLL (SIZEOF_LONG_LONG/SIZEOF_BDIGITS) #endif -#define BIGUP(x) ((BDIGIT_DBL)(x) << BITSPERDIG) +#define BIGUP(x) LSHIFTX(((x) + (BDIGIT_DBL)0), BITSPERDIG) #define BIGDN(x) RSHIFT((x),BITSPERDIG) #define BIGLO(x) ((BDIGIT)((x) & BDIGMAX)) #define BDIGMAX ((BDIGIT)(BIGRAD-1)) @@ -2409,7 +2409,7 @@ static unsigned long big2ulong(VALUE x, const char *type, int check) { long len = RBIGNUM_LEN(x); - BDIGIT_DBL num; + unsigned long num; BDIGIT *ds; if (BIGSIZE(x) > sizeof(long)) { @@ -2423,7 +2423,7 @@ big2ulong(VALUE x, const char *type, int check) num = BIGUP(num); num += ds[len]; } - return (unsigned long)num; + return num; } VALUE @@ -2477,7 +2477,7 @@ static unsigned LONG_LONG big2ull(VALUE x, const char *type) { long len = RBIGNUM_LEN(x); - BDIGIT_DBL num; + unsigned LONG_LONG num; BDIGIT *ds; if (len > SIZEOF_LONG_LONG/SIZEOF_BDIGITS) @@ -4569,7 +4569,7 @@ bigand_int(VALUE x, long y) zds[0] = xds[0] & y; #else { - BDIGIT_DBL num = y; + long num = y; for (i=0; i<bdigit_roomof(SIZEOF_LONG); i++) { zds[i] = xds[i] & BIGLO(num); @@ -4665,7 +4665,7 @@ bigor_int(VALUE x, long y) zds[0] = xds[0] | y; #else { - BDIGIT_DBL num = y; + long num = y; for (i=0; i<bdigit_roomof(SIZEOF_LONG); i++) { zds[i] = xds[i] | BIGLO(num); @@ -4761,7 +4761,7 @@ bigxor_int(VALUE x, long y) zds[0] = xds[0] ^ y; #else { - BDIGIT_DBL num = y; + long num = y; for (i=0; i<bdigit_roomof(SIZEOF_LONG); i++) { zds[i] = xds[i] ^ BIGLO(num); |