Стандарт языка Си С99 TC (1113411), страница 76
Текст из файла (страница 76)
Theminimum magnitudes shown shall be replaced by implementation-defined magnitudeswith the same sign. The values shall all be constant expressions suitable for use in #ifpreprocessing directives. The components are described further in 5.2.4.2.1.#define#define#define#define#define#define#define#define#define#define#define#define#define#define#define#define#define#define#defineCHAR_BITCHAR_MAXCHAR_MININT_MAXINT_MINLONG_MAXLONG_MINLLONG_MAXLLONG_MINMB_LEN_MAXSCHAR_MAXSCHAR_MINSHRT_MAXSHRT_MINUCHAR_MAXUSHRT_MAXUINT_MAXULONG_MAXULLONG_MAX8UCHAR_MAX or SCHAR_MAX0 or SCHAR_MIN+32767-32767+2147483647-2147483647+9223372036854775807-92233720368547758071+127-127+32767-3276725565535655354294967295184467440737095516152The contents of the header <float.h> are given below. All integer values, exceptFLT_ROUNDS, shall be constant expressions suitable for use in #if preprocessingdirectives; all floating values shall be constant expressions. The components aredescribed further in 5.2.4.2.2.3The values given in the following list shall be replaced by implementation-definedexpressions:#define FLT_EVAL_METHOD#define FLT_ROUNDS4The values given in the following list shall be replaced by implementation-definedconstant expressions that are greater or equal in magnitude (absolute value) to thoseshown, with the same sign:442Implementation limits§EWG14/N1256#define#define#define#define#define#define#define#define#define#define#define#define#define#define#define#define#define#define#define#define5Committee Draft — Septermber 7, 2007DBL_DIGDBL_MANT_DIGDBL_MAX_10_EXPDBL_MAX_EXPDBL_MIN_10_EXPDBL_MIN_EXPDECIMAL_DIGFLT_DIGFLT_MANT_DIGFLT_MAX_10_EXPFLT_MAX_EXPFLT_MIN_10_EXPFLT_MIN_EXPFLT_RADIXLDBL_DIGLDBL_MANT_DIGLDBL_MAX_10_EXPLDBL_MAX_EXPLDBL_MIN_10_EXPLDBL_MIN_EXP10+37-37106+37-37210+37-37The values given in the following list shall be replaced by implementation-definedconstant expressions with values that are greater than or equal to those shown:#define DBL_MAX#define FLT_MAX#define LDBL_MAX6ISO/IEC 9899:TC31E+371E+371E+37The values given in the following list shall be replaced by implementation-definedconstant expressions with (positive) values that are less than or equal to those shown:#define#define#define#define#define#define§EDBL_EPSILONDBL_MINFLT_EPSILONFLT_MINLDBL_EPSILONLDBL_MINImplementation limits1E-91E-371E-51E-371E-91E-37443ISO/IEC 9899:TC3Committee Draft — Septermber 7, 2007WG14/N1256Annex F(normative)IEC 60559 floating-point arithmeticF.1 Introduction1This annex specifies C language support for the IEC 60559 floating-point standard.
TheIEC 60559 floating-point standard is specifically Binary floating-point arithmetic formicroprocessor systems, second edition (IEC 60559:1989), previously designatedIEC 559:1989 and as IEEE Standard for Binary Floating-Point Arithmetic(ANSI/IEEE 754−1985). IEEE Standard for Radix-Independent Floating-PointArithmetic (ANSI/IEEE 854−1987) generalizes the binary standard to removedependencies on radix and word length. IEC 60559 generally refers to the floating-pointstandard, as in IEC 60559 operation, IEC 60559 format, etc. An implementation thatdefines _ _STDC_IEC_559_ _ shall conform to the specifications in this annex.
Wherea binding between the C language and IEC 60559 is indicated, the IEC 60559-specifiedbehavior is adopted by reference, unless stated otherwise.F.2 Types1The C floating types match the IEC 60559 formats as follows:— The float type matches the IEC 60559 single format.— The double type matches the IEC 60559 double format.— The long double type matches an IEC 60559 extended format,307) else anon-IEC 60559 extended format, else the IEC 60559 double format.Any non-IEC 60559 extended format used for the long double type shall have moreprecision than IEC 60559 double and at least the range of IEC 60559 double.308)Recommended practice2The long double type should match an IEC 60559 extended format.307) ‘‘Extended’’ is IEC 60559’s double-extended data format. Extended refers to both the common 80-bitand quadruple 128-bit IEC 60559 formats.308) A non-IEC 60559 long double type is required to provide infinity and NaNs, as its values includeall double values.444IEC 60559 floating-point arithmetic§F.2WG14/N1256Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC3F.2.1 Infinities, signed zeros, and NaNs1This specification does not define the behavior of signaling NaNs.309) It generally usesthe term NaN to denote quiet NaNs.
The NAN and INFINITY macros and the nanfunctions in <math.h> provide designations for IEC 60559 NaNs and infinities.F.3 Operators and functions1C operators and functions provide IEC 60559 required and recommended facilities aslisted below.— The +, −, *, and / operators provide the IEC 60559 add, subtract, multiply, anddivide operations.— The sqrt functions in <math.h> provide the IEC 60559 square root operation.— The remainder functions in <math.h> provide the IEC 60559 remainderoperation. The remquo functions in <math.h> provide the same operation butwith additional information.— The rint functions in <math.h> provide the IEC 60559 operation that rounds afloating-point number to an integer value (in the same precision).
The nearbyintfunctions in <math.h> provide the nearbyinteger function recommended in theAppendix to ANSI/IEEE 854.— The conversions for floating types provide the IEC 60559 conversions betweenfloating-point precisions.— The conversions from integer to floating types provide the IEC 60559 conversionsfrom integer to floating point.— The conversions from floating to integer types provide IEC 60559-like conversionsbut always round toward zero.— The lrint and llrint functions in <math.h> provide the IEC 60559conversions, which honor the directed rounding mode, from floating point to thelong int and long long int integer formats.
The lrint and llrintfunctions can be used to implement IEC 60559 conversions from floating to otherinteger formats.— The translation time conversion of floating constants and the strtod, strtof,strtold, fprintf, fscanf, and related library functions in <stdlib.h>,<stdio.h>, and <wchar.h> provide IEC 60559 binary-decimal conversions. Thestrtold function in <stdlib.h> provides the conv function recommended in theAppendix to ANSI/IEEE 854.309) Since NaNs created by IEC 60559 operations are always quiet, quiet NaNs (along with infinities) aresufficient for closure of the arithmetic.§F.3IEC 60559 floating-point arithmetic445ISO/IEC 9899:TC3Committee Draft — Septermber 7, 2007WG14/N1256— The relational and equality operators provide IEC 60559 comparisons.
IEC 60559identifies a need for additional comparison predicates to facilitate writing code thataccounts for NaNs. The comparison macros (isgreater, isgreaterequal,isless, islessequal, islessgreater, and isunordered) in <math.h>supplement the language operators to address this need. The islessgreater andisunordered macros provide respectively a quiet version of the <> predicate andthe unordered predicate recommended in the Appendix to IEC 60559.— The feclearexcept, feraiseexcept, and fetestexcept functions in<fenv.h> provide the facility to test and alter the IEC 60559 floating-pointexception status flags. The fegetexceptflag and fesetexceptflagfunctions in <fenv.h> provide the facility to save and restore all five status flags atone time.
These functions are used in conjunction with the type fexcept_t and thefloating-pointexceptionmacros(FE_INEXACT,FE_DIVBYZERO,FE_UNDERFLOW, FE_OVERFLOW, FE_INVALID) also in <fenv.h>.— The fegetround and fesetround functions in <fenv.h> provide the facilityto select among the IEC 60559 directed rounding modes represented by the roundingdirection macros in <fenv.h> (FE_TONEAREST, FE_UPWARD, FE_DOWNWARD,FE_TOWARDZERO) and the values 0, 1, 2, and 3 of FLT_ROUNDS are theIEC 60559 directed rounding modes.— The fegetenv, feholdexcept, fesetenv, and feupdateenv functions in<fenv.h> provide a facility to manage the floating-point environment, comprisingthe IEC 60559 status flags and control modes.— The copysign functions in <math.h> provide the copysign functionrecommended in the Appendix to IEC 60559.— The unary minus (−) operator provides the minus (−) operation recommended in theAppendix to IEC 60559.— The scalbn and scalbln functions in <math.h> provide the scalb functionrecommended in the Appendix to IEC 60559.— The logb functions in <math.h> provide the logb function recommended in theAppendix to IEC 60559, but following the newer specifications in ANSI/IEEE 854.— The nextafter and nexttoward functions in <math.h> provide the nextafterfunction recommended in the Appendix to IEC 60559 (but with a minor change tobetter handle signed zeros).— The isfinite macro in <math.h> provides the finite function recommended inthe Appendix to IEC 60559.— The isnan macro in <math.h> provides the isnan function recommended in theAppendix to IEC 60559.446IEC 60559 floating-point arithmetic§F.3WG14/N1256Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC3— The signbit macro and the fpclassify macro in <math.h>, used inconjunction with the number classification macros (FP_NAN, FP_INFINITE,FP_NORMAL, FP_SUBNORMAL, FP_ZERO), provide the facility of the classfunction recommended in the Appendix to IEC 60559 (except that the classificationmacros defined in 7.12.3 do not distinguish signaling from quiet NaNs).F.4 Floating to integer conversion1If the floating value is infinite or NaN or if the integral part of the floating value exceedsthe range of the integer type, then the ‘‘invalid’’ floating-point exception is raised and theresulting value is unspecified.