kozec / syncthing-gtk

GTK3 & python based GUI for Syncthing
GNU General Public License v2.0
1.3k stars 138 forks source link

Specify integer division explicitly #472

Closed dralley closed 6 years ago

dralley commented 6 years ago

Python 2's division operator behaves differently depending on the type of the operands. If both operands are integer types, it will perform an 'integer division', whereas if one or both operands are a floating point type it will perform a 'true division'.

e.g. In Python 2:

5 / 2 == 2
5 / 2.0 == 2.5

In Python 3, the division operator always performs a 'true division', and the result will always be a floating point type regardless of the input types.

e.g. In Python 3:

5 / 2 == 2.5
5 / 2.0 == 2.5

Both Python 2 and Python 3 allow the // operator, which always performs floor (integer) division.

e.g. For both Python 2 and Python 3:

5 // 2 == 2
5 // 2.0 == 2.0

In places where both the operands are/should be integers, let's use // instead of /. In Python 2, it will behave the same for these operations as /, but is more explicit.

When changing this it appeared that for the majority of division operations, you had already made at least one operand a float in order to get the "true division" behavior. So there were very few places where this needed to be changed.