[DOC] move rdoc comments.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54796 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2016-04-27 12:46:46 +00:00
parent d5a7299bca
commit 02107a91c8

288
numeric.c
View File

@ -3003,6 +3003,19 @@ rb_int_pred(VALUE num)
#define int_pred rb_int_pred #define int_pred rb_int_pred
/*
* Document-method: Integer#chr
* call-seq:
* int.chr([encoding]) -> string
*
* Returns a string containing the character represented by the +int+'s value
* according to +encoding+.
*
* 65.chr #=> "A"
* 230.chr #=> "\346"
* 255.chr(Encoding::UTF_8) #=> "\303\277"
*/
VALUE VALUE
rb_enc_uint_chr(unsigned int code, rb_encoding *enc) rb_enc_uint_chr(unsigned int code, rb_encoding *enc)
{ {
@ -3025,18 +3038,6 @@ rb_enc_uint_chr(unsigned int code, rb_encoding *enc)
return str; return str;
} }
/*
* call-seq:
* int.chr([encoding]) -> string
*
* Returns a string containing the character represented by the +int+'s value
* according to +encoding+.
*
* 65.chr #=> "A"
* 230.chr #=> "\346"
* 255.chr(Encoding::UTF_8) #=> "\303\277"
*/
static VALUE static VALUE
int_chr(int argc, VALUE *argv, VALUE num) int_chr(int argc, VALUE *argv, VALUE num)
{ {
@ -3145,6 +3146,24 @@ rb_int_uminus(VALUE num)
return rb_funcall(num, idUMinus, 0, 0); return rb_funcall(num, idUMinus, 0, 0);
} }
/*
* Document-method: Integer#to_s
* call-seq:
* int.to_s(base=10) -> string
*
* Returns a string containing the representation of +int+ radix +base+
* (between 2 and 36).
*
* 12345.to_s #=> "12345"
* 12345.to_s(2) #=> "11000000111001"
* 12345.to_s(8) #=> "30071"
* 12345.to_s(10) #=> "12345"
* 12345.to_s(16) #=> "3039"
* 12345.to_s(36) #=> "9ix"
* 78546939656932.to_s(36) #=> "rubyrules"
*
*/
VALUE VALUE
rb_fix2str(VALUE x, int base) rb_fix2str(VALUE x, int base)
{ {
@ -3176,22 +3195,6 @@ rb_fix2str(VALUE x, int base)
return rb_usascii_str_new(b, e - b); return rb_usascii_str_new(b, e - b);
} }
/*
* call-seq:
* int.to_s(base=10) -> string
*
* Returns a string containing the representation of +int+ radix +base+
* (between 2 and 36).
*
* 12345.to_s #=> "12345"
* 12345.to_s(2) #=> "11000000111001"
* 12345.to_s(8) #=> "30071"
* 12345.to_s(10) #=> "12345"
* 12345.to_s(16) #=> "3039"
* 12345.to_s(36) #=> "9ix"
* 78546939656932.to_s(36) #=> "rubyrules"
*
*/
static VALUE static VALUE
int_to_s(int argc, VALUE *argv, VALUE x) int_to_s(int argc, VALUE *argv, VALUE x)
{ {
@ -3543,6 +3546,19 @@ fix_divmod(VALUE x, VALUE y)
} }
} }
/*
* Document-method: Fixnum#**
* call-seq:
* fix ** numeric -> numeric_result
*
* Raises +fix+ to the power of +numeric+, which may be negative or
* fractional.
*
* 2 ** 3 #=> 8
* 2 ** -1 #=> (1/2)
* 2 ** 0.5 #=> 1.4142135623731
*/
static VALUE static VALUE
int_pow(long x, unsigned long y) int_pow(long x, unsigned long y)
{ {
@ -3584,18 +3600,6 @@ rb_int_positive_pow(long x, unsigned long y)
return int_pow(x, y); return int_pow(x, y);
} }
/*
* call-seq:
* fix ** numeric -> numeric_result
*
* Raises +fix+ to the power of +numeric+, which may be negative or
* fractional.
*
* 2 ** 3 #=> 8
* 2 ** -1 #=> (1/2)
* 2 ** 0.5 #=> 1.4142135623731
*/
static VALUE static VALUE
fix_pow(VALUE x, VALUE y) fix_pow(VALUE x, VALUE y)
{ {
@ -3678,6 +3682,19 @@ fix_equal(VALUE x, VALUE y)
} }
} }
/*
* Document-method: Integer#<=>
* call-seq:
* int <=> numeric -> -1, 0, +1 or nil
*
* Comparison---Returns +-1+, +0+, ++1+ or +nil+ depending on whether +fix+ is
* less than, equal to, or greater than +numeric+.
*
* This is the basis for the tests in the Comparable module.
*
* +nil+ is returned if the two values are incomparable.
*/
static VALUE static VALUE
fix_cmp(VALUE x, VALUE y) fix_cmp(VALUE x, VALUE y)
{ {
@ -3703,18 +3720,6 @@ fix_cmp(VALUE x, VALUE y)
return rb_num_coerce_cmp(x, y, id_cmp); return rb_num_coerce_cmp(x, y, id_cmp);
} }
/*
* call-seq:
* int <=> numeric -> -1, 0, +1 or nil
*
* Comparison---Returns +-1+, +0+, ++1+ or +nil+ depending on whether +fix+ is
* less than, equal to, or greater than +numeric+.
*
* This is the basis for the tests in the Comparable module.
*
* +nil+ is returned if the two values are incomparable.
*/
static VALUE static VALUE
int_cmp(VALUE x, VALUE y) int_cmp(VALUE x, VALUE y)
{ {
@ -3936,6 +3941,14 @@ fix_xor(VALUE x, VALUE y)
return rb_funcall(x, '^', 1, y); return rb_funcall(x, '^', 1, y);
} }
/*
* Document-method: Integer#<<
* call-seq:
* int << count -> integer
*
* Shifts +int+ left +count+ positions, or right if +count+ is negative.
*/
static VALUE static VALUE
rb_fix_lshift(VALUE x, VALUE y) rb_fix_lshift(VALUE x, VALUE y)
{ {
@ -3961,13 +3974,6 @@ fix_lshift(long val, unsigned long width)
return LONG2NUM(val); return LONG2NUM(val);
} }
/*
* call-seq:
* int << count -> integer
*
* Shifts +int+ left +count+ positions, or right if +count+ is negative.
*/
static VALUE static VALUE
rb_int_lshift(VALUE x, VALUE y) rb_int_lshift(VALUE x, VALUE y)
{ {
@ -3980,6 +3986,14 @@ rb_int_lshift(VALUE x, VALUE y)
return Qnil; return Qnil;
} }
/*
* Document-method: Integer#>>
* call-seq:
* int >> count -> integer
*
* Shifts +int+ right +count+ positions, or left if +count+ is negative.
*/
static VALUE static VALUE
rb_fix_rshift(VALUE x, VALUE y) rb_fix_rshift(VALUE x, VALUE y)
{ {
@ -4006,13 +4020,6 @@ fix_rshift(long val, unsigned long i)
return LONG2FIX(val); return LONG2FIX(val);
} }
/*
* call-seq:
* int >> count -> integer
*
* Shifts +int+ right +count+ positions, or left if +count+ is negative.
*/
static VALUE static VALUE
rb_int_rshift(VALUE x, VALUE y) rb_int_rshift(VALUE x, VALUE y)
{ {
@ -4025,6 +4032,27 @@ rb_int_rshift(VALUE x, VALUE y)
return Qnil; return Qnil;
} }
/*
* Document-method: Integer#[]
* call-seq:
* fix[n] -> 0, 1
*
* Bit Reference---Returns the +n+th bit in the binary representation of
* +fix+, where <code>fix[0]</code> is the least significant bit.
*
* For example:
*
* a = 0b11001100101010
* 30.downto(0) do |n| print a[n] end
* #=> 0000000000000000011001100101010
*
* a = 9**15
* 50.downto(0) do |n|
* print a[n]
* end
* #=> 000101110110100000111000011110010100111100010111001
*/
static VALUE static VALUE
fix_aref(VALUE fix, VALUE idx) fix_aref(VALUE fix, VALUE idx)
{ {
@ -4052,26 +4080,6 @@ fix_aref(VALUE fix, VALUE idx)
return INT2FIX(0); return INT2FIX(0);
} }
/*
* call-seq:
* fix[n] -> 0, 1
*
* Bit Reference---Returns the +n+th bit in the binary representation of
* +fix+, where <code>fix[0]</code> is the least significant bit.
*
* For example:
*
* a = 0b11001100101010
* 30.downto(0) do |n| print a[n] end
* #=> 0000000000000000011001100101010
*
* a = 9**15
* 50.downto(0) do |n|
* print a[n]
* end
* #=> 000101110110100000111000011110010100111100010111001
*/
static VALUE static VALUE
int_aref(VALUE num, VALUE idx) int_aref(VALUE num, VALUE idx)
{ {
@ -4111,17 +4119,9 @@ int_to_f(VALUE num)
return DBL2NUM(val); return DBL2NUM(val);
} }
static VALUE
fix_abs(VALUE fix)
{
long i = FIX2LONG(fix);
if (i < 0) i = -i;
return LONG2NUM(i);
}
/* /*
* Document-method: Integer#abs
* Document-method: Integer#magnitude
* call-seq: * call-seq:
* int.abs -> integer * int.abs -> integer
* int.magnitude -> integer * int.magnitude -> integer
@ -4134,6 +4134,16 @@ fix_abs(VALUE fix)
* *
*/ */
static VALUE
fix_abs(VALUE fix)
{
long i = FIX2LONG(fix);
if (i < 0) i = -i;
return LONG2NUM(i);
}
static VALUE static VALUE
int_abs(VALUE num) int_abs(VALUE num)
{ {
@ -4146,13 +4156,8 @@ int_abs(VALUE num)
return Qnil; return Qnil;
} }
static VALUE
fix_size(VALUE fix)
{
return INT2FIX(sizeof(long));
}
/* /*
* Document-method: Integer#size
* call-seq: * call-seq:
* int.size -> int * int.size -> int
* *
@ -4166,6 +4171,12 @@ fix_size(VALUE fix)
* (256**40 - 1).size #=> 40 * (256**40 - 1).size #=> 40
*/ */
static VALUE
fix_size(VALUE fix)
{
return INT2FIX(sizeof(long));
}
static VALUE static VALUE
int_size(VALUE num) int_size(VALUE num)
{ {
@ -4178,16 +4189,8 @@ int_size(VALUE num)
return Qnil; return Qnil;
} }
static VALUE
rb_fix_bit_length(VALUE fix)
{
long v = FIX2LONG(fix);
if (v < 0)
v = ~v;
return LONG2FIX(bit_length(v));
}
/* /*
* Document-method: Integer#bit_length
* call-seq: * call-seq:
* int.bit_length -> integer * int.bit_length -> integer
* *
@ -4199,8 +4202,7 @@ rb_fix_bit_length(VALUE fix)
* If there is no such bit (zero or minus one), zero is returned. * If there is no such bit (zero or minus one), zero is returned.
* *
* I.e. This method returns ceil(log2(int < 0 ? -int : int+1)). * I.e. This method returns ceil(log2(int < 0 ? -int : int+1)).
*
* (-2**10000-1).bit_length #=> 10001 * (-2**10000-1).bit_length #=> 10001
* (-2**10000).bit_length #=> 10000 * (-2**10000).bit_length #=> 10000
* (-2**10000+1).bit_length #=> 10000 * (-2**10000+1).bit_length #=> 10000
@ -4238,6 +4240,15 @@ rb_fix_bit_length(VALUE fix)
* end * end
*/ */
static VALUE
rb_fix_bit_length(VALUE fix)
{
long v = FIX2LONG(fix);
if (v < 0)
v = ~v;
return LONG2FIX(bit_length(v));
}
static VALUE static VALUE
rb_int_bit_length(VALUE num) rb_int_bit_length(VALUE num)
{ {
@ -4250,13 +4261,8 @@ rb_int_bit_length(VALUE num)
return Qnil; return Qnil;
} }
static VALUE
int_upto_size(VALUE from, VALUE args, VALUE eobj)
{
return ruby_num_interval_step_size(from, RARRAY_AREF(args, 0), INT2FIX(1), FALSE);
}
/* /*
* Document-method: Integer#upto
* call-seq: * call-seq:
* int.upto(limit) {|i| block } -> self * int.upto(limit) {|i| block } -> self
* int.upto(limit) -> an_enumerator * int.upto(limit) -> an_enumerator
@ -4272,6 +4278,12 @@ int_upto_size(VALUE from, VALUE args, VALUE eobj)
* #=> 5 6 7 8 9 10 * #=> 5 6 7 8 9 10
*/ */
static VALUE
int_upto_size(VALUE from, VALUE args, VALUE eobj)
{
return ruby_num_interval_step_size(from, RARRAY_AREF(args, 0), INT2FIX(1), FALSE);
}
static VALUE static VALUE
int_upto(VALUE from, VALUE to) int_upto(VALUE from, VALUE to)
{ {
@ -4296,13 +4308,8 @@ int_upto(VALUE from, VALUE to)
return from; return from;
} }
static VALUE
int_downto_size(VALUE from, VALUE args, VALUE eobj)
{
return ruby_num_interval_step_size(from, RARRAY_AREF(args, 0), INT2FIX(-1), FALSE);
}
/* /*
* Document-method: Integer#downto
* call-seq: * call-seq:
* int.downto(limit) {|i| block } -> self * int.downto(limit) {|i| block } -> self
* int.downto(limit) -> an_enumerator * int.downto(limit) -> an_enumerator
@ -4317,6 +4324,12 @@ int_downto_size(VALUE from, VALUE args, VALUE eobj)
* #=> "5.. 4.. 3.. 2.. 1.. Liftoff!" * #=> "5.. 4.. 3.. 2.. 1.. Liftoff!"
*/ */
static VALUE
int_downto_size(VALUE from, VALUE args, VALUE eobj)
{
return ruby_num_interval_step_size(from, RARRAY_AREF(args, 0), INT2FIX(-1), FALSE);
}
static VALUE static VALUE
int_downto(VALUE from, VALUE to) int_downto(VALUE from, VALUE to)
{ {
@ -4341,19 +4354,8 @@ int_downto(VALUE from, VALUE to)
return from; return from;
} }
static VALUE
int_dotimes_size(VALUE num, VALUE args, VALUE eobj)
{
if (FIXNUM_P(num)) {
if (NUM2LONG(num) <= 0) return INT2FIX(0);
}
else {
if (RTEST(rb_funcall(num, '<', 1, INT2FIX(0)))) return INT2FIX(0);
}
return num;
}
/* /*
* Document-method: Integer#times
* call-seq: * call-seq:
* int.times {|i| block } -> self * int.times {|i| block } -> self
* int.times -> an_enumerator * int.times -> an_enumerator
@ -4369,6 +4371,18 @@ int_dotimes_size(VALUE num, VALUE args, VALUE eobj)
* #=> 0 1 2 3 4 * #=> 0 1 2 3 4
*/ */
static VALUE
int_dotimes_size(VALUE num, VALUE args, VALUE eobj)
{
if (FIXNUM_P(num)) {
if (NUM2LONG(num) <= 0) return INT2FIX(0);
}
else {
if (RTEST(rb_funcall(num, '<', 1, INT2FIX(0)))) return INT2FIX(0);
}
return num;
}
static VALUE static VALUE
int_dotimes(VALUE num) int_dotimes(VALUE num)
{ {