From f970ffedaebf447da3617c1825b5365ce45a40fd Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 16 May 2008 04:17:45 +0000 Subject: [PATCH] * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16429 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 +++++++++++ complex.c | 4 ++-- math.c | 15 ++++++++++++++- object.c | 8 +------- test/ruby/test_float.rb | 2 +- version.h | 6 +++--- 6 files changed, 32 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 108c0aad0c..af7efa6fe3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Fri May 16 12:48:33 2008 Yukihiro Matsumoto + + * 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 * test/ruby/test_string.rb: add tests to achieve over 90% test diff --git a/complex.c b/complex.c index ab41520b48..7b387b94db 100644 --- a/complex.c +++ b/complex.c @@ -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); diff --git a/math.c b/math.c index fe25c4c0a0..37d019bc70 100644 --- a/math.c +++ b/math.c @@ -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);\ diff --git a/object.c b/object.c index e863edb8da..c1c60714e2 100644 --- a/object.c +++ b/object.c @@ -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 diff --git a/version.h b/version.h index 473b606dc9..c7bdbeb663 100644 --- a/version.h +++ b/version.h @@ -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[];