Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 10
    Summary: signed integer division truncates towards zero. For non-negative results, this is the same as floor (round towards -Infinity). (Beware that C89 doesn't guarantee this, see answers.) Commented Nov 7, 2017 at 4:19
  • 72
    Everyone keeps saying "truncate toward zero" or "ceiling" or "floor" like the code is making a deliberate decision on which technique to use. If the code could talk it would say "I just throw the dam fraction part in the trash and move on with life" Commented Oct 8, 2018 at 3:09
  • 10
    @TimothyL.J.Stewart The "code" is making a deliberate decision. As per the specification, integer division is meant to be T(runcation)-division. Because of this, the modulo/remainder operator is implented differently than if it were in another language, say, Python or Ruby. See this for a list of different ways languages do the modulo operator and this paper that lists out at least five of the common ways programming languages decide to do div/modulo. Commented Oct 23, 2018 at 21:22
  • 11
    @13steinj I'm speaking colloquially per the comments it was turning into a "it's truncate toward zero... no it's floor... no if its negative its ceiling..." sometimes technicalities do not propagate into the future with human memory like we wish, but knowing intuitively that the "fraction part is tossed away" you can derive the technical points. Technicalities are a heavy burden, but intuition is light and refreshing as the wind, I'll carry those far and wide and when necessary I'll know where to start. Like that paper you linked, thank you. Commented Oct 24, 2018 at 0:50
  • I answered here with the emphasis on the Euclidean division (inter-play between integer division and modulus operator). Commented May 18, 2019 at 17:25