What are the situations in which errors from the underflow_error class underflow_error ?

  • reset error; mistake due to loss of significance - titov_andrei
  • @titov_andrei could you give some code examples? - vadim666
  • if the answer was helpful, vote for him - titov_andrei

2 answers 2

 void CheckNumericLimitForAddition(int source , int summand) { if ((source > (source + summand))) { throw overflow_error(MESSAGE_OVERFLOW); } else if ((source < (source + summand))) { throw underflow_error(MESSAGE_UNDERFLOW); } } 
  • In the second condition, else if ((source < (source + summand))) , apparently, it was implied - ? - Monah Tuk

Here it is not clear what exactly is meant in the question.

If - what is the loss of significance, then this is one thing (when, say, adding a small number to a large number does not change the value of this large number).

But the question can be understood in the same way - when exactly is the underflow_error exception underflow_error ? And here the answer is completely different - the standard C ++ library does not generate it . Others can, for example, boost::math , your code can. But the standard library - no, disdain :)