Описание тега floating-point-exceptions
Mathematical operations involving floating point numbers can result in undefined or non-arithmetic values. Common invalid operations encountered include "divide by zero", which results in a mathematical 'Inf', or 0/0, which resutls in a Not-a-Number (NaN). Other invalid operations in overflow, underflow and loss of precision due to rounding.
Propagation of invalid values
Many scientific software codes rely heavily on floating point operations, and so determining the origin of these floating point exceptions can be a painstaking task. The problem for the programmer is that these invalid values can propagate through the code according to extended arithmetic rules for these values. A NaN plus any number is always a NaN. Inf + 1 is still Inf.
Trapping invalid values
Most compilers allow for this propagation. The programmer may only realize something has gone wrong when the output is filled with NaNs or Infs, long after the first invalid operation occurred.
Often, the programmer would rather trap these errors on their first occurrence. To trap these "floating-point-exceptions", one must enable certain compiler or software options. For example, in fortran, compiler flags automatically trap the first occurrence of invalid operations. In C/C++, routines available in may be used to signal to the underlying hardware the occurrence of chosen exceptions should halt execution of the program, or take some other programmer-specified action.