C11 committee draft N1570 Created 2026-10-24 Updated 2026-11-05
The 12 April 2011 committee draft specifies C integer division in section 6.5.5, especially paragraphs 5–6 and footnote 105. It fixes the truncation and quotient–remainder relationship used when verifying signed power-of-two division by biasing.
Additional verified locator: section6.7.2.1, paragraphs10–11, printed p114. Bit-field width and signed/unsigned interpretation; implementation-defined allocation order within a storage unit and unspecified alignment of that storage unit. Used to distinguish a language declaration from a portable external bit/byte encoding.
Additional verified locator: sections 7.22.3.3–7.22.3.4, printed pp. 348–349. The free function deallocates storage for subsequent allocation; invalid or already-deallocated pointers give undefined behavior. The malloc function allocates an object of the requested size with an indeterminate initial value and returns a null pointer on failure. Section 6.2.4 distinguishes storage durations.
Use the same bias, then an arithmetic right shift by ten:
div1024:
    asrs r3, r0, #31    // -1 when a<0, otherwise 0
    lsrs r3, r3, #22    // b = 1023 when a<0, otherwise 0
    adds r0, r0, r3     // a+b, representable for every signed input
    asrs r0, r0, #10    // floor((a+b)/1024)
    bx lr
An arithmetic right shift of a two's complement integer computes division rounded down. For , this already equals truncation towards zero. For , the signed power-of-two division by biasing identity is
Indeed, writing with makes the adjusted numerator ; its quotient rounded down is for every , including zero. Thus the code returns the signed quotient in all cases and contains no data-dependent branch. The final bx lr simply returns to the caller.