aboutsummaryrefslogtreecommitdiffstats
path: root/bignum.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-17 06:53:48 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-17 06:53:48 +0000
commit0362ad83a7c1852d638915859ca56f49d39fb8ac (patch)
treebdf433b181c6d6e00bd33581136ab2970bc9509d /bignum.c
parent314346ad7b7248421af13633ad1bdec704799afe (diff)
downloadruby-0362ad83a7c1852d638915859ca56f49d39fb8ac.tar.gz
[Feature #12005] Unify Fixnum and Bignum into Integer
* [Feature #12005] Unify Fixnum and Bignum into Integer * include/ruby/ruby.h (rb_class_of): Return rb_cInteger for fixnums. * insns.def (INTEGER_REDEFINED_OP_FLAG): Unified from FIXNUM_REDEFINED_OP_FLAG and BIGNUM_REDEFINED_OP_FLAG. * vm_core.h: Ditto. * vm_insnhelper.c (opt_eq_func): Use INTEGER_REDEFINED_OP_FLAG instead of FIXNUM_REDEFINED_OP_FLAG. * vm.c (vm_redefinition_check_flag): Use rb_cInteger instead of rb_cFixnum and rb_cBignum. (C): Use Integer instead of Fixnum and Bignum. * numeric.c (fix_succ): Removed. (Init_Numeric): Define Fixnum as Integer. * bignum.c (bignew): Use rb_cInteger instead of Rb_cBignum. (rb_int_coerce): replaced from rb_big_coerce and return fixnums as-is. (Init_Bignum): Define Bignum as Integer. Don't define ===. * error.c (builtin_class_name): Return "Integer" for fixnums. * sprintf.c (ruby__sfvextra): Use rb_cInteger instead of rb_cFixnum. * ext/-test-/testutil: New directory to test. Currently it provides utilities for fixnum and bignum. * ext/json/generator/generator.c: Define mInteger_to_json. * lib/mathn.rb (Fixnum#/): Redefinition removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/bignum.c b/bignum.c
index bb518d1a44..d1e10b95c3 100644
--- a/bignum.c
+++ b/bignum.c
@@ -110,7 +110,7 @@ STATIC_ASSERT(sizeof_long_and_sizeof_bdigit, SIZEOF_BDIGIT % SIZEOF_LONG == 0);
#define BIGNUM_SET_NEGATIVE_SIGN(b) BIGNUM_SET_SIGN(b, 0)
#define BIGNUM_SET_POSITIVE_SIGN(b) BIGNUM_SET_SIGN(b, 1)
-#define bignew(len,sign) bignew_1(rb_cBignum,(len),(sign))
+#define bignew(len,sign) bignew_1(rb_cInteger,(len),(sign))
#define BDIGITS_ZERO(ptr, n) do { \
BDIGIT *bdigitz_zero_ptr = (ptr); \
@@ -6669,16 +6669,16 @@ rb_big_hash(VALUE x)
*/
static VALUE
-rb_big_coerce(VALUE x, VALUE y)
+rb_int_coerce(VALUE x, VALUE y)
{
- if (FIXNUM_P(y)) {
- y = rb_int2big(FIX2LONG(y));
+ if (FIXNUM_P(y) || RB_BIGNUM_TYPE_P(y)) {
+ return rb_assoc_new(y, x);
}
- else if (!RB_BIGNUM_TYPE_P(y)) {
- rb_raise(rb_eTypeError, "can't coerce %"PRIsVALUE" to Bignum",
- rb_obj_class(y));
+ else {
+ x = rb_Float(x);
+ y = rb_Float(y);
+ return rb_assoc_new(y, x);
}
- return rb_assoc_new(y, x);
}
VALUE
@@ -6783,15 +6783,13 @@ rb_big_even_p(VALUE num)
void
Init_Bignum(void)
{
- rb_cBignum = rb_define_class("Bignum", rb_cInteger);
-
- rb_define_method(rb_cBignum, "coerce", rb_big_coerce, 1);
+ rb_cBignum = rb_cInteger;
+ rb_define_const(rb_cObject, "Bignum", rb_cInteger);
- rb_define_method(rb_cBignum, "===", rb_big_eq, 1);
+ rb_define_method(rb_cInteger, "coerce", rb_int_coerce, 1);
#ifdef USE_GMP
/* The version of loaded GMP. */
- rb_define_const(rb_cBignum, "GMP_VERSION", rb_sprintf("GMP %s", gmp_version));
rb_define_const(rb_cInteger, "GMP_VERSION", rb_sprintf("GMP %s", gmp_version));
#endif