diff options
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | complex.c | 4 | ||||
-rw-r--r-- | math.c | 15 | ||||
-rw-r--r-- | object.c | 8 | ||||
-rw-r--r-- | test/ruby/test_float.rb | 2 | ||||
-rw-r--r-- | version.h | 6 |
6 files changed, 32 insertions, 14 deletions
@@ -1,3 +1,14 @@ +Fri May 16 12:48:33 2008 Yukihiro Matsumoto <matz@ruby-lang.org> + + * math.c (to_flo): rb_Float() accepts even strings for input. + + * complex.c (nucomp_to_f): fix wrong message. + + * complex.c (nucomp_to_r): ditto. + + * object.c (rb_Float): do not check NaN for error. NaN is a part + of valid float values. + Thu May 15 23:36:09 2008 Yusuke Endoh <mame@tsg.ne.jp> * test/ruby/test_string.rb: add tests to achieve over 90% test @@ -1093,7 +1093,7 @@ nucomp_to_f(VALUE self) if (k_float_p(dat->image) || !f_zero_p(dat->image)) { VALUE s = f_to_s(self); - rb_raise(rb_eRangeError, "can't convert %s into Integer", + rb_raise(rb_eRangeError, "can't convert %s into Float", StringValuePtr(s)); } return f_to_f(dat->real); @@ -1106,7 +1106,7 @@ nucomp_to_r(VALUE self) if (k_float_p(dat->image) || !f_zero_p(dat->image)) { VALUE s = f_to_s(self); - rb_raise(rb_eRangeError, "can't convert %s into Integer", + rb_raise(rb_eRangeError, "can't convert %s into Rational", StringValuePtr(s)); } return f_to_r(dat->real); @@ -15,7 +15,20 @@ VALUE rb_mMath; -#define Need_Float(x) (x) = rb_Float(x) +static VALUE +to_flo(VALUE x) +{ + if (!rb_obj_is_kind_of(x, rb_cNumeric)) { + rb_raise(rb_eTypeError, "can't convert %s into Float", + NIL_P(x) ? "nil" : + x == Qtrue ? "true" : + x == Qfalse ? "false" : + rb_obj_classname(x)); + } + return rb_convert_type(x, T_FLOAT, "Float", "to_f"); +} + +#define Need_Float(x) (x) = to_flo(x) #define Need_Float2(x,y) do {\ Need_Float(x);\ Need_Float(y);\ @@ -2148,13 +2148,7 @@ rb_Float(VALUE val) break; default: - { - VALUE f = rb_convert_type(val, T_FLOAT, "Float", "to_f"); - if (isnan(RFLOAT_VALUE(f))) { - rb_raise(rb_eArgError, "invalid value for Float()"); - } - return f; - } + return rb_convert_type(val, T_FLOAT, "Float", "to_f"); } } diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb index ff4cf3fba1..c5bc95f5c7 100644 --- a/test/ruby/test_float.rb +++ b/test/ruby/test_float.rb @@ -415,7 +415,7 @@ class TestFloat < Test::Unit::TestCase assert_raise(TypeError) { Float(nil) } o = Object.new def o.to_f; inf = 1.0/0.0; inf/inf; end - assert_raise(ArgumentError) { Float(o) } + assert(Float(o).nan?) end def test_num2dbl @@ -1,7 +1,7 @@ #define RUBY_VERSION "1.9.0" -#define RUBY_RELEASE_DATE "2008-05-15" +#define RUBY_RELEASE_DATE "2008-05-16" #define RUBY_VERSION_CODE 190 -#define RUBY_RELEASE_CODE 20080515 +#define RUBY_RELEASE_CODE 20080516 #define RUBY_PATCHLEVEL 0 #define RUBY_VERSION_MAJOR 1 @@ -9,7 +9,7 @@ #define RUBY_VERSION_TEENY 0 #define RUBY_RELEASE_YEAR 2008 #define RUBY_RELEASE_MONTH 5 -#define RUBY_RELEASE_DAY 15 +#define RUBY_RELEASE_DAY 16 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[]; |