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
19
numeric.c
19
numeric.c
|
@ -1073,24 +1073,25 @@ flo_divmod(VALUE x, VALUE y)
|
|||
static VALUE
|
||||
flo_pow(VALUE x, VALUE y)
|
||||
{
|
||||
double dx, dy;
|
||||
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)) {
|
||||
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)) {
|
||||
{
|
||||
double dx = RFLOAT_VALUE(x);
|
||||
double dy = RFLOAT_VALUE(y);
|
||||
if (dx < 0 && dy != round(dy))
|
||||
return rb_funcall(rb_complex_raw1(x), rb_intern("**"), 1, y);
|
||||
return DBL2NUM(pow(dx, dy));
|
||||
}
|
||||
dx = RFLOAT_VALUE(x);
|
||||
dy = RFLOAT_VALUE(y);
|
||||
if (dx < 0 && dy != round(dy))
|
||||
return rb_funcall(rb_complex_raw1(x), rb_intern("**"), 1, y);
|
||||
}
|
||||
else {
|
||||
return rb_num_coerce_bin(x, y, rb_intern("**"));
|
||||
}
|
||||
return DBL2NUM(pow(dx, dy));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Reference in a new issue