Should raise FloatDomainError

This commit is contained in:
ksss
2017-03-28 22:50:10 +09:00
parent 1f6bf0e14f
commit db3573e0bf
3 changed files with 18 additions and 12 deletions
+3 -12
View File
@@ -211,16 +211,7 @@ mrb_time_wrap(mrb_state *mrb, struct RClass *tc, struct mrb_time *tm)
return mrb_obj_value(Data_Wrap_Struct(mrb, tc, &mrb_time_type, tm));
}
static void
check_num_exact(mrb_state *mrb, double num)
{
if (isinf(num)) {
mrb_raise(mrb, E_FLOATDOMAIN_ERROR, num < 0 ? "-Infinity" : "Infinity");
}
if (isnan(num)) {
mrb_raise(mrb, E_FLOATDOMAIN_ERROR, "NaN");
}
}
void mrb_check_num_exact(mrb_state *mrb, mrb_float num);
/* Allocates a mrb_time object and initializes it. */
static struct mrb_time*
@@ -229,8 +220,8 @@ time_alloc(mrb_state *mrb, double sec, double usec, enum mrb_timezone timezone)
struct mrb_time *tm;
time_t tsec = 0;
check_num_exact(mrb, sec);
check_num_exact(mrb, usec);
mrb_check_num_exact(mrb, (mrb_float)sec);
mrb_check_num_exact(mrb, (mrb_float)usec);
if (sizeof(time_t) == 4 && (sec > (double)INT32_MAX || (double)INT32_MIN > sec)) {
goto out_of_range;