Removed canonicalization for mathn

This commit is contained in:
Nobuyoshi Nakada 2020-10-23 14:38:24 +09:00 коммит произвёл Hiroshi SHIBATA
Родитель 8b3653b484
Коммит b958e2add8
8 изменённых файлов: 8 добавлений и 83 удалений

1
.github/workflows/compilers.yml поставляемый
Просмотреть файл

@ -92,7 +92,6 @@ jobs:
- { 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' }

Просмотреть файл

@ -7593,13 +7593,7 @@ finish_exact_sum(long n, VALUE r, VALUE v, int z)
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);

Просмотреть файл

@ -429,18 +429,6 @@ f_complex_new_bang2(VALUE klass, VALUE x, VALUE y)
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
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)
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)
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)
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);

Просмотреть файл

@ -1626,10 +1626,8 @@ RUBY_DECL_ATTRIBUTE([__nonnull__(n)], [RUBY_FUNC_NONNULL(n,x)], [rb_cv_func_nonn
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,

11
enum.c
Просмотреть файл

@ -3854,10 +3854,7 @@ sum_iter_normalize_memo(struct enum_sum_memo *memo)
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)
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;
}

Просмотреть файл

@ -430,18 +430,6 @@ f_rational_new_bang1(VALUE klass, VALUE x)
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)
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)
{
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)
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)
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)
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)
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)
num = negate_num(num);
}
if (!canonicalization || den != ONE)
num = rb_rational_raw(num, den);
return num;
return rb_rational_raw(num, den);
}
static VALUE

Просмотреть файл

@ -84,8 +84,7 @@ optflags = @optflags@
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)

Просмотреть файл

@ -67,9 +67,6 @@ icondirs=$(ICONDIRS)
icondirs=$(icondirs:\=/)
iconinc=-I$(icondirs: = -I)
!endif
!if !defined(MATHN)
MATHN = yes
!endif
###############
.SUFFIXES: .def .lib
@ -308,9 +305,6 @@ ARFLAGS = -machine:$(MACHINE) -out:
LD = $(CC)
LDSHARED = $(LD) -LD
XCFLAGS = -DRUBY_EXPORT $(INCFLAGS) $(XCFLAGS)
!if "$(MATHN)" == "yes"
XCFLAGS = $(XCFLAGS) -DCANONICALIZATION_FOR_MATHN
!endif
!if $(MSC_VER) >= 1400
# Prevents VC++ 2005 (cl ver 14) warnings
MANIFESTTOOL = mt -nologo