1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* numeric.c (int_pred): add Integer#pred corresponding

Integer#succ.  [RCR#5]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2007-01-30 04:27:04 +00:00
parent bfc2a070b1
commit 8418ea8bb8
2 changed files with 26 additions and 0 deletions

View file

@ -1,3 +1,8 @@
Tue Jan 30 13:24:06 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* numeric.c (int_pred): add Integer#pred corresponding
Integer#succ. [RCR#5]
Tue Jan 30 12:05:35 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> Tue Jan 30 12:05:35 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* mkconfig.rb: autoconf 2.61 support. [ruby-core:10016] * mkconfig.rb: autoconf 2.61 support. [ruby-core:10016]

View file

@ -1766,6 +1766,26 @@ int_succ(VALUE num)
return rb_funcall(num, '+', 1, INT2FIX(1)); return rb_funcall(num, '+', 1, INT2FIX(1));
} }
/*
* call-seq:
* int.pred => integer
*
* Returns the <code>Integer</code> equal to <i>int</i> - 1.
*
* 1.pred #=> 0
* (-1).pred #=> -2
*/
static VALUE
int_pred(VALUE num)
{
if (FIXNUM_P(num)) {
long i = FIX2LONG(num) - 1;
return LONG2NUM(i);
}
return rb_funcall(num, '-', 1, INT2FIX(1));
}
/* /*
* call-seq: * call-seq:
* int.chr => string * int.chr => string
@ -2948,6 +2968,7 @@ Init_Numeric(void)
rb_include_module(rb_cInteger, rb_mPrecision); rb_include_module(rb_cInteger, rb_mPrecision);
rb_define_method(rb_cInteger, "succ", int_succ, 0); rb_define_method(rb_cInteger, "succ", int_succ, 0);
rb_define_method(rb_cInteger, "next", int_succ, 0); rb_define_method(rb_cInteger, "next", int_succ, 0);
rb_define_method(rb_cInteger, "pred", int_pred, 0);
rb_define_method(rb_cInteger, "chr", int_chr, 0); rb_define_method(rb_cInteger, "chr", int_chr, 0);
rb_define_method(rb_cInteger, "to_i", int_to_i, 0); rb_define_method(rb_cInteger, "to_i", int_to_i, 0);
rb_define_method(rb_cInteger, "to_int", int_to_i, 0); rb_define_method(rb_cInteger, "to_int", int_to_i, 0);