div() filled pre-C99 need: portability
Pre C99 , the direction of rounding of the factor a / b with the negative operand is implementation dependent. With div() , the rounding direction is not optional, but indicated as 0. div() provided that the figurative division is uniform. The secondary use was potential efficiency, when the code had to calculate both the factor and the remainder.
With C99 and later versions of div() and / defining the same circular direction, and with better compilers optimizing the adjacent codes a/b and a%b , the need is reduced.
This was a good reason for div() , and this explains the lack of udiv_t udiv(unsigned numer, unsigned denom) in the C specification: problems with implementation-dependent a/b results with negative operands do not exist for unsigned even in pre -C99.
chux Sep 08 '14 at 22:39 2014-09-08 22:39
source share