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

ruby-changes:42768

From: akr <ko1@a...>
Date: Sat, 30 Apr 2016 18:13:49 +0900 (JST)
Subject: [ruby-changes:42768] akr:r54842 (trunk): Define Integer#< instead of Bignum#<.

akr	2016-04-30 19:10:23 +0900 (Sat, 30 Apr 2016)

  New Revision: 54842

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54842

  Log:
    Define Integer#< instead of Bignum#<.
    
    * numeric.c (int_lt): Define Integer#<.
    
    * bignum.c (rb_big_lt): Don't define Bignum#<.
      Renamed from big_lt.
    
    * internal.h (rb_big_lt): Declared.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
    trunk/internal.h
    trunk/numeric.c
Index: internal.h
===================================================================
--- internal.h	(revision 54841)
+++ internal.h	(revision 54842)
@@ -787,6 +787,7 @@ VALUE rb_big_abs(VALUE x); https://github.com/ruby/ruby/blob/trunk/internal.h#L787
 VALUE rb_big_size_m(VALUE big);
 VALUE rb_big_bit_length(VALUE big);
 VALUE rb_big_remainder(VALUE x, VALUE y);
+VALUE rb_big_lt(VALUE x, VALUE y);
 VALUE rb_big_le(VALUE x, VALUE y);
 
 /* class.c */
Index: bignum.c
===================================================================
--- bignum.c	(revision 54841)
+++ bignum.c	(revision 54842)
@@ -5460,16 +5460,8 @@ big_ge(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5460
     return big_op(x, y, big_op_ge);
 }
 
-/*
- * call-seq:
- *   big < real  ->  true or false
- *
- * Returns <code>true</code> if the value of <code>big</code> is
- * less than that of <code>real</code>.
- */
-
-static VALUE
-big_lt(VALUE x, VALUE y)
+VALUE
+rb_big_lt(VALUE x, VALUE y)
 {
     return big_op(x, y, big_op_lt);
 }
@@ -6875,7 +6867,6 @@ Init_Bignum(void) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6867
     rb_define_method(rb_cBignum, "==", rb_big_eq, 1);
     rb_define_method(rb_cBignum, ">", big_gt, 1);
     rb_define_method(rb_cBignum, ">=", big_ge, 1);
-    rb_define_method(rb_cBignum, "<", big_lt, 1);
     rb_define_method(rb_cBignum, "===", rb_big_eq, 1);
 
 #ifdef USE_GMP
Index: numeric.c
===================================================================
--- numeric.c	(revision 54841)
+++ numeric.c	(revision 54842)
@@ -3880,11 +3880,12 @@ fix_ge(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3880
 }
 
 /*
+ * Document-method: Integer#<
  * Document-method: Fixnum#<
  * call-seq:
- *   fix < real  ->  true or false
+ *   int < real  ->  true or false
  *
- * Returns +true+ if the value of +fix+ is less than that of +real+.
+ * Returns +true+ if the value of +int+ is less than that of +real+.
  */
 
 static VALUE
@@ -3905,6 +3906,18 @@ fix_lt(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3906
     }
 }
 
+static VALUE
+int_lt(VALUE x, VALUE y)
+{
+    if (FIXNUM_P(x)) {
+	return fix_lt(x, y);
+    }
+    else if (RB_TYPE_P(x, T_BIGNUM)) {
+	return rb_big_lt(x, y);
+    }
+    return Qnil;
+}
+
 /*
  * Document-method: Integer#<=
  * Document-method: Fixnum#<=
@@ -4898,6 +4911,7 @@ Init_Numeric(void) https://github.com/ruby/ruby/blob/trunk/numeric.c#L4911
     rb_define_method(rb_cInteger, "abs", int_abs, 0);
     rb_define_method(rb_cInteger, "magnitude", int_abs, 0);
 
+    rb_define_method(rb_cInteger, "<", int_lt, 1);
     rb_define_method(rb_cInteger, "<=", int_le, 1);
 
     rb_define_method(rb_cFixnum, "==", fix_equal, 1);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54841)
+++ ChangeLog	(revision 54842)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Apr 30 19:09:23 2016  Tanaka Akira  <akr@f...>
+
+	* numeric.c (int_lt): Define Integer#<.
+
+	* bignum.c (rb_big_lt): Don't define Bignum#<.
+	  Renamed from big_lt.
+
+	* internal.h (rb_big_lt): Declared.
+
 Sat Apr 30 18:44:05 2016  Tanaka Akira  <akr@f...>
 
 	* numeric.c (int_le): Define Integer#<=.

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

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