| Цитата | If during the evaluation of an expression, the result is not mathematically defined or not in the range of representable values for its type, the behavior is undefined, unless such an expression is a constant expression (5.19), in which case the program is illformed. [Note: most existing implementations of C++ ignore integer overflows. Treatment of division by zero, forming a remainder using a zero divisor, and all floating point exceptions vary among machines, and is usually adjustable by a library function. ]
|
Проверяй сам, если надо бросай исключение.
Цитата(w1zard350 @ 7.3.2010, 11:36 ) | | Я просто не могу проверять конкретно функцию, знаменатель. Функцию вводит юзер с клавиатуры. |
Проверять можно всегда, с этим просто не может возникнуть проблем. В крайнем случае можно написать функцию для деления.
| Код | template <typename T> T div(T a, T b) { if (b == 0) throw std::runtime_error("division by zero"); return a / b; }
|
что-то вроде этого. |