Project

General

Profile

Actions

Bug #16677

closed

Negative integer powered (**) to a float number results in a complex

Added by CamilleDrapier (Camille Drapier) over 4 years ago. Updated over 4 years ago.

Status:
Closed
Target version:
-
ruby -v:
2.5.7, 2.6.5, 2.7.0
[ruby-core:97390]

Description

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:

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


Related issues 2 (0 open2 closed)

Is duplicate of Ruby master - Bug #13152: Numeric parsing differences between ruby <-> crystalRejectedActions
Has duplicate Ruby master - Bug #18188: -1 ** 0 is 1 not -1RejectedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0