diff options
| author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-05-16 04:17:45 +0000 |
|---|---|---|
| committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-05-16 04:17:45 +0000 |
| commit | c3da8872ce8ae7af117021754380907086573e82 (patch) | |
| tree | 2371c51ea4f8d5acadf6971f044b6012c465d0db /math.c | |
| parent | abc1fbf6b22454366d957f427ef1e2ea32eda7e8 (diff) | |
| download | ruby-c3da8872ce8ae7af117021754380907086573e82.tar.gz ruby-c3da8872ce8ae7af117021754380907086573e82.tar.xz ruby-c3da8872ce8ae7af117021754380907086573e82.zip | |
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@16429 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'math.c')
| -rw-r--r-- | math.c | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -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);\ |
