mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
b8118e9645
commit
f970ffedae
6 changed files with 32 additions and 14 deletions
11
ChangeLog
11
ChangeLog
|
@ -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>
|
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
|
* 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)) {
|
if (k_float_p(dat->image) || !f_zero_p(dat->image)) {
|
||||||
VALUE s = f_to_s(self);
|
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));
|
StringValuePtr(s));
|
||||||
}
|
}
|
||||||
return f_to_f(dat->real);
|
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)) {
|
if (k_float_p(dat->image) || !f_zero_p(dat->image)) {
|
||||||
VALUE s = f_to_s(self);
|
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));
|
StringValuePtr(s));
|
||||||
}
|
}
|
||||||
return f_to_r(dat->real);
|
return f_to_r(dat->real);
|
||||||
|
|
15
math.c
15
math.c
|
@ -15,7 +15,20 @@
|
||||||
|
|
||||||
VALUE rb_mMath;
|
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 {\
|
#define Need_Float2(x,y) do {\
|
||||||
Need_Float(x);\
|
Need_Float(x);\
|
||||||
Need_Float(y);\
|
Need_Float(y);\
|
||||||
|
|
8
object.c
8
object.c
|
@ -2148,13 +2148,7 @@ rb_Float(VALUE val)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
return rb_convert_type(val, T_FLOAT, "Float", "to_f");
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -415,7 +415,7 @@ class TestFloat < Test::Unit::TestCase
|
||||||
assert_raise(TypeError) { Float(nil) }
|
assert_raise(TypeError) { Float(nil) }
|
||||||
o = Object.new
|
o = Object.new
|
||||||
def o.to_f; inf = 1.0/0.0; inf/inf; end
|
def o.to_f; inf = 1.0/0.0; inf/inf; end
|
||||||
assert_raise(ArgumentError) { Float(o) }
|
assert(Float(o).nan?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_num2dbl
|
def test_num2dbl
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#define RUBY_VERSION "1.9.0"
|
#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_VERSION_CODE 190
|
||||||
#define RUBY_RELEASE_CODE 20080515
|
#define RUBY_RELEASE_CODE 20080516
|
||||||
#define RUBY_PATCHLEVEL 0
|
#define RUBY_PATCHLEVEL 0
|
||||||
|
|
||||||
#define RUBY_VERSION_MAJOR 1
|
#define RUBY_VERSION_MAJOR 1
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
#define RUBY_VERSION_TEENY 0
|
#define RUBY_VERSION_TEENY 0
|
||||||
#define RUBY_RELEASE_YEAR 2008
|
#define RUBY_RELEASE_YEAR 2008
|
||||||
#define RUBY_RELEASE_MONTH 5
|
#define RUBY_RELEASE_MONTH 5
|
||||||
#define RUBY_RELEASE_DAY 15
|
#define RUBY_RELEASE_DAY 16
|
||||||
|
|
||||||
#ifdef RUBY_EXTERN
|
#ifdef RUBY_EXTERN
|
||||||
RUBY_EXTERN const char ruby_version[];
|
RUBY_EXTERN const char ruby_version[];
|
||||||
|
|
Loading…
Add table
Reference in a new issue