[#97536] [Ruby master Bug#16694] JIT vs hardened GCC with PCH — v.ondruch@...
Issue #16694 has been reported by vo.x (Vit Ondruch).
11 messages
2020/03/18
[ruby-core:97463] [Ruby master Bug#16677] Negative integer powered (**) to a float number results in a complex
From:
sawadatsuyoshi@...
Date:
2020-03-12 21:00:44 UTC
List:
ruby-core #97463
Issue #16677 has been updated by sawa (Tsuyoshi Sawada). I think the issue is this: `**` has higher precedence than `-` adjacent to a numerical, ```ruby -2 ** 2 # => -4 (-2) ** 2 # => 4 -(2 ** 2) # => -4 ``` and `-` adjacent to a numerical has higher precedence than a typical method call (i.e., one that uses a period `.`): ```ruby -2.2.ceil # => -2 (-2.2).ceil # => -2 -(2.2.ceil) # => -3 ``` Our intuition suggests that precedence relation should be transitive. If that were the case, then `**` should have higher precedence than `-` and a method call (although the latter does not make sense because a non-applied method cannot be combined with `**` excluding its receiver; see below). However, when both `-` adjacent to a numerical and a method call appear together, `**` has lower precedence than either: ```ruby -2.itself ** 2 # => 4 ((-2).itself) ** 2 # => 4 -(2.itself ** 2) # => -4 ``` So, a natural suggestion might be to let `**` have higher precedence than `-` even when there is an intervening method as follows: ```ruby -2.itself ** 2 # => -(2.itself ** 2) # => -4 ``` ---------------------------------------- Bug #16677: Negative integer powered (**) to a float number results in a complex https://bugs.ruby-lang.org/issues/16677#change-84607 * Author: CamilleDrapier (Camille Drapier) * Status: Open * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * ruby -v: 2.5.7, 2.6.5, 2.7.0 * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- Not sure if this is an unexpected behavior. This works as I expect: ``` -2 ** 2.2 # => -4.59479341998814 ``` But when I change the code a bit, it gives me a complex: ```ruby -2.to_i ** 2.2 # => (3.717265962412589+2.7007518095995273i) a = -2; a ** 2.2 # => (3.717265962412589+2.7007518095995273i) ``` This seems to happen only with negative numbers and float powers. I think it might be related to how `Fixnum` is treated differently from other classes by the power function. -- 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>