История изменений
Исправление asaw, (текущая версия) :
Я не знаю что тебя так возмущает, но все релевантные цитаты уже преведены. Первую привёл ТС в самом начале, вторую можно суммировать вот так:
Overflows
Unsigned integer arithmetic is always performed modulo 2^n where n is the number of bits in that particular integer. E.g. for unsigned int, adding one to UINT_MAX gives 0, and subtracting one from 0 gives UINT_MAX.
When signed integer arithmetic operation overflows (the result does not fit in the result type), the behavior is undefined: it may wrap around according to the rules of the representation (typically 2's complement), it may trap on some platforms or due to compiler options (e.g. -ftrapv in GCC and Clang), or may be completely optimized out by the compiler.
И при этом не всем всё очевидно. Значит нужно писать std::numeric_limits<unsigned long long>::max(); и т.д.
Исправление asaw, :
Я не знаю что тебя так возмущает, но все релевантные цитаты уже преведены. Первую привёл ТС в самом начале, вторую можно суммировать вот так:
Overflows
Unsigned integer arithmetic is always performed modulo 2n where n is the number of bits in that particular integer. E.g. for unsigned int, adding one to UINT_MAX gives 0, and subtracting one from 0 gives UINT_MAX.
When signed integer arithmetic operation overflows (the result does not fit in the result type), the behavior is undefined: it may wrap around according to the rules of the representation (typically 2's complement), it may trap on some platforms or due to compiler options (e.g. -ftrapv in GCC and Clang), or may be completely optimized out by the compiler.
И при этом не всем всё очевидно. Значит нужно писать std::numeric_limits<unsigned long long>::max(); и т.д.
Исходная версия asaw, :
Я не знаю что тебя так возмущает, но все релевантные цитаты уже преведены. Первую привёл ТС в самом начале, вторую можно суммировать вот так:
Overflows
Unsigned integer arithmetic is always performed modulo 2n where n is the number of bits in that particular integer. E.g. for unsigned int, adding one to UINT_MAX gives 0, and subtracting one from 0 gives UINT_MAX. When signed integer arithmetic operation overflows (the result does not fit in the result type), the behavior is undefined: it may wrap around according to the rules of the representation (typically 2's complement), it may trap on some platforms or due to compiler options (e.g. -ftrapv in GCC and Clang), or may be completely optimized out by the compiler.
Unsigned integer arithmetic is always performed modulo 2n where n is the number of bits in that particular integer. E.g. for unsigned int, adding one to UINT_MAX gives 0, and subtracting one from 0 gives UINT_MAX. When signed integer arithmetic operation overflows (the result does not fit in the result type), the behavior is undefined: it may wrap around according to the rules of the representation (typically 2's complement), it may trap on some platforms or due to compiler options (e.g. -ftrapv in GCC and Clang), or may be completely optimized out by the compiler.
И при этом не всем всё очевидно. Значит нужно писать std::numeric_limits<unsigned long long>::max(); и т.д.