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

ruby-changes:42767

From: akr <ko1@a...>
Date: Sat, 30 Apr 2016 17:51:49 +0900 (JST)
Subject: [ruby-changes:42767] akr:r54841 (trunk): Define Integer#<= instead of Bignum#<=.

akr	2016-04-30 18:48:25 +0900 (Sat, 30 Apr 2016)

  New Revision: 54841

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

  Log:
    Define Integer#<= instead of Bignum#<=.
    
    * numeric.c (int_le): Define Integer#<=.
    
    * bignum.c (rb_big_le): Don't define Bignum#<=.
      Renamed from big_le.
    
    * internal.h (rb_big_le): Declared.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
    trunk/internal.h
    trunk/numeric.c
Index: bignum.c
===================================================================
--- bignum.c	(revision 54840)
+++ bignum.c	(revision 54841)
@@ -5474,16 +5474,8 @@ big_lt(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5474
     return big_op(x, y, big_op_lt);
 }
 
-/*
- * call-seq:
- *   big <= real  ->  true or false
- *
- * Returns <code>true</code> if the value of <code>big</code> is
- * less than or equal to that of <code>real</code>.
- */
-
-static VALUE
-big_le(VALUE x, VALUE y)
+VALUE
+rb_big_le(VALUE x, VALUE y)
 {
     return big_op(x, y, big_op_le);
 }
@@ -6884,7 +6876,6 @@ Init_Bignum(void) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6876
     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, "<=", big_le, 1);
     rb_define_method(rb_cBignum, "===", rb_big_eq, 1);
 
 #ifdef USE_GMP
Index: numeric.c
===================================================================
--- numeric.c	(revision 54840)
+++ numeric.c	(revision 54841)
@@ -3906,11 +3906,12 @@ fix_lt(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3906
 }
 
 /*
+ * 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 or equal to that of
+ * Returns +true+ if the value of +int+ is less than or equal to that of
  * +real+.
  */
 
@@ -3933,6 +3934,18 @@ fix_le(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3934
     }
 }
 
+static VALUE
+int_le(VALUE x, VALUE y)
+{
+    if (FIXNUM_P(x)) {
+	return fix_le(x, y);
+    }
+    else if (RB_TYPE_P(x, T_BIGNUM)) {
+	return rb_big_le(x, y);
+    }
+    return Qnil;
+}
+
 /*
  * Document-method: Integer#~
  * call-seq:
@@ -4885,6 +4898,8 @@ Init_Numeric(void) https://github.com/ruby/ruby/blob/trunk/numeric.c#L4898
     rb_define_method(rb_cInteger, "abs", int_abs, 0);
     rb_define_method(rb_cInteger, "magnitude", int_abs, 0);
 
+    rb_define_method(rb_cInteger, "<=", int_le, 1);
+
     rb_define_method(rb_cFixnum, "==", fix_equal, 1);
     rb_define_method(rb_cFixnum, "===", fix_equal, 1);
     rb_define_method(rb_cFixnum, ">",  fix_gt, 1);
Index: internal.h
===================================================================
--- internal.h	(revision 54840)
+++ internal.h	(revision 54841)
@@ -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_le(VALUE x, VALUE y);
 
 /* class.c */
 VALUE rb_class_boot(VALUE);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54840)
+++ ChangeLog	(revision 54841)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Apr 30 18:44:05 2016  Tanaka Akira  <akr@f...>
+
+	* numeric.c (int_le): Define Integer#<=.
+
+	* bignum.c (rb_big_le): Don't define Bignum#<=.
+	  Renamed from big_le.
+
+	* internal.h (rb_big_le): Declared.
+
 Sat Apr 30 18:11:44 2016  Tanaka Akira  <akr@f...>
 
 	* bignum.c (Init_Bignum): Define Integer#GMP_VERSION.

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

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