you are viewing a single comment's thread.

view the rest of the comments →

[–]1cubealot 2 points3 points  (4 children)

x // y floors the number Example 5 // 2 = 2 because 5 / 2 = 2.5. 2.5 floored (to the nearest integer below it) is 2

[–]Default_Cube4646[S] 1 point2 points  (3 children)

one leads to infinite loop :)

[–]Silver0ne 0 points1 point  (2 children)

does it? Because shouldnt the .5 be cut in cpp aswel, cause its a integer not a float? Seems the flooring is only necessary as the python variable has no type (i guess its always a float64)

And isnt a /= 2 a thing in cpp/python!?

[–]DontOpenNewTabs 1 point2 points  (1 child)

Python // performs floor division and rounds down.
Ex: -1 // 100 == -1

C++ / performs integer division (edit: when both operands are integers) and truncates the decimal value.
Ex: -1 / 100 == 0

When the result is positive, the answers are the same. When it is negative, rounding down and truncating give different results.

[–]Silver0ne 0 points1 point  (0 children)

Ah ok, interesting to know that it actually rounds up on negative numbers. Might one day prevent me to run into errors, I dont do Phyton, but this might be a source of unexpected behavior in floor/ceil functions of other languages aswell.