Closed alexey-malov closed 6 years ago
unsigned int GetSum(const unsigned int a, const unsigned b)
{
if (a >= numeric_limits<unsigned int>::max() - b)
{
throw overflow_error("Input number overflow");
return 0;
}
// Будет ли переполнение при умножении беззнаковых чисел а и b
if (a == 0 || (std::numeric_limits<unsigned>::max() / a >= b))
{
// a * b не вызовет переполнения
}
else
{
// переполнение
}
При входном числе FFFFFFFF (4294967295) программа выдаст ошибку, т.к. numeric_limits
if (str.length() <= 0)
{
wasError = true;
return 0;
}
unsigned int GetMul(const unsigned int a, const unsigned b)
{
if (a == 0 || ((numeric_limits<unsigned int>::max() / b + 1) > a))
[x] Если b == 1
, программа неверно отрепортит переполнение. +1 - это костыль.
[x] Должен быть тест на преобразование максимального числа
unsigned int currentDischargeNumber = LetterToNumber(str[i]);
return InInterval(letter, '0', '9') ? static_cast<int>(letter - '0') : static_cast<int>(letter) - 55;
const char AMinus10 = 'A' - 10;
unsigned int currentDischargeNumber = LetterToNumber(str[i]);
if (currentDischargeNumber > radix)
{
wasError = true;
return 0;
}
bool ValidStringNumber(string number)
{
try
{
int tempNumber = stoi(number);
}
catch (const exception& e)
{
return false;
}
}