# Return to Answer

 2 Fixed error edited Feb 11 '14 at 10:12 david.pfx 7,46811 gold badge1515 silver badges4141 bronze badges The hardware of all modern computers is sufficiently powerful to implement mod operations of either sign with no (or trivial) performance impact. This is not the reason. The common expectation of most computer languages is that (a div b) * b + (a mod b) = a. In other words, div and mod considered together divide a number into parts that can reliably be put back together again. This requirement is explicit in the C++ standard. The concept is closely related to indexing of multi-dimensional arrays. I have used it often. From this it can be seen that div and mod will preserve the sign of a if b is positive (as it usually is). Some languages provide a related 'rem()' function that is usually abs(mod())related to mod and has some other mathematical justification. I have never needed to use this. See for example frem() in Gnu C. [edited] The hardware of all modern computers is sufficiently powerful to implement mod operations of either sign with no (or trivial) performance impact. This is not the reason. The common expectation of most computer languages is that (a div b) * b + (a mod b) = a. In other words, div and mod considered together divide a number into parts that can reliably be put back together again. This requirement is explicit in the C++ standard. The concept is closely related to indexing of multi-dimensional arrays. I have used it often. From this it can be seen that div and mod will preserve the sign of a if b is positive (as it usually is). Some languages provide a related 'rem()' function that is usually abs(mod()). I have never needed to use this. The hardware of all modern computers is sufficiently powerful to implement mod operations of either sign with no (or trivial) performance impact. This is not the reason. The common expectation of most computer languages is that (a div b) * b + (a mod b) = a. In other words, div and mod considered together divide a number into parts that can reliably be put back together again. This requirement is explicit in the C++ standard. The concept is closely related to indexing of multi-dimensional arrays. I have used it often. From this it can be seen that div and mod will preserve the sign of a if b is positive (as it usually is). Some languages provide a 'rem()' function that is related to mod and has some other mathematical justification. I have never needed to use this. See for example frem() in Gnu C. [edited] 1 answered Feb 10 '14 at 14:05 david.pfx 7,46811 gold badge1515 silver badges4141 bronze badges The hardware of all modern computers is sufficiently powerful to implement mod operations of either sign with no (or trivial) performance impact. This is not the reason. The common expectation of most computer languages is that (a div b) * b + (a mod b) = a. In other words, div and mod considered together divide a number into parts that can reliably be put back together again. This requirement is explicit in the C++ standard. The concept is closely related to indexing of multi-dimensional arrays. I have used it often. From this it can be seen that div and mod will preserve the sign of a if b is positive (as it usually is). Some languages provide a related 'rem()' function that is usually abs(mod()). I have never needed to use this.