* sprintf.c (rb_f_sprintf): [ruby-dev:27967]

* range.c (range_include): use discrete membership for non Numeric
  values, for example, String.

* numeric.c (num_scalar_p): new method. [ruby-dev:27936]

* lib/complex.rb (Complex#scalar?): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9654 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2005-12-07 08:41:59 +00:00
Родитель e122cca179
Коммит da32ce1a67
5 изменённых файлов: 57 добавлений и 16 удалений

Просмотреть файл

@ -1,3 +1,16 @@
Wed Dec 7 17:10:27 2005 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
* sprintf.c (rb_f_sprintf): [ruby-dev:27967]
Wed Dec 7 16:39:18 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* range.c (range_include): use discrete membership for non Numeric
values, for example, String.
* numeric.c (num_scalar_p): new method. [ruby-dev:27936]
* lib/complex.rb (Complex#scalar?): ditto.
Wed Dec 7 15:31:35 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* sprintf.c (rb_str_format): integer overflow check added.

Просмотреть файл

@ -103,6 +103,10 @@ class Complex < Numeric
undef step
def scalar?
false
end
def Complex.generic?(other) # :nodoc:
other.kind_of?(Integer) or
other.kind_of?(Float) or

Просмотреть файл

@ -348,6 +348,20 @@ num_remainder(VALUE x, VALUE y)
return z;
}
/*
* call-seq:
* num.scalar? -> true or false
*
* Returns <code>true</code> if <i>num</i> is an <code>Scalar</code>
* (i.e. non <code>Complex</code>).
*/
static VALUE
num_scalar_p(VALUE num)
{
return Qtrue;
}
/*
* call-seq:
* num.integer? -> true or false
@ -2806,6 +2820,7 @@ Init_Numeric(void)
rb_define_method(rb_cNumeric, "abs", num_abs, 0);
rb_define_method(rb_cNumeric, "to_int", num_to_int, 0);
rb_define_method(rb_cNumeric, "scalar?", num_scalar_p, 0);
rb_define_method(rb_cNumeric, "integer?", num_int_p, 0);
rb_define_method(rb_cNumeric, "zero?", num_zero_p, 0);
rb_define_method(rb_cNumeric, "nonzero?", num_nonzero_p, 0);

29
range.c
Просмотреть файл

@ -618,19 +618,28 @@ range_inspect(VALUE range)
static VALUE
range_include(VALUE range, VALUE val)
{
VALUE beg, end;
VALUE beg = rb_ivar_get(range, id_beg);
VALUE end = rb_ivar_get(range, id_end);
VALUE tmp;
int nv = FIXNUM_P(beg) || FIXNUM_P(end) ||
rb_obj_is_kind_of(beg, rb_cNumeric) ||
rb_obj_is_kind_of(end, rb_cNumeric);
beg = rb_ivar_get(range, id_beg);
end = rb_ivar_get(range, id_end);
if (r_le(beg, val)) {
if (EXCL(range)) {
if (r_lt(val, end)) return Qtrue;
}
else {
if (r_le(val, end)) return Qtrue;
if (nv) {
numeric_range:
if (r_le(beg, val)) {
if (EXCL(range)) {
if (r_lt(val, end)) return Qtrue;
}
else {
if (r_le(val, end)) return Qtrue;
}
}
}
return Qfalse;
if (!NIL_P(rb_check_to_integer(beg, "to_int")) ||
!NIL_P(rb_check_to_integer(end, "to_int")))
goto numeric_range;
return rb_call_super(1, &val);
}

Просмотреть файл

@ -116,11 +116,11 @@ sign_bits(int base, const char *p)
t = p++; \
n = 0; \
for (; p < end && ISDIGIT(*p); p++) { \
int times10 = n*10; \
if (times10 / 10 != n) {\
int next_n = 10 * n + (*p - '0'); \
if (next_n / 10 != n) {\
rb_raise(rb_eArgError, #val " too big"); \
} \
n = 10 * n + (*p - '0'); \
n = next_n; \
} \
if (p >= end) { \
rb_raise(rb_eArgError, "malformed format string - %%*[0-9]"); \
@ -320,11 +320,11 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
case '5': case '6': case '7': case '8': case '9':
n = 0;
for (; p < end && ISDIGIT(*p); p++) {
int times10 = n*10;
if (times10 / 10 != n) {
int next_n = 10 * n + (*p - '0');
if (next_n / 10 != n) {
rb_raise(rb_eArgError, "width too big");
}
n = 10 * n + (*p - '0');
n = next_n;
}
if (p >= end) {
rb_raise(rb_eArgError, "malformed format string - %%[0-9]");