Does the C++ standard specify the behavior of floating point numbers during

"exceptional" (exceptional with respect to floating point numbers, not

exceptions) conditions?

For example:

double a = 1.0 / 0.0; // What is the value of a? Infinity?

double b = 0.0 / 0.0; // What is the value of b? NaN?

The behavior of both of the above is just plain undefined. There is

no requirement or specification of a value, there is none.

What about overflow/underflow conditions in the library? Is HUGE_VAL always a

defined constant?

HUGE_VAL is a required macro in <math.h>/<cmath>. It expands to a

positive double constant expression not necessarily representable in a

float. The intent is that it be the largest possible value that can

be held in a double, or a representation of positive infinity, if the

floating point type has such a representation.

#include <cmath>

using namespace std;

double c = pow(1e100, 1e100); // What is the value of c?

Assuming that the result is too large to be represented in a double,

his one should result in HUGE_VAL, and errno is set to ERANGE.

double d = pow(0.5, 1e100); // What is the value ef d?

Again assuming limitations on the range of a double, so that this

underflows to 0, the return will be 0.0, errno might or might not be

set to ERANGE.

But don't confuse library functions, which have fully defined

behavior, with overflow or underflow when using the build-in

arithmetic operators on any arithmetic type, be it floating point or

signed integer types. The latter has just plain undefined behavior.

Division by 0, even with unsigned integer types, is also undefined

behavior.

None of the <math.h>/<cmath> functions are allowed to produce

undefined behavior when passed arguments representable in the argument

type. If the arguments are out of range for the function, such as an

argument outside the range of [-1,+1] to acos(), an

implementation-defined value is returned and errno is set to EDOM.

If the result of the function is not representable in the return type,

the functions mostly return HUGE_VAL or -HUGE_VAL and set errno to

ERANGE on magnitude overflow, and 0 with errno possible set to ERANGE.