Issue #16677 has been updated by CamilleDrapier (Camille Drapier).


Oh sorry, I just notice that this is an expected behaviour in the documentation (example) given in Integer.

I guess the to-i attribute assignment is a bit confusing that it changes the behaviour but probably not a bug!

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

* Author: CamilleDrapier (Camille Drapier)
* Status: Open
* 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>