3 ms·
The simplest and best example in this presentation: (x * 2000) / 1000 can be reduced to x * 2 but only if we make some assumptions about x (about if x can ov
by petermcneeley 8y ago
The simplest and best example in this presentation:
(x * 2000) / 1000 can be reduced to x * 2 but only if we make some assumptions about x (about if x can overflow)
The reason why this is such a problem in C languages is because most of the time one is working in a mixed abstraction environment. The underlying model for many parts of the language is assembly. In order to get away from these issues and to produce more optional code we should move away from mixing models of abstraction.
- andromeduck 8y agoThe value of (X2000)/1000 will always depend on type. For example, this could result in overflows if it were a fixed point integral or loss of precision if it were a floating point type. X could be a non associative type with overloaded operators like a digest/summary type. IMO the wierdist thing to read in C++ though is X / A A. Its roughly the same as X -= X % A. They values may differ if X or A are negative.