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

ruby-changes:63568

From: Nobuyoshi <ko1@a...>
Date: Tue, 10 Nov 2020 11:14:31 +0900 (JST)
Subject: [ruby-changes:63568] b958e2add8 (master): Removed canonicalization for mathn

https://git.ruby-lang.org/ruby.git/commit/?id=b958e2add8

From b958e2add835d62c0a62edaf9a23ecbbd70a3635 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Fri, 23 Oct 2020 14:38:24 +0900
Subject: Removed canonicalization for mathn


diff --git a/.github/workflows/compilers.yml b/.github/workflows/compilers.yml
index 17211b5..7ab65fe 100644
--- a/.github/workflows/compilers.yml
+++ b/.github/workflows/compilers.yml
@@ -92,7 +92,6 @@ jobs: https://github.com/ruby/ruby/blob/trunk/.github/workflows/compilers.yml#L92
           - { key: append_configure, name: valgrind,             value: '--with-valgrind' }
           - { key: append_configure, name: 'coroutine=ucontext', value: '--with-coroutine=ucontext' }
           - { key: append_configure, name: 'coroutine=copy',     value: '--with-coroutine=copy' }
-          - { key: append_configure, name: disable-mathn,        value: '--disable-mathn' }
           - { key: append_configure, name: disable-jit-support,  value: '--disable-jit-support' }
           - { key: append_configure, name: disable-dln,          value: '--disable-dln' }
           - { key: append_configure, name: disable-rubygems,     value: '--disable-rubygems' }
diff --git a/array.c b/array.c
index 6a7a790..ba13ac5 100644
--- a/array.c
+++ b/array.c
@@ -7593,13 +7593,7 @@ finish_exact_sum(long n, VALUE r, VALUE v, int z) https://github.com/ruby/ruby/blob/trunk/array.c#L7593
     if (n != 0)
         v = rb_fix_plus(LONG2FIX(n), v);
     if (r != Qundef) {
-	/* r can be an Integer when mathn is loaded */
-	if (FIXNUM_P(r))
-	    v = rb_fix_plus(r, v);
-	else if (RB_TYPE_P(r, T_BIGNUM))
-	    v = rb_big_plus(r, v);
-	else
-	    v = rb_rational_plus(r, v);
+        v = rb_rational_plus(r, v);
     }
     else if (!n && z) {
         v = rb_fix_plus(LONG2FIX(0), v);
diff --git a/complex.c b/complex.c
index 377aae5..560d978 100644
--- a/complex.c
+++ b/complex.c
@@ -429,18 +429,6 @@ f_complex_new_bang2(VALUE klass, VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/complex.c#L429
     return nucomp_s_new_internal(klass, x, y);
 }
 
-#ifdef CANONICALIZATION_FOR_MATHN
-static int canonicalization = 0;
-
-RUBY_FUNC_EXPORTED void
-nucomp_canonicalization(int f)
-{
-    canonicalization = f;
-}
-#else
-#define canonicalization 0
-#endif
-
 inline static void
 nucomp_real_check(VALUE num)
 {
@@ -456,10 +444,6 @@ inline static VALUE https://github.com/ruby/ruby/blob/trunk/complex.c#L444
 nucomp_s_canonicalize_internal(VALUE klass, VALUE real, VALUE imag)
 {
     int complex_r, complex_i;
-#ifdef CANONICALIZATION_FOR_MATHN
-    if (k_exact_zero_p(imag) && canonicalization)
-	return real;
-#endif
     complex_r = RB_TYPE_P(real, T_COMPLEX);
     complex_i = RB_TYPE_P(imag, T_COMPLEX);
     if (!complex_r && !complex_i) {
@@ -636,14 +620,12 @@ f_complex_polar(VALUE klass, VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/complex.c#L620
     assert(!RB_TYPE_P(x, T_COMPLEX));
     assert(!RB_TYPE_P(y, T_COMPLEX));
     if (f_zero_p(x) || f_zero_p(y)) {
-	if (canonicalization) return x;
 	return nucomp_s_new_internal(klass, x, RFLOAT_0);
     }
     if (RB_FLOAT_TYPE_P(y)) {
 	const double arg = RFLOAT_VALUE(y);
 	if (arg == M_PI) {
 	    x = f_negate(x);
-	    if (canonicalization) return x;
 	    y = RFLOAT_0;
 	}
 	else if (arg == M_PI_2) {
@@ -658,14 +640,12 @@ f_complex_polar(VALUE klass, VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/complex.c#L640
 	    const double abs = RFLOAT_VALUE(x);
 	    const double real = abs * cos(arg), imag = abs * sin(arg);
 	    x = DBL2NUM(real);
-	    if (canonicalization && imag == 0.0) return x;
 	    y = DBL2NUM(imag);
 	}
 	else {
             const double ax = sin(arg), ay = cos(arg);
             y = f_mul(x, DBL2NUM(ax));
             x = f_mul(x, DBL2NUM(ay));
-	    if (canonicalization && f_zero_p(y)) return x;
 	}
 	return nucomp_s_new_internal(klass, x, y);
     }
@@ -725,7 +705,6 @@ nucomp_s_polar(int argc, VALUE *argv, VALUE klass) https://github.com/ruby/ruby/blob/trunk/complex.c#L705
     switch (rb_scan_args(argc, argv, "11", &abs, &arg)) {
       case 1:
 	nucomp_real_check(abs);
-	if (canonicalization) return abs;
 	return nucomp_s_new_internal(klass, abs, ZERO);
       default:
 	nucomp_real_check(abs);
diff --git a/configure.ac b/configure.ac
index 1d511ea..a5e3dc7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1626,10 +1626,8 @@ RUBY_DECL_ATTRIBUTE([__nonnull__(n)], [RUBY_FUNC_NONNULL(n,x)], [rb_cv_func_nonn https://github.com/ruby/ruby/blob/trunk/configure.ac#L1626
 RUBY_APPEND_OPTION(XCFLAGS, -DRUBY_EXPORT)
 
 AC_ARG_ENABLE(mathn,
-    AS_HELP_STRING([--disable-mathn], [disable canonicalization for mathn]),
-    [mathn=$enableval], [mathn=yes])
-test "x$mathn" = xyes || mathn=
-AC_SUBST(MATHN, $mathn)
+    AS_HELP_STRING([--enable-mathn], [enable canonicalization for mathn]),
+    [AC_MSG_ERROR([mathn support has been dropped])])
 
 AC_CACHE_CHECK(for function name string predefined identifier,
     rb_cv_function_name_string,
diff --git a/enum.c b/enum.c
index 8a791cc..d21becd 100644
--- a/enum.c
+++ b/enum.c
@@ -3854,10 +3854,7 @@ sum_iter_normalize_memo(struct enum_sum_memo *memo) https://github.com/ruby/ruby/blob/trunk/enum.c#L3854
     memo->v = rb_fix_plus(LONG2FIX(memo->n), memo->v);
     memo->n = 0;
 
-    /* r can be an Integer when mathn is loaded */
     switch (TYPE(memo->r)) {
-      case T_FIXNUM:   memo->v = rb_fix_plus(memo->r, memo->v);      break;
-      case T_BIGNUM:   memo->v = rb_big_plus(memo->r, memo->v);      break;
       case T_RATIONAL: memo->v = rb_rational_plus(memo->r, memo->v); break;
       case T_UNDEF:    break;
       default:         UNREACHABLE; /* or ...? */
@@ -4107,13 +4104,7 @@ enum_sum(int argc, VALUE* argv, VALUE obj) https://github.com/ruby/ruby/blob/trunk/enum.c#L4104
         if (memo.n != 0)
             memo.v = rb_fix_plus(LONG2FIX(memo.n), memo.v);
         if (memo.r != Qundef) {
-            /* r can be an Integer when mathn is loaded */
-            if (FIXNUM_P(memo.r))
-                memo.v = rb_fix_plus(memo.r, memo.v);
-            else if (RB_TYPE_P(memo.r, T_BIGNUM))
-                memo.v = rb_big_plus(memo.r, memo.v);
-            else
-                memo.v = rb_rational_plus(memo.r, memo.v);
+            memo.v = rb_rational_plus(memo.r, memo.v);
         }
         return memo.v;
     }
diff --git a/rational.c b/rational.c
index abf3331..bb7c66c 100644
--- a/rational.c
+++ b/rational.c
@@ -430,18 +430,6 @@ f_rational_new_bang1(VALUE klass, VALUE x) https://github.com/ruby/ruby/blob/trunk/rational.c#L430
     return nurat_s_new_internal(klass, x, ONE);
 }
 
-#ifdef CANONICALIZATION_FOR_MATHN
-static int canonicalization = 0;
-
-RUBY_FUNC_EXPORTED void
-nurat_canonicalization(int f)
-{
-    canonicalization = f;
-}
-#else
-# define canonicalization 0
-#endif
-
 inline static void
 nurat_int_check(VALUE num)
 {
@@ -490,8 +478,6 @@ nurat_s_canonicalize_internal(VALUE klass, VALUE num, VALUE den) https://github.com/ruby/ruby/blob/trunk/rational.c#L478
     nurat_canonicalize(&num, &den);
     nurat_reduce(&num, &den);
 
-    if (canonicalization && f_one_p(den))
-	return num;
     return nurat_s_new_internal(klass, num, den);
 }
 
@@ -500,8 +486,6 @@ nurat_s_canonicalize_internal_no_reduce(VALUE klass, VALUE num, VALUE den) https://github.com/ruby/ruby/blob/trunk/rational.c#L486
 {
     nurat_canonicalize(&num, &den);
 
-    if (canonicalization && f_one_p(den))
-	return num;
     return nurat_s_new_internal(klass, num, den);
 }
 
@@ -2028,12 +2012,7 @@ rb_numeric_quo(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/rational.c#L2012
         return rb_funcallv(x, idFdiv, 1, &y);
     }
 
-    if (canonicalization) {
-        x = rb_rational_raw1(x);
-    }
-    else {
-        x = rb_convert_type(x, T_RATIONAL, "Rational", "to_r");
-    }
+    x = rb_convert_type(x, T_RATIONAL, "Rational", "to_r");
     return nurat_div(x, y);
 }
 
@@ -2092,9 +2071,6 @@ rb_float_numerator(VALUE self) https://github.com/ruby/ruby/blob/trunk/rational.c#L2071
     if (isinf(d) || isnan(d))
 	return self;
     r = float_to_r(self);
-    if (canonicalization && k_integer_p(r)) {
-	return r;
-    }
     return nurat_numerator(r);
 }
 
@@ -2115,9 +2091,6 @@ rb_float_denominator(VALUE self) https://github.com/ruby/ruby/blob/trunk/rational.c#L2091
     if (isinf(d) || isnan(d))
 	return INT2FIX(1);
     r = float_to_r(self);
-    if (canonicalization && k_integer_p(r)) {
-	return ONE;
-    }
     return nurat_denominator(r);
 }
 
@@ -2425,7 +2398,7 @@ parse_rat(const char *s, const char *const e, int strict, int raise) https://github.com/ruby/ruby/blob/trunk/rational.c#L2398
 
     if (!read_num(&s, e, &num, &nexp)) {
 	if (strict) return Qnil;
-	return canonicalization ? ZERO : nurat_s_alloc(rb_cRational);
+	return nurat_s_alloc(rb_cRational);
     }
     den = ONE;
     if (s < e && *s == '/') {
@@ -2481,9 +2454,7 @@ parse_rat(const char *s, const char *const e, int strict, int raise) https://github.com/ruby/ruby/blob/trunk/rational.c#L2454
 	num = negate_num(num);
     }
 
-    if (!canonicalization || den != ONE)
-	num = rb_rational_raw(num, den);
-    return num;
+    return rb_rational_raw(num, den);
 }
 
 static VALUE
diff --git a/template/Makefile.in b/template/Makefile.in
index c674de9..08e47e7 100644
--- a/template/Makefile.in
+++ b/template/Makefile.in
@@ -84,8 +84,7 @@ optflags = @optflags@ https://github.com/ruby/ruby/blob/trunk/template/Makefile.in#L84
 debugflags = @debugflags@
 warnflags = @warnflags@ @strict_warnflags@
 cppflags = @cppflags@
-MATHN = @MATHN@
-XCFLAGS = @XCFLAGS@ $(MATHN:yes=-DCANONICALIZATION_FOR_MATHN) $(INCFLAGS)
+XCFLAGS = @XCFLAGS@ $(INCFLAGS)
 USE_RUBYGEMS = @USE_RUBYGEMS@
 USE_RUBYGEMS_ = $(USE_RUBYGEMS:yes=)
 CPPFLAGS = @CPPFLAGS@ $(USE_RUBYGEMS_:no=-DDISABLE_RUBYGEMS=1)
diff --git a/win32/Makefile.sub b/win32/Makefile.sub
index 87cda5f..9686d1c 100644
--- a/win32/Makefile.sub
+++ b/win32/Makefile.sub
@@ -67,9 +67,6 @@ icondirs=$(ICONDIRS) https://github.com/ruby/ruby/blob/ (... truncated)

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

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