* time.c (num_exact): fix for mathn. [ruby-dev:41599]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28389 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7d8d8c4f59
commit
bf8cec6db1
@ -1,3 +1,7 @@
|
|||||||
|
Tue Jun 22 23:10:10 2010 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* time.c (num_exact): fix for mathn. [ruby-dev:41599]
|
||||||
|
|
||||||
Tue Jun 22 22:00:06 2010 Tanaka Akira <akr@fsij.org>
|
Tue Jun 22 22:00:06 2010 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* ext/socket/lib/socket.rb: suppress warnings.
|
* ext/socket/lib/socket.rb: suppress warnings.
|
||||||
|
43
time.c
43
time.c
@ -656,36 +656,51 @@ wmod(wideval_t wx, wideval_t wy)
|
|||||||
static VALUE
|
static VALUE
|
||||||
num_exact(VALUE v)
|
num_exact(VALUE v)
|
||||||
{
|
{
|
||||||
switch (TYPE(v)) {
|
VALUE tmp;
|
||||||
|
int t;
|
||||||
|
|
||||||
|
t = TYPE(v);
|
||||||
|
switch (t) {
|
||||||
case T_FIXNUM:
|
case T_FIXNUM:
|
||||||
case T_BIGNUM:
|
case T_BIGNUM:
|
||||||
case T_RATIONAL:
|
return v;
|
||||||
break;
|
|
||||||
|
|
||||||
case T_FLOAT:
|
case T_RATIONAL:
|
||||||
v = rb_convert_type(v, T_RATIONAL, "Rational", "to_r");
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case T_STRING:
|
case T_STRING:
|
||||||
case T_NIL:
|
case T_NIL:
|
||||||
goto typeerror;
|
goto typeerror;
|
||||||
|
|
||||||
default: {
|
default:
|
||||||
VALUE tmp;
|
if ((tmp = rb_check_funcall(v, rb_intern("to_r"), 0, NULL)) != Qundef) {
|
||||||
if (!NIL_P(tmp = rb_check_convert_type(v, T_RATIONAL, "Rational", "to_r"))) {
|
|
||||||
if (rb_respond_to(v, rb_intern("to_str"))) goto typeerror;
|
if (rb_respond_to(v, rb_intern("to_str"))) goto typeerror;
|
||||||
v = tmp;
|
v = tmp;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if (!NIL_P(tmp = rb_check_to_integer(v, "to_int")))
|
if (!NIL_P(tmp = rb_check_to_integer(v, "to_int"))) {
|
||||||
v = tmp;
|
v = tmp;
|
||||||
else {
|
break;
|
||||||
|
}
|
||||||
|
goto typeerror;
|
||||||
|
}
|
||||||
|
|
||||||
|
t = TYPE(v);
|
||||||
|
switch (t) {
|
||||||
|
case T_FIXNUM:
|
||||||
|
case T_BIGNUM:
|
||||||
|
return v;
|
||||||
|
|
||||||
|
case T_RATIONAL:
|
||||||
|
if (RRATIONAL(v)->den == INT2FIX(1))
|
||||||
|
v = RRATIONAL(v)->num;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
typeerror:
|
typeerror:
|
||||||
rb_raise(rb_eTypeError, "can't convert %s into an exact number",
|
rb_raise(rb_eTypeError, "can't convert %s into an exact number",
|
||||||
NIL_P(v) ? "nil" : rb_obj_classname(v));
|
NIL_P(v) ? "nil" : rb_obj_classname(v));
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3140,7 +3155,7 @@ time_to_r(VALUE time)
|
|||||||
GetTimeval(time, tobj);
|
GetTimeval(time, tobj);
|
||||||
v = w2v(rb_time_unmagnify(tobj->timew));
|
v = w2v(rb_time_unmagnify(tobj->timew));
|
||||||
if (TYPE(v) != T_RATIONAL) {
|
if (TYPE(v) != T_RATIONAL) {
|
||||||
v = rb_convert_type(v, T_RATIONAL, "Rational", "to_r");
|
v = rb_Rational1(v);
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user