Issue #17318 has been updated by deXterbed (Manoj Mishra).


mame (Yusuke Endoh) wrote in #note-2:
> It is due to precedence of operators unary minus and `**`.
> 
> `x**y` calculates `(-0.4790529833050308)**0.9918032786885246`, and `-0.4790529833050308**0.9918032786885246` calculates `-(0.4790529833050308**0.9918032786885246)`.
> 
> ```
> irb(main):001:0> -(0.4790529833050308**0.9918032786885246)
> => -0.4819515219418196
> irb(main):002:0> (-0.4790529833050308)**0.9918032786885246
> => (-0.48179173935576963+0.012409246172848266i)
> ```

Thanks for the explanation Yusuke Endoh,

that still raises the question, how exactly am i supposed to calculate x**y without ending up with a complex number? x and y are dynamic values, i can't use parentheses to force precedence. 


----------------------------------------
Bug #17318: Raising float to the power of other issue
https://bugs.ruby-lang.org/issues/17318#change-88472

* Author: deXterbed (Manoj Mishra)
* Status: Rejected
* Priority: Normal
* ruby -v: 2.6.3
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
Raising a negative float to another float results in a complex number. Interestingly, doing the same thing without using variables works fine!

Sample Snippet:

$ irb
2.6.3 :001 > x=-0.4790529833050308
 => -0.4790529833050308
2.6.3 :002 > y=0.9918032786885246
 => 0.9918032786885246
2.6.3 :003 > x**y
 => (-0.48179173935576963+0.012409246172848264i)
2.6.3 :004 > -0.4790529833050308**0.9918032786885246
 => -0.4819515219418196



-- 
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>