Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Jones D.M.The new C standard (C90 and C++).An economic and cultural commentary.2005

.pdf
Скачиваний:
19
Добавлен:
23.08.2013
Размер:
1.36 Mб
Скачать

5.2.4.2.2 Characteristics of floating types <float.h> 350

347 All except DECIMAL_DIG, FLT_EVAL_METHOD, FLT_RADIX, and FLT_ROUNDS have separate names for all three floating-point types.

C90

Support for DECIMAL_DIG and FLT_EVAL_METHOD is new in C99. The FLT_EVAL_METHOD macro appears to add functionality that could cause a change of behavior in existing programs. However, in practice it provides access to information on an implementation’s behavior that was not previously available at the source code level. Implementations are not likely to change their behavior because of this macro, other than to support it.

C++

It is possible that some implementations will only meet the requirements contained in the C90 Standard.

348 The floating-point model representation is provided for all values except FLT_EVAL_METHOD and FLT_ROUNDS.

C90

Support for FLT_EVAL_METHOD is new in C99.

C++

It is possible that some implementations will only meet the requirements contained in the C90 Standard.

349 The rounding mode for floating-point addition is characterized by the implementation-defined value of

18)

FLT_ROUNDS:FLT_ROUNDS

-1

indeterminable

 

0

toward zero

 

1to nearest

2 toward positive infinity

3toward negative infinity

All other values for FLT_ROUNDS characterize implementation-defined rounding behavior.

C++

It is possible that some implementations will only meet the requirements contained in the C90 Standard.

The C++ header <limits> also contains the enumerated type:

namespace std {

 

18.2.1.3

 

 

enum float_round_style {

 

 

round_indeterminable

= -1,

 

round_toward_zero

= 0,

 

round_to_nearest

= 1,

 

round_toward_infinity

= 2,

 

round_toward_neg_infinity

= 3

 

};

 

 

}

 

 

 

 

 

which is referenced by the following member, which exists for every specialization of an arithmetic type (in theory this allows every floating-point type to support a different rounding mode):

18.2.1.2p62

Meaningful for all floating point types.

static const float_round_style round_style;

The rounding style for the type.206)

September 2, 2005

v 1.0b

355 5.2.4.2.2 Characteristics of floating types <float.h>

The values of operations with floating operands and values subject to the usual arithmetic conversions and 350 of floating constants are evaluated to a format whose range and precision may be greater than required by

the type.

C90

6.2.1.5

The values of floating operands and of the results of floating expressions may be represented in greater precision and range than that required by the type;

This wording allows wider representations to be used for floating-point operands and expressions. It could also be interpreted (somewhat liberally) to support the idea that C90 permitted floating constants to be represented in wider formats where the usual arithmetic conversions applied.

Having the representation of floating constants change depending on how an implementation chooses to specify FLT_EVAL_METHOD is new in C99.

C++

Like C90, the FLT_EVAL_METHOD macro is not available in C++.

The use of evaluation formats is characterized by the implementation-defined value of FLT_EVAL_METHOD:19) 351

FLT_EVAL_METHOD

C90

Support for the FLT_EVAL_METHOD macro is new in C99. Its significant attendant baggage was also present in C90 implementations, but was explicitly not highlighted in that standard.

C++

Support for the FLT_EVAL_METHOD macro is new in C99 and it is not available in C++. However, it is likely that the implementation of floating point in C ++ will be the same as in C.

For implementations that do not support IEC 60559:1989, the terms quiet NaN and signaling NaN are in- 355 tended to apply to encodings with similar behavior.

C90

The concept of NaN is new, in terms of being explicitly discussed, in C99.

C++

18.2.1.2p34

18.2.1.2p37

static const bool has_quiet_NaN;

True if the type has a representation for a quiet (non-signaling) “Not a Number.” 193)

Meaningful for all floating point types.

Shall be true for all specializations in which is_iec559 != false.

static const bool has_signaling_NaN;

True if the type has a representation for a signaling “Not a Number.”194) Meaningful for all floating point types.

Shall be true for all specializations in which is_iec559 != false.

v 1.0b

September 2, 2005

5.2.4.2.2 Characteristics of floating types <float.h> 363

18.2.1.2p52

static const bool is_iec559;

True if and only if the type adheres to IEC 559 standard.201)

The C++ Standard requires NaNs to be supported if IEC 60559 is supported, but says nothing about the situation where that standard is not supported by an implementation.

356 18) Evaluation of FLT_ROUNDS correctly reflects any execution-time change of rounding mode through the function fesetround in <fenv.h>.

C90

Support for the header <fenv.h> is new in C99. The C90 Standard did not provide a mechanism for changing the rounding direction.

C++

Support for the header <fenv.h> and the fesetround function is new in C99 and is not specified in the C++ Standard.

357 19) The evaluation method determines evaluation formats of expressions involving all floating types, not just real types.

C90

Support for complex types is new in C99.

C++

The complex types are a template class in C++. The definitions of the instantiation of these classes do not specify that the evaluation format shall be the same as for the real types. But then, the C++ Standard does not specify the evaluation format for the real types.

footnote 18

footnote 19

358 For example, if FLT_EVAL_METHOD is 1, then the product of two float _Complex operands is represented in the double _Complex format, and its parts are evaluated to double.

C++

The C++ Standard does not specify a FLT_EVAL_METHOD mechanism.

362 The values given in the following list shall be replaced by constant expressions with implementation-defined values that are greater or equal in magnitude (absolute value) to those shown, with the same sign:

C90

In C90 the only expression that was required to be a constant expression was FLT_RADIX. It was explicitly stated that the others need not be constant expressions; however, in most implementations, the values were constant expressions.

C++

18.2.1p3

For all members declared static const in the numeric_limits template, specializations shall define these values in such a way that they are usable as integral constant expressions.

September 2, 2005

v 1.0b

366

 

5.2.4.2.2 Characteristics of floating types

<float.h>

 

 

 

 

 

 

363

FLT_RADIX

— radix of exponent representation,

b

 

 

FLT_RADIX

2

 

 

 

 

C++

 

 

 

18.2.1.2p16

static const int radix;

For floating types, specifies the base or radix of the exponent representation (often 2). 185)

DECIMAL_DIG — number of decimal digits, n, such that any floating-point number in the widest supported floating type with 365

macro

pmax radix b digits can be rounded to a floating-point number with n decimal digits and back again without

 

 

change to the value,

 

 

pmax log10 b

if b is a power of 10

 

d1 + pmax log10 be

otherwise

 

DECIMAL_DIG

10

*_DIG macros

C90

Support for the DECIMAL_DIG macro is new in C99.

C++

Support for the DECIMAL_DIG macro is new in C99 and specified in the C++ Standard.

— number of decimal digits, q, such that any floating-point number with q decimal digits can be rounded into 366 a floating-point number with p radix b digits and back again without change to the q decimal digits,

pmax log10 b

if b is a power of 10

b(p − 1) log10 bc

otherwise

FLT_DIG

6

DBL_DIG

10

LDBL_DIG

10

C++

18.2.1.2p9

static const int digits10;

Number of base 10 digits that can be represented without change.

Footnote 184

Equivalent to FLT_DIG, DBL_DIG, LDBL_DIG.

18.2.2p4

v 1.0b

September 2, 2005

5.2.4.2.2 Characteristics of floating types <float.h> 368

Header <cfloat> (Table 17): . . . The contents are the same as the Standard C library header <float.h>.

367 — minimum negative integer such that FLT_RADIX raised to one less than that power is a normalized floating-

*_MIN_EXP

point number, emin

 

FLT_MIN_EXP

 

DBL_MIN_EXP

 

LDBL_MIN_EXP

 

C++

18.2.1.2p23

static const int min_exponent;

Minimum negative integer such that radix raised to that power is in the range of normalised floating point numbers.189)

Footnote 189

Equivalent to FLT_MIN_EXP, DBL_MIN_EXP, LDBL_MIN_EXP.

18.2.2p4

Header <cfloat> (Table 17): . . . The contents are the same as the Standard C library header <float.h>.

368 — minimum negative integer such that 10 raised to that power is in the range of normalized floating-point

*_MIN_10_EXP

numbers, dlog10 bemin −1e

 

 

FLT_MIN_10_EXP

-37

 

DBL_MIN_10_EXP

-37

 

LDBL_MIN_10_EXP

-37

 

C++

18.2.1.2p25

static const int min_exponent10;

Minimum negative integer such that 10 raised to that power is in the range of normalised floating point numbers.190)

Footnote 190

Equivalent to FLT_MIN_10_EXP, DBL_MIN_10_EXP, LDBL_MIN_10_EXP.

18.2.2p4

September 2, 2005

v 1.0b

370

5.2.4.2.2 Characteristics of floating types <float.h>

Header <cfloat> (Table 17): . . . The contents are the same as the Standard C library header <float.h>.

*_MAX_EXP

— maximum integer such that FLT_RADIX raised to one less than that power is a representable finite floating- 369

 

point number, emax

 

FLT_MAX_EXP

 

DBL_MAX_EXP

 

LDBL_MAX_EXP

 

C++

 

 

 

18.2.1.2p27

static const int max_exponent;

 

 

 

 

Maximum positive integer such that radix raised to the power one less than that integer is a representable

 

 

finite floating point number. 191)

 

 

 

 

Footnote 191

18.2.2p4

*_MAX_10_EXP

Equivalent to FLT_MAX_EXP, DBL_MAX_EXP, LDBL_MAX_EXP.

Header <cfloat> (Table 17): . . . The contents are the same as the Standard C library header <float.h>.

— maximum integer such that 10 raised to that power is in the range of representable finite floating-point 370 numbers, blog10((1 − b−p)bemax )c

FLT_MAX_10_EXP

+37

DBL_MAX_10_EXP

+37

LDBL_MAX_10_EXP

+37

C++

18.2.1.2p29

static const int max_exponent10;

 

Maximum positive integer such that 10 raised to that power is in the range of normalised floating point numbers.

Footnote 192

Equivalent to FLT_MAX_10_EXP, DBL_MAX_10_EXP, LDBL_MAX_10_EXP.

18.2.2

v 1.0b

September 2, 2005

5.2.4.2.2 Characteristics of floating types <float.h> 374

Header <cfloat> (Table 17): . . . The contents are the same as the Standard C library header <float.h>.

371 The values given in the following list shall be replaced by constant expressions with implementation-defined

floating val-

values that are greater than or equal to those shown:

ues listed

C90

C90 did not contain the requirement that the values be constant expressions.

C++

This requirement is not specified in the C ++ Standard, which refers to the C90 Standard by reference.

372 — maximum representable finite floating-point number, (1 − b−p)bemax

FLT_MAX

1E+37

DBL_MAX

1E+37

LDBL_MAX

1E+37

C++

static T max() throw();

Maximum finite value. 182

Equivalent to CHAR_MAX, SHRT_MAX, FLT_MAX, DBL_MAX, etc.

Header <cfloat> (Table 17): . . . The contents are the same as the Standard C library header <float.h>.

374 — the difference between 1 and the least value greater than 1 that is representable in the given floating point type, b1−p

FLT_EPSILON

1E-5

DBL_EPSILON

1E-9

LDBL_EPSILON

1E-9

C++

18.2.1.2p4

Footnote 182

18.2.2p4

*_EPSILON

static T epsilon() throw();

18.2.1.2p20

 

Machine epsilon: the difference between 1 and the least value greater than 1 that is representable.187)

Footnote 187

September 2, 2005

v 1.0b

378

5.2.4.2.2 Characteristics of floating types <float.h>

Equivalent to FLT_EPSILON, DBL_EPSILON, LDBL_EPSILON.

18.2.2p4

Header <cfloat> (Table 17): . . . The contents are the same as the Standard C library header <float.h>.

*_MIN

— minimum normalized positive floating-point number, bemin −1

375

macros

 

 

 

 

FLT_MIN

1E-37

 

 

DBL_MIN

1E-37

 

 

LDBL_MIN

1E-37

 

C++

18.2.1.2p1

static T min() throw();

Maximum finite value. 181)

Footnote 181

Equivalent to CHAR_MIN, SHRT_MIN, FLT_MIN, DBL_MIN, etc.

18.2.2p4

Header <cfloat> (Table 17): . . . The contents are the same as the Standard C library header <float.h>.

Recommended practice

DECIMAL_DIG

conversion recommended practice

EXAMPLE IEC 60559 floating-point

Conversion from (at least) double to decimal with DECIMAL_DIG digits and back should be the identity function. 376

C90

The Recommended practice clauses are new in the C99 Standard.

C++

There is no such macro, or requirement specified in the C ++ Standard.

EXAMPLE 2 The following describes floating-point representations that also meet the requirements for 378 single-precision and double-precision normalized numbers in IEC 60559,20) and the appropriate values in

a <float.h> header for types float and double:

xf = s2e

24

fk2−k, −125 ≤ e ≤ +128

 

P

 

k=1

 

53

xd = s2e

fk2−k, −1021 ≤ e ≤ +1024

 

kP

 

=1

v 1.0b

September 2, 2005

6.1 Notation 381

 

FLT_RADIX

 

2

 

 

 

 

DECIMAL_DIG

 

17

 

 

 

 

FLT_MANT_DIG

24

 

 

 

 

FLT_EPSILON

 

1.19209290E-07F //

decimal constant

 

 

FLT_EPSILON

 

0X1P-23F //

hex constant

 

 

FLT_DIG

 

6

 

 

 

 

FLT_MIN_EXP

 

-125

 

 

 

 

FLT_MIN

 

1.17549435E-38F //

decimal constant

 

 

FLT_MIN

 

0X1P-126F //

hex constant

 

 

FLT_MIN_10_EXP

-37

 

 

 

 

FLT_MAX_EXP

 

+128

 

 

 

 

FLT_MAX

 

3.40282347E+38F //

decimal constant

 

 

FLT_MAX

 

0X1.fffffeP127F //

hex constant

 

 

FLT_MAX_10_EXP

+38

 

 

 

 

DBL_MANT_DIG

53

 

 

 

 

DBL_EPSILON 2.2204460492503131E-16 //

decimal constant

 

 

DBL_EPSILON

 

0X1P-52 //

hex constant

 

 

DBL_DIG

 

15

 

 

 

 

DBL_MIN_EXP

 

-1021

 

 

 

 

DBL_MIN

2.2250738585072014E-308 //

decimal constant

 

 

DBL_MIN

 

0X1P-1022 //

hex constant

 

 

DBL_MIN_10_EXP

-307

 

 

 

 

DBL_MAX_EXP

 

+1024

 

 

 

 

DBL_MAX

1.7976931348623157E+308 //

decimal constant

 

 

DBL_MAX

0X1.fffffffffffffP1023 //

hex constant

 

 

DBL_MAX_10_EXP

+308

 

 

 

 

If a type wider than double were supported, then DECIMAL_DIG would be greater than 17. For example, if

 

 

the widest type were to use the minimal-width IEC 60559 double-extended format (64 bits of precision), then

 

 

DECIMAL_DIG would be 21.

 

 

 

 

 

C90

 

 

 

 

 

 

The C90 wording referred to the ANSI/IEEE-754–1985 standard.

 

6. Language

 

 

 

 

 

6.1 Notation

 

 

 

 

 

 

 

 

 

381 In the syntax notation used in this clause, syntactic categories (nonterminals) are indicated by italic type,

notation

and literal words and character set members (terminals) by bold type.

C++

1.6p1

In the syntax notation used in this International Standard, syntactic categories are indicated by italic type, and literal words and characters in constant width type.

September 2, 2005

v 1.0b

397

6.2.1 Scopes of identifiers

 

 

 

The C++ grammar contains significantly more syntactic ambiguities than C. Some implementations have

 

used mainly syntactic approaches to resolving these,[7] while others make use of semantic information to

 

guide the parse.[2] For instance, knowing what an identifier has been declared as, simplifies the parsing of

 

the following:

 

 

 

1

template_name

< a , b > - 5

// equivalent to (template_name < a , b >) - 5)

 

2

non_template_name < a , b > - 5

// equivalent to (non_template_name < a) , (b > - 5)

 

A colon (:) following a nonterminal introduces its definition.

382

 

C++

 

 

The C++ Standard does not go into this level of detail (although it does use this notation).

 

 

 

 

 

 

When syntactic categories are referred to in the main text, they are not italicized and words are separated by

385

 

spaces instead of hyphens.

 

 

C90

 

 

This convention was not explicitly specified in the C90 Standard.

 

 

C++

 

 

The C++ Standard does not explicitly specify the conventions used. However, based on the examples given

 

 

in clause 1.6 and usage within the standard, the conventions used appear to be the reverse of those used in

 

 

C (i.e., syntactic categories are italicized and words are separated by hyphens).

 

 

 

 

 

 

A summary of the language syntax is given in annex A.

386

 

C90

 

 

The summary appeared in Annex B of the C90 Standard, and this fact was not pointed out in the normative

 

 

text.

 

6.2 Concepts

 

6.2.1 Scopes of identifiers

 

 

 

 

 

 

a tag or a member of a structure, union, or enumeration;

389

 

C++

 

identifier macro param-

eter

The C++ Standard does not define the term tag.

It uses the terms enum-name (7.2p1) for enumeration

definitions and class-name (9p1) for classes.

 

 

 

 

 

or a macro parameter.

393

C++

 

 

The C++ Standard does not list macro parameters as one of the entities that can be denoted by an identifier.

identifier

The same identifier can denote different entities at different points in the program.

394

denote different

 

 

 

entities

C++

 

 

 

 

The C++ Standard does not explicitly state this possibility, although it does include wording (e.g., 3.3p4)

 

 

that implies it is possible.

 

 

 

 

 

enumeration

A member of an enumeration is called an enumeration constant.

395

constant

 

 

 

v 1.0b

September 2, 2005

Соседние файлы в предмете Электротехника