diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-27 17:42:12 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-27 17:42:12 +0000 |
commit | 6eea7a7c718acdeb2c800d52c5e738ef22d4c467 (patch) | |
tree | 5f5e5eb95e169f5831e7fe2cdec9ed9aa5334cd7 /sprintf.c | |
parent | 0cdd3bced5e42557ed4ee3c7f3cd35f7f56cbcf0 (diff) |
* bignum.c (big2str_find_n1): removed extraneous element.
[ruby-dev:32351], [ruby-dev:32365]
* bignum.c (big2str_find_n1): returns necessary digits now.
* sprintf.c (remove_sign_bits): extends sign bit first.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14034 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r-- | sprintf.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -19,6 +19,8 @@ #include <stdarg.h> #define BIT_DIGITS(N) (((N)*146)/485 + 1) /* log2(10) =~ 146/485 */ +#define BITSPERDIG (SIZEOF_BDIGITS*CHAR_BIT) +#define EXTENDSIGN(n, l) (((~0 << (n)) >> (((n)*(l)) % BITSPERDIG)) & ~(~0 << (n))) static void fmt_setup(char*,int,int,int,int); @@ -35,7 +37,7 @@ remove_sign_bits(char *str, int base) } } else if (base == 8) { - if (*t == '3') t++; + *t |= EXTENDSIGN(3, strlen(t)); while (*t == '7') { t++; } @@ -662,7 +664,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) val = rb_big_clone(val); rb_big_2comp(val); } - tmp1 = tmp = rb_big2str0(val, base, Qtrue); + tmp1 = tmp = rb_big2str0(val, base, RBIGNUM_SIGN(val)); s = RSTRING_PTR(tmp); if (*s == '-') { if (base == 10) { @@ -695,7 +697,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) if (*p == 'X') { char *pp = s; int c; - while (c = (int)*pp) { + while ((c = (int)(unsigned char)*pp) != 0) { *pp = rb_enc_toupper(c, enc); pp++; } |