* complex.c (nucomp_expt): convert to a float when the given power
is a bignum. * rational.c (nurat_expt): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23883 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
faea8893f8
commit
268432c51d
@ -1,3 +1,10 @@
|
|||||||
|
Sun Jun 28 22:25:07 2009 Tadayoshi Funaba <tadf@dotrb.org>
|
||||||
|
|
||||||
|
* complex.c (nucomp_expt): convert to a float when the given power
|
||||||
|
is a bignum.
|
||||||
|
|
||||||
|
* rational.c (nurat_expt): ditto.
|
||||||
|
|
||||||
Sun Jun 28 21:16:48 2009 Tadayoshi Funaba <tadf@dotrb.org>
|
Sun Jun 28 21:16:48 2009 Tadayoshi Funaba <tadf@dotrb.org>
|
||||||
|
|
||||||
* lib/cmath.rb (sqrt): fixed an issue [ruby-list:45852].
|
* lib/cmath.rb (sqrt): fixed an issue [ruby-list:45852].
|
||||||
|
19
complex.c
19
complex.c
@ -226,6 +226,18 @@ k_integer_p(VALUE x)
|
|||||||
return f_kind_of_p(x, rb_cInteger);
|
return f_kind_of_p(x, rb_cInteger);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline static VALUE
|
||||||
|
k_fixnum_p(VALUE x)
|
||||||
|
{
|
||||||
|
return f_kind_of_p(x, rb_cFixnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static VALUE
|
||||||
|
k_bignum_p(VALUE x)
|
||||||
|
{
|
||||||
|
return f_kind_of_p(x, rb_cBignum);
|
||||||
|
}
|
||||||
|
|
||||||
inline static VALUE
|
inline static VALUE
|
||||||
k_float_p(VALUE x)
|
k_float_p(VALUE x)
|
||||||
{
|
{
|
||||||
@ -831,7 +843,7 @@ nucomp_expt(VALUE self, VALUE other)
|
|||||||
f_mul(dat->imag, m_log_bang(r)));
|
f_mul(dat->imag, m_log_bang(r)));
|
||||||
return f_complex_polar(CLASS_OF(self), nr, ntheta);
|
return f_complex_polar(CLASS_OF(self), nr, ntheta);
|
||||||
}
|
}
|
||||||
if (k_integer_p(other)) {
|
if (k_fixnum_p(other)) {
|
||||||
if (f_gt_p(other, ZERO)) {
|
if (f_gt_p(other, ZERO)) {
|
||||||
VALUE x, z, n;
|
VALUE x, z, n;
|
||||||
|
|
||||||
@ -862,9 +874,12 @@ nucomp_expt(VALUE self, VALUE other)
|
|||||||
if (k_numeric_p(other) && f_real_p(other)) {
|
if (k_numeric_p(other) && f_real_p(other)) {
|
||||||
VALUE r, theta;
|
VALUE r, theta;
|
||||||
|
|
||||||
|
if (k_bignum_p(other))
|
||||||
|
rb_warn("in a**b, b may be too big");
|
||||||
|
|
||||||
r = f_abs(self);
|
r = f_abs(self);
|
||||||
theta = f_arg(self);
|
theta = f_arg(self);
|
||||||
return f_complex_polar(CLASS_OF(self), f_expt(r, other),
|
return f_complex_polar(CLASS_OF(self), rb_fexpt(r, other),
|
||||||
f_mul(theta, other));
|
f_mul(theta, other));
|
||||||
}
|
}
|
||||||
return rb_num_coerce_bin(self, other, id_expt);
|
return rb_num_coerce_bin(self, other, id_expt);
|
||||||
|
@ -902,7 +902,6 @@ nurat_expt(VALUE self, VALUE other)
|
|||||||
|
|
||||||
switch (TYPE(other)) {
|
switch (TYPE(other)) {
|
||||||
case T_FIXNUM:
|
case T_FIXNUM:
|
||||||
case T_BIGNUM:
|
|
||||||
{
|
{
|
||||||
VALUE num, den;
|
VALUE num, den;
|
||||||
|
|
||||||
@ -924,6 +923,8 @@ nurat_expt(VALUE self, VALUE other)
|
|||||||
}
|
}
|
||||||
return f_rational_new2(CLASS_OF(self), num, den);
|
return f_rational_new2(CLASS_OF(self), num, den);
|
||||||
}
|
}
|
||||||
|
case T_BIGNUM:
|
||||||
|
rb_warn("in a**b, b may be too big");
|
||||||
case T_FLOAT:
|
case T_FLOAT:
|
||||||
case T_RATIONAL:
|
case T_RATIONAL:
|
||||||
return rb_fexpt(f_to_f(self), other);
|
return rb_fexpt(f_to_f(self), other);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user