Commit 33bb4578 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #1678 from iij/float-nan-p

add Float#nan?
parents 857e3cfa 7bf63c28
......@@ -612,6 +612,12 @@ flo_truncate(mrb_state *mrb, mrb_value num)
return mrb_fixnum_value((mrb_int)f);
}
static mrb_value
flo_nan_p(mrb_state *mrb, mrb_value num)
{
return mrb_bool_value(isnan(mrb_float(num)));
}
/*
* Document-class: Integer
*
......@@ -1331,4 +1337,5 @@ mrb_init_numeric(mrb_state *mrb)
mrb_define_method(mrb, fl, "to_s", flo_to_s, MRB_ARGS_NONE()); /* 15.2.9.3.16(x) */
mrb_define_method(mrb, fl, "inspect", flo_to_s, MRB_ARGS_NONE());
mrb_define_method(mrb, fl, "nan?", flo_nan_p, MRB_ARGS_NONE());
}
......@@ -143,3 +143,10 @@ assert('Float#truncate', '15.2.9.3.15') do
assert_equal( 3, 3.123456789.truncate)
assert_equal(-3, -3.1.truncate)
end
assert('Float#nan?') do
assert_true (0.0/0.0).nan?
assert_false 0.0.nan?
assert_false (1.0/0.0).nan?
assert_false (-1.0/0.0).nan?
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment