When developing applications, you may need to control the exceptions that can occur during the run-time processing of floating-point numbers. These exceptions can be categorized into specific types: overflow, divide-by-zero, underflow, and invalid operations.
Overflow
Overflow is signaled whenever the destination format’s largest finite number is exceeded in magnitude by what would have been the rounded floating-point result. The result computed is rounding mode specific:
Round-to-nearest (default): +/- Infinity in specified precision
Round-to-zero: +/- Maximum Number in specified precision
Round-to-+Infinity: +Infinity or –(Maximum Positive Number) in specified precision
Round-to--Infinity: (Maximum Positive Number) or -Infinity in specified precision
For example, in round-to-nearest mode 1E30 * 1E30 overflows the single-precision floating-point range and results in a +Infinity; -1E30 * 1E30 results in a -Infinity.
Divide-by-zero
Divide-by-zero is signaled when the divisor is zero and the dividend
is a finite nonzero number. The computed result is a correctly signed
Infinity.
For example, 2.0E0/+0.0 produces a divide-by-zero exception and results
in a +Infinity; -2.0E0/+0.0 produces a divide-by-zero exception and results
in a –Infinity.
Underflow
Underflow occurs when a computed result (of an add, subtract, multiply, divide, or math function call) falls beyond the minimum range in magnitude of normalized numbers of the floating-point data type. Each floating-point type (32-, 64-, and 128-bit) has a denormalized range where very small numbers can be represented with some loss of precision. This is called gradual underflow. For example, the lower bound for normalized single-precision floating-point is approximately 1E-38, while the lower bound for denormalized single-precision floating-point is approximately 1E-45. Results falling below the lower bound of the denormalized range simply become zero. 1E-30 / 1E10 underflows the normalized range but not the denormalized range so the result is the denormal value 1E-40. 1E-30 / 1E30 underflows the entire range and the result is zero.
Invalid operation
Invalid occurs when operands to the basic floating-point operations or math function inputs produce an undefined (QNaN) result. Some examples include:
SNaN operand in any floating-point operation or math function call
Division of zeroes: (+/-0.0)/(+/-0.0)
Sum of Infinities having different signs: Infinity + (-Infinity)
Difference of Infinities having the same sign: (+/-Infinity) – (+/-Infinity
Product of signed Infinities with zero: (+/-Inf) * 0
Math Function Domain Errors: log(negative), sqrt(negative), asin(|x}>1)
With the Intel® Compiler, you can use the -fpe (Linux* and Mac OS*) or /fpe (Windows*) option to control floating-point exceptions.