* complex.c, rational.c: fixed indent.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16154 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9f9a532d98
commit
f80616b6d2
39
complex.c
39
complex.c
@ -74,12 +74,14 @@ f_add(VALUE x, VALUE y)
|
|||||||
r = x;
|
r = x;
|
||||||
else
|
else
|
||||||
r = rb_funcall(x, '+', 1, y);
|
r = rb_funcall(x, '+', 1, y);
|
||||||
} else if (FIXNUM_P(x)) {
|
}
|
||||||
|
else if (FIXNUM_P(x)) {
|
||||||
if (FIX2LONG(x) == 0)
|
if (FIX2LONG(x) == 0)
|
||||||
r = y;
|
r = y;
|
||||||
else
|
else
|
||||||
r = rb_funcall(x, '+', 1, y);
|
r = rb_funcall(x, '+', 1, y);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
r = rb_funcall(x, '+', 1, y);
|
r = rb_funcall(x, '+', 1, y);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -95,7 +97,8 @@ f_cmp(VALUE x, VALUE y)
|
|||||||
else if (c < 0)
|
else if (c < 0)
|
||||||
c = -1;
|
c = -1;
|
||||||
r = INT2FIX(c);
|
r = INT2FIX(c);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
r = rb_funcall(x, id_cmp, 1, y);
|
r = rb_funcall(x, id_cmp, 1, y);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -146,22 +149,26 @@ f_mul(VALUE x, VALUE y)
|
|||||||
r = rb_float_new(0.0);
|
r = rb_float_new(0.0);
|
||||||
else
|
else
|
||||||
r = ZERO;
|
r = ZERO;
|
||||||
} else if (_iy == 1)
|
}
|
||||||
|
else if (_iy == 1)
|
||||||
r = x;
|
r = x;
|
||||||
else
|
else
|
||||||
r = rb_funcall(x, '*', 1, y);
|
r = rb_funcall(x, '*', 1, y);
|
||||||
} else if (FIXNUM_P(x)) {
|
}
|
||||||
|
else if (FIXNUM_P(x)) {
|
||||||
long _ix = FIX2LONG(x);
|
long _ix = FIX2LONG(x);
|
||||||
if (_ix == 0) {
|
if (_ix == 0) {
|
||||||
if (TYPE(y) == T_FLOAT)
|
if (TYPE(y) == T_FLOAT)
|
||||||
r = rb_float_new(0.0);
|
r = rb_float_new(0.0);
|
||||||
else
|
else
|
||||||
r = ZERO;
|
r = ZERO;
|
||||||
} else if (_ix == 1)
|
}
|
||||||
|
else if (_ix == 1)
|
||||||
r = y;
|
r = y;
|
||||||
else
|
else
|
||||||
r = rb_funcall(x, '*', 1, y);
|
r = rb_funcall(x, '*', 1, y);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
r = rb_funcall(x, '*', 1, y);
|
r = rb_funcall(x, '*', 1, y);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -175,7 +182,8 @@ f_sub(VALUE x, VALUE y)
|
|||||||
r = x;
|
r = x;
|
||||||
else
|
else
|
||||||
r = rb_funcall(x, '-', 1, y);
|
r = rb_funcall(x, '-', 1, y);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
r = rb_funcall(x, '-', 1, y);
|
r = rb_funcall(x, '-', 1, y);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -403,13 +411,15 @@ nucomp_s_canonicalize_internal(VALUE klass, VALUE real, VALUE image)
|
|||||||
return nucomp_s_new_internal(klass,
|
return nucomp_s_new_internal(klass,
|
||||||
f_sub(real, dat->image),
|
f_sub(real, dat->image),
|
||||||
f_add(ZERO, dat->real));
|
f_add(ZERO, dat->real));
|
||||||
} else if (f_scalar_p(image)) {
|
}
|
||||||
|
else if (f_scalar_p(image)) {
|
||||||
get_dat1(real);
|
get_dat1(real);
|
||||||
|
|
||||||
return nucomp_s_new_internal(klass,
|
return nucomp_s_new_internal(klass,
|
||||||
dat->real,
|
dat->real,
|
||||||
f_add(dat->image, image));
|
f_add(dat->image, image));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
get_dat2(real, image);
|
get_dat2(real, image);
|
||||||
|
|
||||||
return nucomp_s_new_internal(klass,
|
return nucomp_s_new_internal(klass,
|
||||||
@ -538,7 +548,8 @@ m_sqrt(VALUE x)
|
|||||||
return m_sqrt_bang(x);
|
return m_sqrt_bang(x);
|
||||||
else
|
else
|
||||||
return f_complex_new2(rb_cComplex, ZERO, m_sqrt_bang(f_negate(x)));
|
return f_complex_new2(rb_cComplex, ZERO, m_sqrt_bang(f_negate(x)));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
get_dat1(x);
|
get_dat1(x);
|
||||||
|
|
||||||
if (f_negative_p(dat->image))
|
if (f_negative_p(dat->image))
|
||||||
@ -759,7 +770,8 @@ nucomp_expt(VALUE self, VALUE other)
|
|||||||
n = f_sub(n, ONE);
|
n = f_sub(n, ONE);
|
||||||
}
|
}
|
||||||
return z;
|
return z;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return f_expt(f_div(f_to_r(ONE), self), f_negate(other));
|
return f_expt(f_div(f_to_r(ONE), self), f_negate(other));
|
||||||
}
|
}
|
||||||
case T_FLOAT:
|
case T_FLOAT:
|
||||||
@ -989,7 +1001,8 @@ nucomp_to_s(VALUE self)
|
|||||||
rb_str_cat2(s, "(");
|
rb_str_cat2(s, "(");
|
||||||
rb_str_concat(s, f_to_s(rezero ? dat->image : f_abs(dat->image)));
|
rb_str_concat(s, f_to_s(rezero ? dat->image : f_abs(dat->image)));
|
||||||
rb_str_cat2(s, ")i");
|
rb_str_cat2(s, ")i");
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
rb_str_concat(s, f_to_s(rezero ? dat->image : f_abs(dat->image)));
|
rb_str_concat(s, f_to_s(rezero ? dat->image : f_abs(dat->image)));
|
||||||
rb_str_cat2(s, "i");
|
rb_str_cat2(s, "i");
|
||||||
}
|
}
|
||||||
|
39
rational.c
39
rational.c
@ -23,7 +23,7 @@
|
|||||||
VALUE rb_cRational;
|
VALUE rb_cRational;
|
||||||
|
|
||||||
static ID id_Unify, id_abs, id_cmp, id_convert, id_equal_p,
|
static ID id_Unify, id_abs, id_cmp, id_convert, id_equal_p,
|
||||||
id_expt, id_floor, id_format,id_idiv, id_inspect, id_negate, id_new,
|
id_expt, id_floor, id_format, id_idiv, id_inspect, id_negate, id_new,
|
||||||
id_new_bang, id_to_f, id_to_i, id_to_s, id_truncate;
|
id_new_bang, id_to_f, id_to_i, id_to_s, id_truncate;
|
||||||
|
|
||||||
#define f_boolcast(x) ((x) ? Qtrue : Qfalse)
|
#define f_boolcast(x) ((x) ? Qtrue : Qfalse)
|
||||||
@ -58,12 +58,14 @@ f_add(VALUE x, VALUE y)
|
|||||||
r = x;
|
r = x;
|
||||||
else
|
else
|
||||||
r = rb_funcall(x, '+', 1, y);
|
r = rb_funcall(x, '+', 1, y);
|
||||||
} else if (FIXNUM_P(x)) {
|
}
|
||||||
|
else if (FIXNUM_P(x)) {
|
||||||
if (FIX2LONG(x) == 0)
|
if (FIX2LONG(x) == 0)
|
||||||
r = y;
|
r = y;
|
||||||
else
|
else
|
||||||
r = rb_funcall(x, '+', 1, y);
|
r = rb_funcall(x, '+', 1, y);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
r = rb_funcall(x, '+', 1, y);
|
r = rb_funcall(x, '+', 1, y);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -79,7 +81,8 @@ f_cmp(VALUE x, VALUE y)
|
|||||||
else if (c < 0)
|
else if (c < 0)
|
||||||
c = -1;
|
c = -1;
|
||||||
r = INT2FIX(c);
|
r = INT2FIX(c);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
r = rb_funcall(x, id_cmp, 1, y);
|
r = rb_funcall(x, id_cmp, 1, y);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -130,22 +133,26 @@ f_mul(VALUE x, VALUE y)
|
|||||||
r = rb_float_new(0.0);
|
r = rb_float_new(0.0);
|
||||||
else
|
else
|
||||||
r = ZERO;
|
r = ZERO;
|
||||||
} else if (_iy == 1)
|
}
|
||||||
|
else if (_iy == 1)
|
||||||
r = x;
|
r = x;
|
||||||
else
|
else
|
||||||
r = rb_funcall(x, '*', 1, y);
|
r = rb_funcall(x, '*', 1, y);
|
||||||
} else if (FIXNUM_P(x)) {
|
}
|
||||||
|
else if (FIXNUM_P(x)) {
|
||||||
long _ix = FIX2LONG(x);
|
long _ix = FIX2LONG(x);
|
||||||
if (_ix == 0) {
|
if (_ix == 0) {
|
||||||
if (TYPE(y) == T_FLOAT)
|
if (TYPE(y) == T_FLOAT)
|
||||||
r = rb_float_new(0.0);
|
r = rb_float_new(0.0);
|
||||||
else
|
else
|
||||||
r = ZERO;
|
r = ZERO;
|
||||||
} else if (_ix == 1)
|
}
|
||||||
|
else if (_ix == 1)
|
||||||
r = y;
|
r = y;
|
||||||
else
|
else
|
||||||
r = rb_funcall(x, '*', 1, y);
|
r = rb_funcall(x, '*', 1, y);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
r = rb_funcall(x, '*', 1, y);
|
r = rb_funcall(x, '*', 1, y);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -159,7 +166,8 @@ f_sub(VALUE x, VALUE y)
|
|||||||
r = x;
|
r = x;
|
||||||
else
|
else
|
||||||
r = rb_funcall(x, '-', 1, y);
|
r = rb_funcall(x, '-', 1, y);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
r = rb_funcall(x, '-', 1, y);
|
r = rb_funcall(x, '-', 1, y);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -635,7 +643,8 @@ f_addsub(VALUE self, VALUE anum, VALUE aden, VALUE bnum, VALUE bden, int k)
|
|||||||
num = f_idiv(c, g);
|
num = f_idiv(c, g);
|
||||||
a = f_idiv(bden, g);
|
a = f_idiv(bden, g);
|
||||||
den = f_mul(a, b);
|
den = f_mul(a, b);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
VALUE g = f_gcd(aden, bden);
|
VALUE g = f_gcd(aden, bden);
|
||||||
VALUE a = f_mul(anum, f_idiv(bden, g));
|
VALUE a = f_mul(anum, f_idiv(bden, g));
|
||||||
VALUE b = f_mul(bnum, f_idiv(aden, g));
|
VALUE b = f_mul(bnum, f_idiv(aden, g));
|
||||||
@ -739,7 +748,8 @@ f_muldiv(VALUE self, VALUE anum, VALUE aden, VALUE bnum, VALUE bden, int k)
|
|||||||
|
|
||||||
num = f_imul(an / g1, bn / g2);
|
num = f_imul(an / g1, bn / g2);
|
||||||
den = f_imul(ad / g2, bd / g1);
|
den = f_imul(ad / g2, bd / g1);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
VALUE g1 = f_gcd(anum, bden);
|
VALUE g1 = f_gcd(anum, bden);
|
||||||
VALUE g2 = f_gcd(aden, bnum);
|
VALUE g2 = f_gcd(aden, bnum);
|
||||||
|
|
||||||
@ -890,7 +900,8 @@ nurat_cmp(VALUE self, VALUE other)
|
|||||||
FIXNUM_P(bdat->num) && FIXNUM_P(bdat->den)) {
|
FIXNUM_P(bdat->num) && FIXNUM_P(bdat->den)) {
|
||||||
num1 = f_imul(FIX2LONG(adat->num), FIX2LONG(bdat->den));
|
num1 = f_imul(FIX2LONG(adat->num), FIX2LONG(bdat->den));
|
||||||
num2 = f_imul(FIX2LONG(bdat->num), FIX2LONG(adat->den));
|
num2 = f_imul(FIX2LONG(bdat->num), FIX2LONG(adat->den));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
num1 = f_mul(adat->num, bdat->den);
|
num1 = f_mul(adat->num, bdat->den);
|
||||||
num2 = f_mul(bdat->num, adat->den);
|
num2 = f_mul(bdat->num, adat->den);
|
||||||
}
|
}
|
||||||
@ -954,6 +965,7 @@ nurat_idiv(VALUE self, VALUE other)
|
|||||||
{
|
{
|
||||||
return f_floor(f_div(self, other));
|
return f_floor(f_div(self, other));
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
nurat_mod(VALUE self, VALUE other)
|
nurat_mod(VALUE self, VALUE other)
|
||||||
{
|
{
|
||||||
@ -1044,7 +1056,8 @@ nurat_round(VALUE self)
|
|||||||
num = f_add(f_mul(num, TWO), dat->den);
|
num = f_add(f_mul(num, TWO), dat->den);
|
||||||
den = f_mul(dat->den, TWO);
|
den = f_mul(dat->den, TWO);
|
||||||
return f_negate(f_idiv(num, den));
|
return f_negate(f_idiv(num, den));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
VALUE num = f_add(f_mul(dat->num, TWO), dat->den);
|
VALUE num = f_add(f_mul(dat->num, TWO), dat->den);
|
||||||
VALUE den = f_mul(dat->den, TWO);
|
VALUE den = f_mul(dat->den, TWO);
|
||||||
return f_idiv(num, den);
|
return f_idiv(num, den);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user