Project

General

Profile

Actions

Bug #13152

closed

Numeric parsing differences between ruby <-> crystal

Added by jzakiya (Jabari Zakiya) over 4 years ago. Updated over 1 year ago.

Status:
Rejected
Priority:
Normal
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

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

Also available in: Atom PDF