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

* numeric.c (int_round): small optimization to handle bignums.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2007-06-01 16:27:05 +00:00
parent 62872956b6
commit 2c4aff3fe0
3 changed files with 24 additions and 4 deletions

View file

@ -1,3 +1,7 @@
Sat Jun 2 01:27:27 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* numeric.c (int_round): small optimization to handle bignums.
Fri Jun 1 13:02:35 2007 NAKAMURA Usaku <usa@ruby-lang.org>
* insnhelper.h (INC_SP): shouldn't cast ``x'' to unsigned type because

View file

@ -2308,6 +2308,22 @@ int_pow(long x, unsigned long y)
return LONG2NUM(z);
}
static VALUE
int_round(int argc, VALUE* argv, VALUE num)
{
VALUE nd;
int ndigits;
if (argc == 0) return num;
rb_scan_args(argc, argv, "1", &nd);
ndigits = NUM2INT(nd);
if (ndigits > 0) {
return rb_Float(num);
}
ndigits = -ndigits;
return rb_funcall(num, '-', 1, rb_funcall(num, '%', 1, int_pow(10, ndigits)));
}
/*
* call-seq:
* fix ** other => Numeric
@ -3013,8 +3029,8 @@ Init_Numeric(void)
rb_define_method(rb_cInteger, "to_int", int_to_i, 0);
rb_define_method(rb_cInteger, "floor", int_to_i, 0);
rb_define_method(rb_cInteger, "ceil", int_to_i, 0);
rb_define_method(rb_cInteger, "round", int_to_i, 0);
rb_define_method(rb_cInteger, "truncate", int_to_i, 0);
rb_define_method(rb_cInteger, "round", int_round, -1);
rb_cFixnum = rb_define_class("Fixnum", rb_cInteger);
rb_include_module(rb_cFixnum, rb_mPrecision);

View file

@ -1,7 +1,7 @@
#define RUBY_VERSION "1.9.0"
#define RUBY_RELEASE_DATE "2007-06-01"
#define RUBY_RELEASE_DATE "2007-06-02"
#define RUBY_VERSION_CODE 190
#define RUBY_RELEASE_CODE 20070601
#define RUBY_RELEASE_CODE 20070602
#define RUBY_PATCHLEVEL 0
#define RUBY_VERSION_MAJOR 1
@ -9,7 +9,7 @@
#define RUBY_VERSION_TEENY 0
#define RUBY_RELEASE_YEAR 2007
#define RUBY_RELEASE_MONTH 6
#define RUBY_RELEASE_DAY 1
#define RUBY_RELEASE_DAY 2
#ifdef RUBY_EXTERN
RUBY_EXTERN const char ruby_version[];