Project

General

Profile

Actions

Bug #13152

closed

Numeric parsing differences between ruby <-> crystal

Added by jzakiya (Jabari Zakiya) almost 8 years ago. Updated over 4 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:79226]

Description

I noticed this difference between ruby and crystal when converting a gem.

puts   -2**4 -> -16 (ruby) || 16 (crystal)
puts (-2)**4 ->  16 (both)

ruby parses -2**4 as -(2**4), while crystal does (-2)**4, which is more intuitive.
This creates need to be careful converting negative number usage from ruby <-> crystal.
(I haven't investigated differences with other languages.)
Using parentheses to explicitly create intended outcomes can overcome this.

However, on the heels of the discussion/decision to not change the default rounding behavior of numerics
in 2.4.0 would it also be worth it to change this parsing behavior to make this more natural
and intuitive, as in crystal?


Related issues 2 (0 open2 closed)

Has duplicate Ruby master - Bug #16677: Negative integer powered (**) to a float number results in a complex Closedmatz (Yukihiro Matsumoto)Actions
Has duplicate Ruby master - Bug #18188: -1 ** 0 is 1 not -1RejectedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0