diff options
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | lib/complex.rb | 4 | ||||
-rw-r--r-- | numeric.c | 15 | ||||
-rw-r--r-- | range.c | 31 | ||||
-rw-r--r-- | sprintf.c | 12 |
5 files changed, 58 insertions, 17 deletions
@@ -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. diff --git a/lib/complex.rb b/lib/complex.rb index 110a28ee7e..8832f17f82 100644 --- a/lib/complex.rb +++ b/lib/complex.rb @@ -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 @@ -350,6 +350,20 @@ num_remainder(VALUE x, VALUE y) /* * 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 * * Returns <code>true</code> if <i>num</i> is an <code>Integer</code> @@ -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); @@ -618,19 +618,28 @@ range_inspect(VALUE range) static VALUE range_include(VALUE range, VALUE val) { - VALUE beg, end; - - 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; + 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); + + 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]"); |