Integer operations are very frequent. The library should be very handy even in a complex expression like |
Integer operations are very frequent. The library should be very handy even for a complex expression like |
C and C++ don't guarantee mathematically correct semantic for integer arithmetic. It badly affects both languages because many developers write incorrect code without realizing it.
Integer operations are very frequent. The library should be very handy even for a complex expression like
size = prefix_len + n * sizeof(X) + 2 * suffix_len;One approach is to wrap Boost lambda expression into an object that controls every operation. For example, the earlier expression would become
bool const ok = is_mathematically_correct(_1 = _2 + _3 * sizeof(T) + 2 * _4)(size, prefix_len, n, suffix_len);The function is_mathematically_correct returns a lambda expression which is immediately evaluated and returns true if passed expression is mathematically correct, or false otherwise.
Note: although overflow is more common, it is incorrect because unsigned types never overflow.
The library should check the following
http://www.cert.org/secure-coding/IntegerLib.zip