From ceb8031b6b795b189012c38057ebf82733f4aeaf Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 26 Jan 1999 10:08:18 +0000 Subject: 990126 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@378 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- numeric.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'numeric.c') diff --git a/numeric.c b/numeric.c index e8ea6075a9..6bc2e4478e 100644 --- a/numeric.c +++ b/numeric.c @@ -6,7 +6,7 @@ $Date$ created at: Fri Aug 13 18:33:09 JST 1993 - Copyright (C) 1993-1998 Yukihiro Matsumoto + Copyright (C) 1993-1999 Yukihiro Matsumoto ************************************************/ @@ -777,6 +777,27 @@ int_chr(num) return rb_str_new(&c, 1); } +static VALUE +rb_fix_induced_from(klass, x) + VALUE klass, x; +{ + return rb_funcall(x, rb_intern("to_i"), 0); +} + +static VALUE +rb_int_induced_from(klass, x) + VALUE klass, x; +{ + return rb_funcall(x, rb_intern("to_i"), 0); +} + +static VALUE +rb_flo_induced_from(klass, x) + VALUE klass, x; +{ + return rb_funcall(x, rb_intern("to_f"), 0); +} + static VALUE fix_uminus(num) VALUE num; @@ -1380,11 +1401,15 @@ Init_Numeric() rb_define_method(rb_cInteger, "downto", int_downto, 1); rb_define_method(rb_cInteger, "step", int_step, 2); rb_define_method(rb_cInteger, "times", int_dotimes, 0); + rb_include_module(rb_cInteger, rb_mPrecision); rb_define_method(rb_cInteger, "succ", int_succ, 0); rb_define_method(rb_cInteger, "next", int_succ, 0); rb_define_method(rb_cInteger, "chr", int_chr, 0); rb_cFixnum = rb_define_class("Fixnum", rb_cInteger); + rb_include_module(rb_cFixnum, rb_mPrecision); + rb_define_singleton_method(rb_cFixnum, "induced_from", rb_fix_induced_from, 1); + rb_define_singleton_method(rb_cInteger, "induced_from", rb_int_induced_from, 1); rb_undef_method(CLASS_OF(rb_cFixnum), "new"); @@ -1437,6 +1462,9 @@ Init_Numeric() rb_undef_method(CLASS_OF(rb_cFloat), "new"); + rb_define_singleton_method(rb_cFloat, "induced_from", rb_flo_induced_from, 1); + rb_include_module(rb_cFloat, rb_mPrecision); + rb_define_method(rb_cFloat, "to_s", flo_to_s, 0); rb_define_method(rb_cFloat, "coerce", flo_coerce, 1); rb_define_method(rb_cFloat, "-@", flo_uminus, 0); -- cgit v1.2.3