Issue #16894 has been updated by ankane (Andrew Kane).


fwiw, array indexing code likely wouldn't need changed.

``` ruby
a = ["zero", "one", "two"]
a[1/2]   # "zero"
a[1/2.0] # "zero"
```

Some code would break, but we have major versions to account for this. It seems like a smaller change than keyword arguments (which I realize is being reconsidered).

mruby uses [float division](https://github.com/mruby/mruby/issues/1431), and other languages have made the change as jzakiya pointed out, so I don't think it's a crazy idea (even if Ruby decides not to do it).

`//` is the current syntax for regular expression, so I'm not sure that's an option. I personally don't think floor division is common enough to need an operator, but I realize others don't share that opinion.

----------------------------------------
Feature #16894: Integer division for Ruby 3
https://bugs.ruby-lang.org/issues/16894#change-85666

* Author: ankane (Andrew Kane)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
----------------------------------------
Hi Ruby team,

It'd be great if division in Ruby matched what we all learned in school.

``` ruby
1 / 2 == 0.5
```

New developers wouldn't immediately be confused when they try to do division and experienced developers could stop adding to_f to their code (typically after they get tripped up on the first run). In my experience, floating point division is way more common than floor division. This could definitely break existing code, so I understand it's a decision that shouldn't be made lightly. Overall, Ruby is really intuitive, but this is one place where it's not.

It looks like this was considered for Ruby 2.0 as well as few years ago in #5512, so feel free to close if it's not something you'd like to reconsider right now.

---Files--------------------------------
integer division.png (14.3 KB)


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