Issue #16677 has been updated by Dan0042 (Daniel DeLorme).


It's actually a bit more complicated than that.

```ruby
-2.to_i ** 2.2 #=> (3.717265962412589+2.7007518095995264i)
x = 2
-x.to_i ** 2.2 #=> -4.59479341998814
```

So it looks like there's something special about how negative integers are parsed? I'm not really sure how to describe the above behavior.

----------------------------------------
Bug #16677: Negative integer powered (**) to a float number results in a complex 
https://bugs.ruby-lang.org/issues/16677#change-84534

* Author: CamilleDrapier (Camille Drapier)
* Status: Closed
* Priority: Normal
* ruby -v: 2.5.7, 2.6.5, 2.7.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
Not sure if my understanding is wrong or if this is an unexpected behavior.

This seems to be working as I expect it would:

```
-2 ** 2.2
=> -4.59479341998814
```

But when changing a bit the code, for something that seemingly shouldn't have that big an impact, it gives me a complex:

```
-2.to_i ** 2.2
=> (3.717265962412589+2.7007518095995273i)
```

Also, this seems to behave the same way:
```
a = -2; a ** 2.2
=> (3.717265962412589+2.7007518095995273i)
```

This seems to only be happening with negative numbers and float powers. I think it might be related to how Fixnum are treated separately when applying the power function, but I did not dig further.
Sorry if this is an intended behavior and I did simply not understand it was!

Thank you!



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>