From: Thibault Jouan Date: 2018-07-22T18:35:13+00:00 Subject: [ruby-core:88047] Re: [Ruby trunk Feature#14924] // floor division operator > Out of curiosity what are you doing that needs integer division? :) For example in my window manager I have some rules to determine how windows should be sized and positioned (tiling). ~~~ ruby # how many windows with 484px width would fit in a given screen? windows_count = screen.width / 484 # what height to use for multiple windows in a "column"? window_height = column.height / column.windows.size ~~~ (this is not my actual code, I changed it slightly for clarity) In another case, I wanted to overlay some CSV values from telemetry data on videos. My values are within -1024..1024, and I want to overlay a "bar chart" that is 720px high for example, so I had code similar to this: ~~~ ruby (telemetry_value + 1024) * 720 / 2048 ~~~ Last example, I use ruby to generate "templates" for my keyboards (to draw and cut holes for switches/keys). I was worried about Float approximation (maybe wrongly), and preferred to calculate everything with integers representing 1/10 millimeter (the most precise measurement I work with is only 0.5�mm). ~~~ ruby class Key < Struct.new :x, :y, :u, :direction def urect Rect.new( x * U + CASE_PADDING[3], y * U + CASE_PADDING[0], U * (direction == :horizontal ? u : 1), U * (direction == :vertical ? u : 1), :blue ) end def switch cx, cy = urect.center Rect.new( cx - SWITCH_SIZE / 2, cy - SWITCH_SIZE / 2, SWITCH_SIZE, SWITCH_SIZE, :red ) end end class Rect < Struct.new :x, :y, :width, :height, :color def center [x + (width / 2), y + (height / 2)] end end ~~~ (https://raw.githubusercontent.com/tjouan/keyboards/master/lib/keyboards/layout.rb for the rest of the code, sorry for ugliness and that github is the only place I have it public for now) So in most cases, it was about coordinates�: I can't split a pixel for example. But I also remember using integer division at work for financial amounts, I cannot split a "cent" either and can't rely on approximations in such case. > Still I think that 99% of people expect that when you divide 3 / 2 you get 1.5 (it's like that in every calculators in the world). > > 3 / 2 == 1 is against the principle of least surprise, but hey I understand that we can't change that anymore in Ruby. :) Yes I have exaggerated in saying the opposite, sorry�:-) I understand that for math and scientific usage it's very different. My background is mostly C and Ruby, and my "calculator" is almost always `bc' program so I might be biased here. -- Thibault Jouan Unsubscribe: