1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* complex.c: added two macros.

* rational.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19446 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tadf 2008-09-21 12:21:32 +00:00
parent a46544a4f9
commit cbae6d0911
3 changed files with 20 additions and 6 deletions

View file

@ -1,3 +1,9 @@
Sun Sep 21 21:20:24 2008 Tadayoshi Funaba <tadf@dotrb.org>
* complex.c: added two macros.
* rational.c: ditto.
Sun Sep 21 18:06:38 2008 Tadayoshi Funaba <tadf@dotrb.org>
* complex.c (nucomp_s_convert): checks argc.

View file

@ -195,6 +195,8 @@ f_negative_p(VALUE x)
return rb_funcall(x, '<', 1, ZERO);
}
#define f_positive_p(x) (!f_negative_p(x))
inline static VALUE
f_zero_p(VALUE x)
{
@ -203,6 +205,8 @@ f_zero_p(VALUE x)
return rb_funcall(x, id_equal_p, 1, ZERO);
}
#define f_nonzero_p(x) (!f_zero_p(x))
inline static VALUE
f_one_p(VALUE x)
{
@ -487,7 +491,7 @@ static VALUE
m_sqrt(VALUE x)
{
if (f_real_p(x)) {
if (!f_negative_p(x))
if (f_positive_p(x))
return m_sqrt_bang(x);
return f_complex_new2(rb_cComplex, ZERO, m_sqrt_bang(f_negate(x)));
}
@ -1326,7 +1330,7 @@ numeric_abs2(VALUE self)
static VALUE
numeric_arg(VALUE self)
{
if (!f_negative_p(self))
if (f_positive_p(self))
return INT2FIX(0);
return rb_const_get(rb_mMath, id_PI);
}

View file

@ -167,6 +167,8 @@ f_negative_p(VALUE x)
return rb_funcall(x, '<', 1, ZERO);
}
#define f_positive_p(x) (!f_negative_p(x))
inline static VALUE
f_zero_p(VALUE x)
{
@ -175,6 +177,8 @@ f_zero_p(VALUE x)
return rb_funcall(x, id_equal_p, 1, ZERO);
}
#define f_nonzero_p(x) (!f_zero_p(x))
inline static VALUE
f_one_p(VALUE x)
{
@ -280,7 +284,7 @@ inline static VALUE
f_gcd(VALUE x, VALUE y)
{
VALUE r = f_gcd_orig(x, y);
if (!f_zero_p(r)) {
if (f_nonzero_p(r)) {
assert(f_zero_p(f_mod(x, r)));
assert(f_zero_p(f_mod(y, r)));
}
@ -366,8 +370,8 @@ f_rational_new_bang1(VALUE klass, VALUE x)
inline static VALUE
f_rational_new_bang2(VALUE klass, VALUE x, VALUE y)
{
assert(!f_negative_p(y));
assert(!f_zero_p(y));
assert(f_positive_p(y));
assert(f_nonzero_p(y));
return nurat_s_new_internal(klass, x, y);
}
@ -955,7 +959,7 @@ nurat_quotrem(VALUE self, VALUE other)
static VALUE
nurat_abs(VALUE self)
{
if (!f_negative_p(self))
if (f_positive_p(self))
return self;
return f_negate(self);
}