diff options
author | (no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-04-14 14:35:50 +0000 |
---|---|---|
committer | (no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-04-14 14:35:50 +0000 |
commit | ed131ebad88c2948d7b40f93ff6ce39f1eb8a2f7 (patch) | |
tree | 7bbf62c5e0d0bb8ff971637cf432c6f16824f8f6 /bignum.c | |
parent | be1fea072cd0d22788ef8a931c0c6b64a2503b5d (diff) |
This commit was manufactured by cvs2svn to create tag 'v1_4_4'.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_4_4@668 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r-- | bignum.c | 27 |
1 files changed, 12 insertions, 15 deletions
@@ -16,11 +16,11 @@ VALUE rb_cBignum; typedef unsigned short USHORT; #define BDIGITS(x) RBIGNUM(x)->digits -#define BITSPERDIG (sizeof(short)*CHAR_BIT) +#define BITSPERDIG (sizeof(USHORT)*CHAR_BIT) #define BIGRAD (1L << BITSPERDIG) -#define DIGSPERINT ((unsigned int)(sizeof(long)/sizeof(short))) +#define DIGSPERLONG ((unsigned int)(sizeof(long)/sizeof(USHORT))) #define BIGUP(x) ((unsigned long)(x) << BITSPERDIG) -#define BIGDN(x) (((x)<0) ? ~((~(x))>>BITSPERDIG) : (x)>>BITSPERDIG) +#define BIGDN(x) RSHIFT(x,BITSPERDIG) #define BIGLO(x) ((USHORT)((x) & (BIGRAD-1))) static VALUE @@ -33,7 +33,7 @@ bignew_1(klass, len, sign) OBJSETUP(big, klass, T_BIGNUM); big->sign = sign; big->len = len; - BDIGITS(big) = ALLOC_N(USHORT, len); + big->digits = ALLOC_N(USHORT, len); return (VALUE)big; } @@ -116,14 +116,14 @@ rb_uint2big(n) VALUE big; i = 0; - big = bignew(DIGSPERINT, 1); + big = bignew(DIGSPERLONG, 1); digits = BDIGITS(big); - while (i < DIGSPERINT) { + while (i < DIGSPERLONG) { digits[i++] = BIGLO(n); n = BIGDN(n); } - i = DIGSPERINT; + i = DIGSPERLONG; while (i-- && !digits[i]) ; RBIGNUM(big)->len = i+1; return big; @@ -1255,20 +1255,17 @@ rb_big_abs(x) */ VALUE -rb_big_rand(max) +rb_big_rand(max, rand) VALUE max; + double rand; { - struct RBignum *v; + VALUE v; long len; len = RBIGNUM(max)->len; - v = RBIGNUM(bignew(len,1)); + v = bignew(len,1); while (len--) { -#ifdef HAVE_RANDOM - BDIGITS(v)[len] = random(); -#else - BDIGITS(v)[len] = rand(); -#endif + BDIGITS(v)[len] = ((USHORT)~0) * rand; } return rb_big_mod((VALUE)v, max); |