DekGenius.com
Team LiB   Previous Section   Next Section

13.6 <cfloat>

The <cfloat> header is the C++ version of the C standard <float.h> header. It defines parameters that characterize floating-point types in the same way <climits> does for the integral types. The native C++ header, <limits>, defines the same information (and more) using templates instead of macros.

There are three sets of macros, each describing a different fundamental type. For each type, the corresponding set of macros has a common prefix: float (FLT_), double (DBL_), and long double (LDBL_). Each set characterizes a floating-point value as a sign, a significand (sometimes called the mantissa), a base, and an exponent:

x = sign x significand x base exponent

In everyday arithmetic, we are used to working with a base of 10. (The base is also called the radix.) The most common bases for computer arithmetic, however, are 16 and 2. Many modern workstations use the IEC 60559 (IEEE 754) standard for floating-point arithmetic, which uses a base of 2.

The significand is a string of digits in the given base. There is an implied radix point at the start of the significand so the value of the significand is always less than 1. (A radix point is the generalization of a decimal point for any radix.)

A floating-point value is normalized if the first digit of its significand is nonzero, or if the entire value is 0. A value that is not normalized is denormalized.

The precision of a floating-point type is the maximum number of places in the significand. The range of a floating-point type depends primarily on the minimum and maximum values for the exponent.

figs/acorn.gif

The value returned by each macro is implementation-defined because all the fundamental types are implementation-defined. The standard mandates minimum decimal precision and range for each floating-point type. In this section, the descriptions for the decimal characteristics of each type include the minimum value set by the standard.

Only FLT_RADIX expands to a constant expression. All other macros in <cfloat> expand to numeric expressions, but the values might not be compile-time constants.

DBL_DIG macro Decimal precision

int DBL_DIG

Number of significant decimal digits that can be stored in a double. The value is always at least 10.

DBL_EPSILON macro Limit of accuracy

double DBL_EPSILON

The difference between 1 and the smallest value greater than 1 that can be stored in a double. The value is always less than or equal to 10-9.

DBL_MANT_DIG macro Significand precision

int DBL_MANT_DIG

Number of FLT_RADIX digits in the significand of a double.

DBL_MAX macro Maximum finite value

double DBL_MAX

Maximum finite double value. The value is always at least 1037.

DBL_MAX_10_EXP macro Maximum decimal exponent

int DBL_MAX_10_EXP

Maximum decimal exponent for a finite double. The value is always at least 37.

DBL_MAX_EXP macro Maximum exponent

int DBL_MAX_EXP

Maximum exponent of a FLT_RADIX base for a finite double.

DBL_MIN macro Minimum positive value

double DBL_MIN

Minimum normalized, positive double value. The value is always less than or equal to 10-37.

DBL_MIN_10_EXP macro Minimum decimal exponent

int DBL_MIN_10_EXP

Minimum negative decimal exponent for a normalized double. The value is always less than or equal to -37.

DBL_MIN_EXP macro Minimum exponent

int DBL_MIN_EXP

Minimum negative exponent of a FLT_RADIX base for a normalized double.

FLT_DIG macro Decimal precision

int FLT_DIG

Number of significant decimal digits that can be stored in a float. The value is always at least 6.

FLT_EPSILON macro Limit of accuracy

float FLT_EPSILON

The difference between 1 and the smallest value greater than 1 that can be stored in a float. The value is always less than or equal to 10-5.

FLT_MANT_DIG macro Significand precision

int FLT_MANT_DIG

Number of FLT_RADIX digits in the significand of a float.

FLT_MAX macro Maximum finite value

float FLT_MAX

Maximum finite float value. The value is always at least 1037.

FLT_MAX_10_EXP macro Maximum decimal exponent

int FLT_MAX_10_EXP

Maximum decimal exponent for a finite float. The value is always at least 37.

FLT_MAX_EXP macro Maximum exponent

int FLT_MAX_EXP

Maximum exponent of a FLT_RADIX base for a finite float.

FLT_MIN macro Minimum positive value

float FLT_MIN

Minimum normalized, positive float value. The value is always less than or equal to 10-37.

FLT_MIN_10_EXP macro Minimum decimal exponent

int FLT_MIN_10_EXP

Minimum negative decimal exponent for a normalized float. The value is always less than or equal to -37.

FLT_MIN_EXP macro Minimum exponent

int FLT_MIN_EXP

Minimum negative exponent of a FLT_RADIX base for a normalized float.

FLT_RADIX macro Implementation base

int FLT_RADIX

The FLT_RADIX macro is an integer constant that specifies the radix, or base, for the floating-point implementation. For example, IEC 60559 (IEEE 754) has a FLT_RADIX of 2.

FLT_ROUNDS macro Rounding mode

int FLT_ROUNDS

The FLT_ROUNDS macro specifies how the implementation rounds floating-point numbers. Table 13-2 lists the possible values as defined in the C++ standard. An implementation can define additional values with other meanings.

Table 13-2. Floating-point rounding mode

Value

Description

-1

Indeterminable

0

Rounds toward 0

1

Rounds to nearest

2

Rounds up (toward positive infinity)

3

Rounds down (toward negative infinity)

LDBL_DIG macro Decimal precision

int LDBL_DIG

Number of significant decimal digits that can be stored in a long double.The value is always at least 10.

LDBL_EPSILON macro Limit of accuracy

long double LDBL_EPSILON

The difference between 1 and the smallest value greater than 1 that can be stored in a long double. The value is always less than or equal to 10-9.

LDBL_MANT_DIG macro Significand precision

int LDBL_MANT_DIG

Number of FLT_RADIX digits in the significand of a long double.

LDBL_MAX macro Maximum finite value

long double LDBL_MAX

Maximum finite long double value. The value is always at least 1037.

LDBL_MAX_10_EXP macro Maximum decimal exponent

int LDBL_MAX_10_EXP

Maximum decimal exponent for a finite long double. The value is always at least 37.

LDBL_MAX_EXP macro Maximum exponent

int LDBL_MAX_EXP

Maximum exponent of a FLT_RADIX base for a finite double.

LDBL_MIN macro Minimum positive value

long double LDBL_MIN

Minimum normalized, positive long double value. The value is always less than or equal to 10-37.

LDBL_MIN_10_EXP macro Minimum decimal exponent

int LDBL_MIN_10_EXP

Minimum negative decimal exponent for a normalized long double. The value is always less than or equal to -37.

LDBL_MIN_EXP macro Minimum exponent

int LDBL_MIN_EXP

Minimum negative exponent of a FLT_RADIX base for a normalized long double.

    Team LiB   Previous Section   Next Section