Removed canonicalization for mathn

This commit is contained in:
Nobuyoshi Nakada 2020-10-23 14:38:24 +09:00 committed by Hiroshi SHIBATA
parent 8b3653b484
commit b958e2add8
Notes: git 2020-11-10 11:14:40 +09:00
8 changed files with 8 additions and 83 deletions

View file

@ -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);