Project

General

Profile

Actions

Feature #14924

closed

// floor division operator

Added by Anonymous about 4 years ago. Updated about 4 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:88018]

Description

Hello!

In my job, I have to do many math operations. And it's kind of a pain because of integer division (3 / 2 == 1). I have to constantly cast integers to floats.

Would it be a good idea to always return a float when you divide two numbers? I mean, 99% of the time you just want that. (The principle of least surprise.)

Python is doing that just right:

3 / 2 == 1.5
3 // 2 == 1

http://python-reference.readthedocs.io/en/latest/docs/operators/floor_division.html

I don't know if it's too much of a breaking change though? Maybe for Ruby3x3?

Thanks.

Actions

Also available in: Atom PDF