Стандарт языка Си С99 TC (1113411), страница 41
Текст из файла (страница 41)
The structurepointed to by the return value shall not be modified by the program, but may beoverwritten by a subsequent call to the localeconv function. In addition, calls to thesetlocale function with categories LC_ALL, LC_MONETARY, or LC_NUMERIC mayoverwrite the contents of the structure.9EXAMPLE 1 The following table illustrates rules which may well be used by four countries to formatmonetary quantities.Local format10International formatCountryPositiveNegativePositiveCountry1Country2Country3Country41.234,56 mkL.1.234ƒ 1.234,56SFrs.1,234.56-1.234,56 mk-L.1.234ƒ -1.234,56SFrs.1,234.56CFIMITLNLGCHF1.234,561.2341.234,561,234.56NegativeFIM -1.234,56-ITL 1.234NLG -1.234,56CHF 1,234.56CFor these four countries, the respective values for the monetary members of the structure returned bylocaleconv could be:mon_decimal_pointmon_thousands_sepmon_groupingpositive_signnegative_signcurrency_symbolfrac_digitsp_cs_precedesn_cs_precedesp_sep_by_spacen_sep_by_spacep_sign_posnn_sign_posnint_curr_symbolint_frac_digitsint_p_cs_precedesint_n_cs_precedesint_p_sep_by_spaceint_n_sep_by_spaceint_p_sign_posnint_n_sign_posn210Country1Country2Country3Country4","".""\3""""-""mk"2001111"FIM "2111214""".""\3""""-""L."0110011"ITL "0111111","".""\3""""-""\u0192"2111214"NLG "2111214"."",""\3""""C""SFrs."2110012"CHF "2111112Library§7.11.2.1WG14/N125611Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC3EXAMPLE 2 The following table illustrates how the cs_precedes, sep_by_space, and sign_posn membersaffect the formatted value.p_sep_by_spacep_cs_precedesp_sign_posn01§7.11.2.101201234(1.25$)+1.25$1.25$+1.25+$1.25$+(1.25 $)+1.25 $1.25 $+1.25 +$1.25 $+(1.25$)+ 1.25$1.25$ +1.25+ $1.25$ +01234($1.25)+$1.25$1.25++$1.25$+1.25($ 1.25)+$ 1.25$ 1.25++$ 1.25$+ 1.25($1.25)+ $1.25$1.25 ++ $1.25$ +1.25Library211ISO/IEC 9899:TC3Committee Draft — Septermber 7, 2007WG14/N12567.12 Mathematics <math.h>1The header <math.h> declares two types and many mathematical functions and definesseveral macros.
Most synopses specify a family of functions consisting of a principalfunction with one or more double parameters, a double return value, or both; andother functions with the same name but with f and l suffixes, which are correspondingfunctions with float and long double parameters, return values, or both.198)Integer arithmetic functions and conversion functions are discussed later.2The typesfloat_tdouble_tare floating types at least as wide as float and double, respectively, and such thatdouble_t is at least as wide as float_t. If FLT_EVAL_METHOD equals 0,float_t and double_t are float and double, respectively; ifFLT_EVAL_METHOD equals 1, they are both double; if FLT_EVAL_METHOD equals2, they are both long double; and for other values of FLT_EVAL_METHOD, they areotherwise implementation-defined.199)3The macroHUGE_VALexpands to a positive double constant expression, not necessarily representable as afloat.
The macrosHUGE_VALFHUGE_VALLare respectively float and long double analogs of HUGE_VAL.200)4The macroINFINITYexpands to a constant expression of type float representing positive or unsignedinfinity, if available; else to a positive constant of type float that overflows at198) Particularly on systems with wide expression evaluation, a <math.h> function might pass argumentsand return values in wider format than the synopsis prototype indicates.199) The types float_t and double_t are intended to be the implementation’s most efficient types atleast as wide as float and double, respectively.
For FLT_EVAL_METHOD equal 0, 1, or 2, thetype float_t is the narrowest type used by the implementation to evaluate floating expressions.200) HUGE_VAL, HUGE_VALF, and HUGE_VALL can be positive infinities in an implementation thatsupports infinities.212Library§7.12WG14/N1256Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC3translation time.201)5The macroNANis defined if and only if the implementation supports quiet NaNs for the float type. Itexpands to a constant expression of type float representing a quiet NaN.6The number classification macrosFP_INFINITEFP_NANFP_NORMALFP_SUBNORMALFP_ZEROrepresent the mutually exclusive kinds of floating-point values.
They expand to integerconstant expressions with distinct values. Additional implementation-defined floatingpoint classifications, with macro definitions beginning with FP_ and an uppercase letter,may also be specified by the implementation.7The macroFP_FAST_FMAis optionally defined. If defined, it indicates that the fma function generally executesabout as fast as, or faster than, a multiply and an add of double operands.202) ThemacrosFP_FAST_FMAFFP_FAST_FMALare, respectively, float and long double analogs of FP_FAST_FMA. If defined,these macros expand to the integer constant 1.8The macrosFP_ILOGB0FP_ILOGBNANexpand to integer constant expressions whose values are returned by ilogb(x) if x iszero or NaN, respectively. The value of FP_ILOGB0 shall be either INT_MIN or-INT_MAX. The value of FP_ILOGBNAN shall be either INT_MAX or INT_MIN.201) In this case, using INFINITY will violate the constraint in 6.4.4 and thus require a diagnostic.202) Typically, the FP_FAST_FMA macro is defined if and only if the fma function is implementeddirectly with a hardware multiply-add instruction.
Software implementations are expected to besubstantially slower.§7.12Library213ISO/IEC 9899:TC39Committee Draft — Septermber 7, 2007WG14/N1256The macrosMATH_ERRNOMATH_ERREXCEPTexpand to the integer constants 1 and 2, respectively; the macromath_errhandlingexpands to an expression that has type int and the value MATH_ERRNO,MATH_ERREXCEPT, or the bitwise OR of both. The value of math_errhandling isconstant for the duration of the program.
It is unspecified whethermath_errhandling is a macro or an identifier with external linkage. If a macrodefinition is suppressed or a program defines an identifier with the namemath_errhandling, the behavior is undefined.If the expressionmath_errhandling & MATH_ERREXCEPT can be nonzero, the implementationshall define the macros FE_DIVBYZERO, FE_INVALID, and FE_OVERFLOW in<fenv.h>.7.12.1 Treatment of error conditions1The behavior of each of the functions in <math.h> is specified for all representablevalues of its input arguments, except where stated otherwise.
Each function shall executeas if it were a single operation without generating any externally visible exceptionalconditions.2For all functions, a domain error occurs if an input argument is outside the domain overwhich the mathematical function is defined. The description of each function lists anyrequired domain errors; an implementation may define additional domain errors, providedthat such errors are consistent with the mathematical definition of the function.203) On adomain error, the function returns an implementation-defined value; if the integerexpression math_errhandling & MATH_ERRNO is nonzero, the integer expressionerrno acquires the value EDOM; if the integer expression math_errhandling &MATH_ERREXCEPT is nonzero, the ‘‘invalid’’ floating-point exception is raised.3Similarly, a range error occurs if the mathematical result of the function cannot berepresented in an object of the specified type, due to extreme magnitude.4A floating result overflows if the magnitude of the mathematical result is finite but solarge that the mathematical result cannot be represented without extraordinary roundofferror in an object of the specified type.
If a floating result overflows and default roundingis in effect, or if the mathematical result is an exact infinity from finite arguments (forexample log(0.0)), then the function returns the value of the macro HUGE_VAL,203) In an implementation that supports infinities, this allows an infinity as an argument to be a domainerror if the mathematical domain of the function does not include the infinity.214Library§7.12.1WG14/N1256Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC3HUGE_VALF, or HUGE_VALL according to the return type, with the same sign as thecorrect value of the function; if the integer expression math_errhandling &MATH_ERRNO is nonzero, the integer expression errno acquires the value ERANGE; ifthe integer expression math_errhandling & MATH_ERREXCEPT is nonzero, the‘‘divide-by-zero’’ floating-point exception is raised if the mathematical result is an exactinfinity and the ‘‘overflow’’ floating-point exception is raised otherwise.5The result underflows if the magnitude of the mathematical result is so small that themathematical result cannot be represented, without extraordinary roundoff error, in anobject of the specified type.204) If the result underflows, the function returns animplementation-defined value whose magnitude is no greater than the smallestnormalized positive number in the specified type; if the integer expressionmath_errhandling & MATH_ERRNO is nonzero, whether errno acquires thevalueERANGEisimplementation-defined;iftheintegerexpressionmath_errhandling & MATH_ERREXCEPT is nonzero, whether the ‘‘underflow’’floating-point exception is raised is implementation-defined.7.12.2 The FP_CONTRACT pragmaSynopsis1#include <math.h>#pragma STDC FP_CONTRACT on-off-switchDescription2The FP_CONTRACT pragma can be used to allow (if the state is ‘‘on’’) or disallow (if thestate is ‘‘off’’) the implementation to contract expressions (6.5).
Each pragma can occureither outside external declarations or preceding all explicit declarations and statementsinside a compound statement. When outside external declarations, the pragma takeseffect from its occurrence until another FP_CONTRACT pragma is encountered, or untilthe end of the translation unit. When inside a compound statement, the pragma takeseffect from its occurrence until another FP_CONTRACT pragma is encountered(including within a nested compound statement), or until the end of the compoundstatement; at the end of a compound statement the state for the pragma is restored to itscondition just before the compound statement.
If this pragma is used in any othercontext, the behavior is undefined. The default state (‘‘on’’ or ‘‘off’’) for the pragma isimplementation-defined.204) The term underflow here is intended to encompass both ‘‘gradual underflow’’ as in IEC 60559 andalso ‘‘flush-to-zero’’ underflow.§7.12.2Library215ISO/IEC 9899:TC3Committee Draft — Septermber 7, 2007WG14/N12567.12.3 Classification macros1In the synopses in this subclause, real-floating indicates that the argument shall be anexpression of real floating type.7.12.3.1 The fpclassify macroSynopsis1#include <math.h>int fpclassify(real-floating x);Description2The fpclassify macro classifies its argument value as NaN, infinite, normal,subnormal, zero, or into another implementation-defined category.