Skip to content

Commit

Permalink
* sprintf.c (rb_f_sprintf): preceding ".." for negative
Browse files Browse the repository at this point in the history
  hexadecimal numbers should not appear if prec (e.g. %.4) is
  specified.

* pack.c (NUM2I32): support platforms which does not have 32bit
  integers (e.g. Cray).


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3081 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
matz committed Nov 22, 2002
1 parent 0b2c50f commit 7f62113
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
Fri Nov 22 22:55:01 2002 Yukihiro Matsumoto <[email protected]>

* sprintf.c (rb_f_sprintf): preceding ".." for negative
hexadecimal numbers should not appear if prec (e.g. %.4) is
specified.

* pack.c (NUM2I32): support platforms which does not have 32bit
integers (e.g. Cray).

Fri Nov 22 19:20:36 2002 Akinori MUSHA <[email protected]>

* instruby.rb: Install batch files on Windows. [Submitted by usa]
Expand Down
41 changes: 38 additions & 3 deletions pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,46 @@ typedef long I32;
typedef unsigned long U32;
#define NUM2I32(x) NUM2LONG(x)
#define NUM2U32(x) NUM2ULONG(x)
#elif SIZEOF_INT == SIZE32
#else
typedef int I32;
typedef unsigned int U32;
#define NUM2I32(x) NUM2INT(x)
#define NUM2U32(x) NUM2UINT(x)
# if SIZEOF_INT == SIZE32
# define NUM2I32(x) NUM2INT(x)
# define NUM2U32(x) NUM2UINT(x)
# else

#define I32_MAX 2147483647
#define I32_MIN (-I32_MAX-1)

static I32
num2i32(x)
VALUE x;
{
long num = NUM2LONG(x);

if (num < I32_MIN || I32_MAX < num) {
rb_raise(rb_eRangeError, "integer %ld too big to convert to `I32'", num);
}
return (I32)num;
}

#define U32_MAX 4294967295

static U32
num2u32(x)
VALUE x;
{
unsigned long num = NUM2ULONG(x);

if (U32_MAX < num) {
rb_raise(rb_eRangeError, "integer %ld too big to convert to `U32'", num);
}
return (U32)num;
}

# define NUM2I32(x) num2i32(x)
# define NUM2U32(x) num2u32(x)
# endif
#endif

#ifdef HAVE_LONG_LONG
Expand Down
14 changes: 8 additions & 6 deletions sprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ rb_f_sprintf(argc, argv)
if (base == 10) {
rb_warning("negative number for %%u specifier");
}
else {
else if (!(flags&FPREC)) {
strcpy(s, "..");
s += 2;
}
Expand Down Expand Up @@ -463,8 +463,10 @@ rb_f_sprintf(argc, argv)
remove_sign_bits(++s, base);
val = rb_str_new(0, 3+strlen(s));
t = RSTRING(val)->ptr;
strcpy(t, "..");
t += 2;
if (!(flags&FPREC)) {
strcpy(t, "..");
t += 2;
}
switch (base) {
case 16:
if (s[0] != 'f') strcpy(t++, "f"); break;
Expand Down Expand Up @@ -492,7 +494,7 @@ rb_f_sprintf(argc, argv)
}
if (prec < len) prec = len;
width -= prec;
if (!(flags&(FZERO|FMINUS)) && s[0] != '.') {
if (!(flags&(FZERO|FMINUS)) && v >= 0) {
CHECK(width);
while (width-->0) {
buf[blen++] = ' ';
Expand All @@ -507,7 +509,7 @@ rb_f_sprintf(argc, argv)
if (!(flags & FMINUS)) {
char c = ' ';

if (s[0] == '.') {
if (v < 0) {
c = '.';
if ((flags & FPREC) && prec > len) {
pos = blen;
Expand All @@ -524,7 +526,7 @@ rb_f_sprintf(argc, argv)
}
CHECK(prec - len);
while (len < prec--) {
buf[blen++] = s[0]=='.'?'.':'0';
buf[blen++] = v < 0 ? '.' : '0';
}
PUSH(s, len);
CHECK(width);
Expand Down

0 comments on commit 7f62113

Please sign in to comment.