mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
numeric.c: common expressions
* numeric.c (flo_pow): extract common expressions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52108 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
930595cd35
commit
5f0d9e8644
1 changed files with 10 additions and 9 deletions
15
numeric.c
15
numeric.c
|
@ -1073,24 +1073,25 @@ flo_divmod(VALUE x, VALUE y)
|
||||||
static VALUE
|
static VALUE
|
||||||
flo_pow(VALUE x, VALUE y)
|
flo_pow(VALUE x, VALUE y)
|
||||||
{
|
{
|
||||||
|
double dx, dy;
|
||||||
if (RB_TYPE_P(y, T_FIXNUM)) {
|
if (RB_TYPE_P(y, T_FIXNUM)) {
|
||||||
return DBL2NUM(pow(RFLOAT_VALUE(x), (double)FIX2LONG(y)));
|
dx = RFLOAT_VALUE(x);
|
||||||
|
dy = (double)FIX2LONG(y);
|
||||||
}
|
}
|
||||||
else if (RB_TYPE_P(y, T_BIGNUM)) {
|
else if (RB_TYPE_P(y, T_BIGNUM)) {
|
||||||
return DBL2NUM(pow(RFLOAT_VALUE(x), rb_big2dbl(y)));
|
dx = RFLOAT_VALUE(x);
|
||||||
|
dy = rb_big2dbl(y);
|
||||||
}
|
}
|
||||||
else if (RB_TYPE_P(y, T_FLOAT)) {
|
else if (RB_TYPE_P(y, T_FLOAT)) {
|
||||||
{
|
dx = RFLOAT_VALUE(x);
|
||||||
double dx = RFLOAT_VALUE(x);
|
dy = RFLOAT_VALUE(y);
|
||||||
double dy = RFLOAT_VALUE(y);
|
|
||||||
if (dx < 0 && dy != round(dy))
|
if (dx < 0 && dy != round(dy))
|
||||||
return rb_funcall(rb_complex_raw1(x), rb_intern("**"), 1, y);
|
return rb_funcall(rb_complex_raw1(x), rb_intern("**"), 1, y);
|
||||||
return DBL2NUM(pow(dx, dy));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return rb_num_coerce_bin(x, y, rb_intern("**"));
|
return rb_num_coerce_bin(x, y, rb_intern("**"));
|
||||||
}
|
}
|
||||||
|
return DBL2NUM(pow(dx, dy));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue