diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-12-29 13:40:33 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-12-29 13:40:33 +0000 |
commit | ad004644893b2f867521c3f215753cf8c04ea887 (patch) | |
tree | 23ba13bfdfb9f68d7fdeefb9f774968ffa2b8e01 /object.c | |
parent | 6bbd76a73295564871ab06f8da167ce6de0af467 (diff) | |
download | ruby-ad004644893b2f867521c3f215753cf8c04ea887.tar.gz |
* pack.c (pack_pack): template f should not accept non float
values. [ruby-dev:37656]
* object.c (rb_to_float): new function to type check floats.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r-- | object.c | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -2267,6 +2267,21 @@ rb_f_float(VALUE obj, VALUE arg) return rb_Float(arg); } +VALUE +rb_to_float(VALUE val) +{ + VALUE v; + + if (TYPE(val) == T_FLOAT) return val; + v = convert_type(val, "Float", "to_f", Qtrue); + if (TYPE(v) != T_FLOAT) { + const char *cname = rb_obj_classname(val); + rb_raise(rb_eTypeError, "can't convert %s to Float (%s#to_f gives %s)", + cname, cname, rb_obj_classname(v)); + } + return v; +} + double rb_num2dbl(VALUE val) { |