ruby-changes:4936
From: ko1@a...
Date: Fri, 16 May 2008 13:18:03 +0900 (JST)
Subject: [ruby-changes:4936] matz - Ruby:r16429 (trunk): * math.c (to_flo): rb_Float() accepts even strings for input.
matz 2008-05-16 13:17:45 +0900 (Fri, 16 May 2008)
New Revision: 16429
Modified files:
trunk/ChangeLog
trunk/complex.c
trunk/math.c
trunk/object.c
trunk/test/ruby/test_float.rb
trunk/version.h
Log:
* 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.
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/version.h?r1=16429&r2=16428&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/math.c?r1=16429&r2=16428&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/complex.c?r1=16429&r2=16428&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16429&r2=16428&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_float.rb?r1=16429&r2=16428&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/object.c?r1=16429&r2=16428&diff_format=u
Index: complex.c
===================================================================
--- complex.c (revision 16428)
+++ complex.c (revision 16429)
@@ -1093,7 +1093,7 @@
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 @@
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);
Index: math.c
===================================================================
--- math.c (revision 16428)
+++ math.c (revision 16429)
@@ -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);\
Index: ChangeLog
===================================================================
--- ChangeLog (revision 16428)
+++ ChangeLog (revision 16429)
@@ -1,3 +1,14 @@
+Fri May 16 12:48:33 2008 Yukihiro Matsumoto <matz@r...>
+
+ * 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@t...>
* test/ruby/test_string.rb: add tests to achieve over 90% test
Index: object.c
===================================================================
--- object.c (revision 16428)
+++ object.c (revision 16429)
@@ -2148,13 +2148,7 @@
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");
}
}
Index: version.h
===================================================================
--- version.h (revision 16428)
+++ version.h (revision 16429)
@@ -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[];
Index: test/ruby/test_float.rb
===================================================================
--- test/ruby/test_float.rb (revision 16428)
+++ test/ruby/test_float.rb (revision 16429)
@@ -415,7 +415,7 @@
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
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/