From: sawadatsuyoshi@... Date: 2020-05-07T05:26:09+00:00 Subject: [ruby-core:98166] [Ruby master Bug#16677] Negative integer powered (**) to a float number results in a complex Issue #16677 has been updated by sawa (Tsuyoshi Sawada). matz (Yukihiro Matsumoto) wrote in #note-20: > @sawa Are you proposing something new? I couldn't read the concrete behavior proposed. My proposal (which I have suggested not so clearly in my previous comment) is this: ```ruby -2.itself # => -(2.itself) (change from current behavior) ``` From this, it follows that: ```ruby -2 ** 2.2 # => -(2 ** 2.2) (as is now) -2.to_i ** 2.2 # => -(2.to_i ** 2.2) (change from current behavior) -2.to_s # => frozen "2" (change from current behavior) ``` ---------------------------------------- Bug #16677: Negative integer powered (**) to a float number results in a complex https://bugs.ruby-lang.org/issues/16677#change-85405 * Author: CamilleDrapier (Camille Drapier) * Status: Closed * 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: