[前][次][番号順一覧][スレッド一覧]

ruby-changes:7909

From: yugui <ko1@a...>
Date: Fri, 19 Sep 2008 22:11:25 +0900 (JST)
Subject: [ruby-changes:7909] Ruby:r19430 (trunk): * prec.c: removed. Precision will be redesigned and be back again.

yugui	2008-09-19 22:10:54 +0900 (Fri, 19 Sep 2008)

  New Revision: 19430

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19430

  Log:
    * prec.c: removed. Precision will be redesigned and be back again.
      c.f. [ruby-dev:36352].
    
    * common.mk (COMMON_OBJS): removed prec.o.
    
    * inits.c (rb_call_inits): removed Init_Precision.
    
    * numeric.c (Init_Numeric): removed inclusion of Precision.
      removed #induced_from from each class.
    
    * rational.c: ditto.
    
    * ext/bigdecimal/bigdecimal.c: ditto.
    
    * lib/rdoc/knwon_classes.rb: removed the entry for Precision.
    
    * test/ruby/test_prec.rb: removed.
    
    * test/ruby/test_integer.rb: removed tests for Precision.
    
    * test/ruby/test_fixnum.rb: ditto.
    
    * test/ruby/test_float.rb: ditto.
    
    * test/ruby/test_rational.rb: ditto.
    
    * test/ruby/test_complex.rb: ditto.
    
    * test/bigdecimal/test_bigdecimal.rb: ditto.

  Removed files:
    trunk/prec.c
    trunk/test/ruby/test_prec.rb
  Modified files:
    trunk/ChangeLog
    trunk/common.mk
    trunk/ext/bigdecimal/bigdecimal.c
    trunk/inits.c
    trunk/lib/rdoc/known_classes.rb
    trunk/numeric.c
    trunk/rational.c
    trunk/test/bigdecimal/test_bigdecimal.rb
    trunk/test/ruby/test_complex.rb
    trunk/test/ruby/test_fixnum.rb
    trunk/test/ruby/test_float.rb
    trunk/test/ruby/test_integer.rb
    trunk/test/ruby/test_rational.rb

Index: prec.c
===================================================================
--- prec.c	(revision 19429)
+++ prec.c	(revision 19430)
@@ -1,138 +0,0 @@
-/**********************************************************************
-
-  prec.c -
-
-  $Author$
-  created at: Tue Jan 26 02:40:41 2000
-
-  Copyright (C) 1993-2007 Yukihiro Matsumoto
-
-**********************************************************************/
-
-#include "ruby/ruby.h"
-
-VALUE rb_mPrecision;
-
-static ID prc_pr, prc_if;
-
-
-/*
- *  call-seq:
- *   num.prec(klass)   => a_class
- *
- *  Converts _self_ into an instance of _klass_. By default,
- *  +prec+ invokes 
- *
- *     klass.induced_from(num)
- *
- *  and returns its value. So, if <code>klass.induced_from</code>
- *  doesn't return an instance of _klass_, it will be necessary
- *  to reimplement +prec+.
- */
-
-static VALUE
-prec_prec(VALUE x, VALUE klass)
-{
-    return rb_funcall(klass, prc_if, 1, x);
-}
-
-/*
- *  call-seq:
- *    num.prec_i  =>  Integer
- *
- *  Returns an +Integer+ converted from _num_. It is equivalent 
- *  to <code>prec(Integer)</code>.
- */
-
-static VALUE
-prec_prec_i(VALUE x)
-{
-    VALUE klass = rb_cInteger;
-
-    return rb_funcall(x, prc_pr, 1, klass);
-}
-
-/*
- *  call-seq:
- *    num.prec_f  =>  Float
- *
- *  Returns a +Float+ converted from _num_. It is equivalent 
- *  to <code>prec(Float)</code>.
- */
-
-static VALUE
-prec_prec_f(VALUE x)
-{
-    VALUE klass = rb_cFloat;
-
-    return rb_funcall(x, prc_pr, 1, klass);
-}
-
-/*
- * call-seq:
- *   Mod.induced_from(number)  =>  a_mod
- * 
- * Creates an instance of mod from. This method is overridden
- * by concrete +Numeric+ classes, so that (for example)
- *
- *   Fixnum.induced_from(9.9)   #=>  9
- *
- * Note that a use of +prec+ in a redefinition may cause
- * an infinite loop.
- */
-
-static VALUE
-prec_induced_from(VALUE module, VALUE x)
-{
-    rb_raise(rb_eTypeError, "undefined conversion from %s into %s",
-            rb_obj_classname(x), rb_class2name(module));
-    return Qnil;		/* not reached */
-}
-
-/*
- * call_seq:
- *   included
- *
- * When the +Precision+ module is mixed-in to a class, this +included+
- * method is used to add our default +induced_from+ implementation
- * to the host class.
- */
-
-static VALUE
-prec_included(VALUE module, VALUE include)
-{
-    switch (TYPE(include)) {
-      case T_CLASS:
-      case T_MODULE:
-       break;
-      default:
-       Check_Type(include, T_CLASS);
-       break;
-    }
-    rb_define_singleton_method(include, "induced_from", prec_induced_from, 1);
-    return module;
-}
-
-/*
- * Precision is a mixin for concrete numeric classes with
- * precision.  Here, `precision' means the fineness of approximation
- * of a real number, so, this module should not be included into
- * anything which is not a subset of Real (so it should not be
- * included in classes such as +Complex+ or +Matrix+).
-*/
-
-void
-Init_Precision(void)
-{
-#undef rb_intern
-#define rb_intern(str) rb_intern_const(str)
-
-    rb_mPrecision = rb_define_module("Precision");
-    rb_define_singleton_method(rb_mPrecision, "included", prec_included, 1);
-    rb_define_method(rb_mPrecision, "prec", prec_prec, 1);
-    rb_define_method(rb_mPrecision, "prec_i", prec_prec_i, 0);
-    rb_define_method(rb_mPrecision, "prec_f", prec_prec_f, 0);
-
-    prc_pr = rb_intern("prec");
-    prc_if = rb_intern("induced_from");
-}
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19429)
+++ ChangeLog	(revision 19430)
@@ -1,3 +1,35 @@
+Fri Sep 19 20:48:06 2008  Yuki Sonoda  <yugui@y...>
+
+	* prec.c: removed. Precision will be redesigned and be back again.
+	  c.f. [ruby-dev:36352].
+
+	* common.mk (COMMON_OBJS): removed prec.o.
+
+	* inits.c (rb_call_inits): removed Init_Precision.
+
+	* numeric.c (Init_Numeric): removed inclusion of Precision.
+	  removed #induced_from from each class.
+
+	* rational.c: ditto.
+
+	* ext/bigdecimal/bigdecimal.c: ditto.
+
+	* lib/rdoc/knwon_classes.rb: removed the entry for Precision.
+
+	* test/ruby/test_prec.rb: removed.
+
+	* test/ruby/test_integer.rb: removed tests for Precision.
+
+	* test/ruby/test_fixnum.rb: ditto.
+
+	* test/ruby/test_float.rb: ditto.
+
+	* test/ruby/test_rational.rb: ditto.
+
+	* test/ruby/test_complex.rb: ditto.
+
+	* test/bigdecimal/test_bigdecimal.rb: ditto.
+
 Fri Sep 19 19:43:40 2008  Yuki Sonoda  <yugui@y...>
 
 	* common.mk : Reverts the changeset 18994.
Index: lib/rdoc/known_classes.rb
===================================================================
--- lib/rdoc/known_classes.rb	(revision 19429)
+++ lib/rdoc/known_classes.rb	(revision 19430)
@@ -62,7 +62,6 @@
     "rb_mGC"               => "GC",
     "rb_mKernel"           => "Kernel",
     "rb_mMath"             => "Math",
-    "rb_mPrecision"        => "Precision",
     "rb_mProcess"          => "Process"
   }
 
Index: common.mk
===================================================================
--- common.mk	(revision 19429)
+++ common.mk	(revision 19430)
@@ -49,7 +49,6 @@
 		pack.$(OBJEXT) \
 		parse.$(OBJEXT) \
 		process.$(OBJEXT) \
-		prec.$(OBJEXT) \
 		random.$(OBJEXT) \
 		range.$(OBJEXT) \
 		rational.$(OBJEXT) \
Index: ext/bigdecimal/bigdecimal.c
===================================================================
--- ext/bigdecimal/bigdecimal.c	(revision 19429)
+++ ext/bigdecimal/bigdecimal.c	(revision 19430)
@@ -579,13 +579,6 @@
     return rb_cstr2inum(psz,10);
 }
 
-static VALUE
-BigDecimal_induced_from(VALUE self, VALUE x)
-{
-    Real *p = GetVpValue(x,1);
-    return p->obj;
-}
-
 /* Returns a new Float object having approximately the same value as the
  * BigDecimal number. Normal accuracy limits and built-in errors of binary
  * Float arithmetic apply.
@@ -1807,7 +1800,6 @@
     rb_define_singleton_method(rb_cBigDecimal, "mode", BigDecimal_mode, -1);
     rb_define_singleton_method(rb_cBigDecimal, "limit", BigDecimal_limit, -1);
     rb_define_singleton_method(rb_cBigDecimal, "double_fig", BigDecimal_double_fig, 0);
-    rb_define_singleton_method(rb_cBigDecimal, "induced_from",BigDecimal_induced_from, 1);
     rb_define_singleton_method(rb_cBigDecimal, "_load", BigDecimal_load, 1);
     rb_define_singleton_method(rb_cBigDecimal, "ver", BigDecimal_version, 0);
 
Index: numeric.c
===================================================================
--- numeric.c	(revision 19429)
+++ numeric.c	(revision 19430)
@@ -1951,66 +1951,6 @@
 
 /*
  * call-seq:
- *   Fixnum.induced_from(obj)    =>  fixnum
- *
- * Convert <code>obj</code> to a Fixnum. Works with numeric parameters.
- * Also works with Symbols, but this is deprecated.
- */
-
-static VALUE
-rb_fix_induced_from(VALUE klass, VALUE x)
-{
-    return rb_num2fix(x);
-}
-
-/*
- * call-seq:
- *   Integer.induced_from(obj)    =>  fixnum, bignum
- *
- * Convert <code>obj</code> to an Integer.
- */
-
-static VALUE
-rb_int_induced_from(VALUE klass, VALUE x)
-{
-    switch (TYPE(x)) {
-      case T_FIXNUM:
-      case T_BIGNUM:
-	return x;
-      case T_FLOAT:
-      case T_RATIONAL:
-	return rb_funcall(x, id_to_i, 0);
-      default:
-	rb_raise(rb_eTypeError, "failed to convert %s into Integer",
-		 rb_obj_classname(x));
-    }
-}
-
-/*
- * call-seq:
- *   Float.induced_from(obj)    =>  float
- *
- * Convert <code>obj</code> to a float.
- */
-
-static VALUE
-rb_flo_induced_from(VALUE klass, VALUE x)
-{
-    switch (TYPE(x)) {
-      case T_FIXNUM:
-      case T_BIGNUM:
-      case T_RATIONAL:
-	return rb_funcall(x, rb_intern("to_f"), 0);
-      case T_FLOAT:
-	return x;
-      default:
-	rb_raise(rb_eTypeError, "failed to convert %s into Float",
-		 rb_obj_classname(x));
-    }
-}
-
-/*
- * call-seq:
  *   -fix   =>  integer
  *
  * Negates <code>fix</code> (which might return a Bignum).
@@ -3172,7 +3112,6 @@
     rb_define_method(rb_cInteger, "upto", int_upto, 1);
     rb_define_method(rb_cInteger, "downto", int_downto, 1);
     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, "pred", int_pred, 0);
@@ -3185,9 +3124,6 @@
     rb_define_method(rb_cInteger, "round", int_round, -1);
 
     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_define_method(rb_cInteger, "numerator", int_numerator, 0);
     rb_define_method(rb_cInteger, "denominator", int_denominator, 0);
@@ -3237,9 +3173,6 @@
     rb_undef_alloc_func(rb_cFloat);
     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_const(rb_cFloat, "ROUNDS", INT2FIX(FLT_ROUNDS));
     rb_define_const(rb_cFloat, "RADIX", INT2FIX(FLT_RADIX));
     rb_define_const(rb_cFloat, "MANT_DIG", INT2FIX(DBL_MANT_DIG));
Index: inits.c
===================================================================
--- inits.c	(revision 19429)
+++ inits.c	(revision 19430)
@@ -34,7 +34,6 @@
 void Init_Numeric(void);
 void Init_Object(void);
 void Init_pack(void);
-void Init_Precision(void);
 void Init_sym(void);
 void Init_process(void);
 void Init_RandomSeed(void);
@@ -66,7 +65,6 @@
     Init_Encoding();
     Init_Comparable();
     Init_Enumerable();
-    Init_Precision();
     Init_String();
     Init_Exception();
     Init_eval();
Index: test/bigdecimal/test_bigdecimal.rb
===================================================================
--- test/bigdecimal/test_bigdecimal.rb	(revision 19429)
+++ test/bigdecimal/test_bigdecimal.rb	(revision 19430)
@@ -245,13 +245,6 @@
     assert_operator(BigDecimal.new((2**100).to_s), :==, d)
   end
 
-  def test_induced_from
-    assert_instance_of(BigDecimal, BigDecimal.induced_from(1))
-    assert_raise(TypeError) do
-      BigDecimal.induced_from(Time.now)
-    end
-  end
-
   def test_precs
     a = BigDecimal.new("1").precs
     assert_instance_of(Array, a)
Index: test/ruby/test_prec.rb
===================================================================
--- test/ruby/test_prec.rb	(revision 19429)
+++ test/ruby/test_prec.rb	(revision 19430)
@@ -1,21 +0,0 @@
-require 'test/unit'
-
-class TestPrecision < Test::Unit::TestCase
-  def test_prec_i
-    assert_same(1, 1.0.prec(Integer))
-    assert_same(1, 1.0.prec_i)
-    assert_same(1, Integer.induced_from(1.0))
-  end
-
-  def test_prec_f
-    assert_equal(1.0, 1.prec(Float))
-    assert_equal(1.0, 1.prec_f)
-    assert_equal(1.0, Float.induced_from(1))
-  end
-
-  def test_induced_from
-    m = Module.new
-    m.instance_eval { include(Precision) }
-    assert_raise(TypeError) { m.induced_from(0) }
-  end
-end
Index: test/ruby/test_integer.rb
===================================================================
--- test/ruby/test_integer.rb	(revision 19429)
+++ test/ruby/test_integer.rb	(revision 19430)
@@ -122,12 +122,6 @@
     assert_raise(RangeError) { 0x100.chr }
   end
 
-  def test_induced_from
-    assert_equal(1, Integer.induced_from(1))
-    assert_equal(1, Integer.induced_from(1.0))
-    assert_raise(TypeError) { Integer.induced_from(nil) }
-  end
-
   def test_upto
     a = []
     1.upto(3) {|x| a << x }
Index: test/ruby/test_float.rb
===================================================================
--- test/ruby/test_float.rb	(revision 19429)
+++ test/ruby/test_float.rb	(revision 19430)
@@ -275,13 +275,6 @@
     assert_equal(11100.0, 11111.1.round(-2))
   end
 
-  def test_induced_from
-    assert_equal(1.0, Float.induced_from(1))
-    assert_equal(1.0, Float.induced_from(1.0))
-    assert_raise(TypeError) { Float.induced_from(nil) }
-  end
-
-
   VS = [
     18446744073709551617.0,
     18446744073709551616.0,
Index: test/ruby/test_fixnum.rb
===================================================================
--- test/ruby/test_fixnum.rb	(revision 19429)
+++ test/ruby/test_fixnum.rb	(revision 19430)
@@ -119,15 +119,6 @@
     assert_equal(0x4000000000000000, (-0x4000000000000000).abs)
   end
 
-  def test_induced_from
-    assert_equal(1, Fixnum.induced_from(1))
-    assert_raise(RangeError) do
-      Fixnum.induced_from(2**31-1)
-      Fixnum.induced_from(2**63-1)
-    end
-    assert_equal(1, Fixnum.induced_from((2**32).coerce(1).first))
-  end
-
   def test_to_s
     assert_equal("1010", 10.to_s(2))
     assert_equal("a", 10.to_s(36))
Index: test/ruby/test_complex.rb
===================================================================
--- test/ruby/test_complex.rb	(revision 19429)
+++ test/ruby/test_complex.rb	(revision 19430)
@@ -882,10 +882,6 @@
     assert_equal([1, 2], [c.real, c.image])
   end
 
-  def test_prec
-    assert_equal(nil, Complex < Precision)
-  end
-
   def test_supp
     assert_equal(true, 1.real?)
     assert_equal(true, 1.1.real?)
Index: test/ruby/test_rational.rb
===================================================================
--- test/ruby/test_rational.rb	(revision 19429)
+++ test/ruby/test_rational.rb	(revision 19430)
@@ -1028,16 +1028,6 @@
     end
   end
 
-  def test_prec
-    assert_equal(true, Rational < Precision)
-
-    c = Rational(3,2)
-
-    assert_eql(1, c.prec(Integer))
-    assert_eql(1.5, c.prec(Float))
-    assert_eql(c, c.prec(Rational))
-  end
-
   def test_gcdlcm
     assert_equal(7, 91.gcd(-49))
     assert_equal(5, 5.gcd(0))
Index: rational.c
===================================================================
--- rational.c	(revision 19429)
+++ rational.c	(revision 19430)
@@ -1470,12 +1470,6 @@
     }
 }
 
-static VALUE
-nurat_s_induced_from(VALUE klass, VALUE n)
-{
-    return f_to_r(n);
-}
-
 void
 Init_Rational(void)
 {
@@ -1592,10 +1586,6 @@
     rb_define_singleton_method(rb_cRational, "convert", nurat_s_convert, -1);
     rb_funcall(rb_cRational, rb_intern("private_class_method"), 1,
 	       ID2SYM(rb_intern("convert")));
-
-    rb_include_module(rb_cRational, rb_mPrecision);
-    rb_define_singleton_method(rb_cRational, "induced_from",
-			       nurat_s_induced_from, 1);
 }
 
 /*

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]