mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
complex.c: small optimization of Complex#**
* complex.c (rb_complex_pow): calculate power of a Fixnum without allocating intermediate Complex objects, and avoid unexpected NaNs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c561284bc2
commit
b4bbfe4bb9
5 changed files with 79 additions and 44 deletions
16
numeric.c
16
numeric.c
|
@ -4077,6 +4077,22 @@ rb_int_pow(VALUE x, VALUE y)
|
|||
return Qnil;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_num_pow(VALUE x, VALUE y)
|
||||
{
|
||||
VALUE z = rb_int_pow(x, y);
|
||||
if (!NIL_P(z)) return z;
|
||||
if (RB_FLOAT_TYPE_P(x)) return rb_float_pow(x, y);
|
||||
if (SPECIAL_CONST_P(x)) return Qnil;
|
||||
switch (BUILTIN_TYPE(x)) {
|
||||
case T_COMPLEX:
|
||||
return rb_complex_pow(x, y);
|
||||
case T_RATIONAL:
|
||||
return rb_rational_pow(x, y);
|
||||
}
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
/*
|
||||
* Document-method: Integer#==
|
||||
* Document-method: Integer#===
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue