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

* numeric.c (fix_divide): added an entry to rational.

* rational.c (rb_rational_reciprocal): added.

	* complex.c (f_reciprocal): added.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24035 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tadf 2009-07-12 11:46:40 +00:00
parent 17c1e45405
commit fff1183ffe
4 changed files with 28 additions and 1 deletions

View file

@ -1,3 +1,11 @@
Sun Jul 12 20:42:58 2009 Tadayoshi Funaba <tadf@dotrb.org>
* numeric.c (fix_divide): added an entry to rational.
* rational.c (rb_rational_reciprocal): added.
* complex.c (f_reciprocal): added.
Sun Jul 12 02:24:42 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* random.c (rand_init): use fixed buffer for small numbers.

View file

@ -812,6 +812,12 @@ rb_fexpt(VALUE x, VALUE y)
return m_exp(f_mul(m_log(x), y));
}
inline static VALUE
f_reciprocal(VALUE x)
{
return f_quo(ONE, x);
}
/*
* call-seq:
* cmp ** numeric -> complex
@ -879,7 +885,7 @@ nucomp_expt(VALUE self, VALUE other)
}
return z;
}
return f_expt(f_div(f_to_r(ONE), self), f_negate(other));
return f_expt(f_reciprocal(self), f_negate(other));
}
if (k_numeric_p(other) && f_real_p(other)) {
VALUE r, theta;

View file

@ -2268,6 +2268,8 @@ fix_fdiv(VALUE x, VALUE y)
}
}
VALUE rb_rational_reciprocal(VALUE x);
static VALUE
fix_divide(VALUE x, VALUE y, ID op)
{
@ -2295,6 +2297,10 @@ fix_divide(VALUE x, VALUE y, ID op)
return rb_dbl2big(floor(div));
}
}
case T_RATIONAL:
if (op == '/' && FIX2LONG(x) == 1)
return rb_rational_reciprocal(y);
return rb_funcall(rb_rational_new1(x), op, 1, y);
default:
return rb_num_coerce_bin(x, y, op);
}

View file

@ -1428,6 +1428,13 @@ nurat_marshal_load(VALUE self, VALUE a)
/* --- */
VALUE
rb_rational_reciprocal(VALUE x)
{
get_dat1(x);
return f_rational_new_no_reduce2(CLASS_OF(x), dat->den, dat->num);
}
/*
* call-seq:
* int.gcd(int2) -> integer