?? lang.texi
字號:
machine.@menu* Floating Point Concepts:: Definitions of terminology.* Floating Point Parameters:: Details of specific macros.* IEEE Floating Point:: The measurements for one common representation. @end menu@node Floating Point Concepts@subsubsection Floating Point Representation ConceptsThis section introduces the terminology for describing floating pointrepresentations.You are probably already familiar with most of these concepts in termsof scientific or exponential notation for floating point numbers. Forexample, the number @code{123456.0} could be expressed in exponentialnotation as @code{1.23456e+05}, a shorthand notation indicating that themantissa @code{1.23456} is multiplied by the base @code{10} raised topower @code{5}.More formally, the internal representation of a floating point numbercan be characterized in terms of the following parameters:@itemize @bullet@item@cindex sign (of floating point number)The @dfn{sign} is either @code{-1} or @code{1}.@item@cindex base (of floating point number)@cindex radix (of floating point number)The @dfn{base} or @dfn{radix} for exponentiation, an integer greaterthan @code{1}. This is a constant for a particular representation.@item@cindex exponent (of floating point number)The @dfn{exponent} to which the base is raised. The upper and lowerbounds of the exponent value are constants for a particularrepresentation.@cindex bias (of floating point number exponent)Sometimes, in the actual bits representing the floating point number,the exponent is @dfn{biased} by adding a constant to it, to make italways be represented as an unsigned quantity. This is only importantif you have some reason to pick apart the bit fields making up thefloating point number by hand, which is something for which the GNUlibrary provides no support. So this is ignored in the discussion thatfollows.@item@cindex mantissa (of floating point number)@cindex significand (of floating point number)The @dfn{mantissa} or @dfn{significand}, an unsigned integer which is apart of each floating point number.@item @cindex precision (of floating point number)The @dfn{precision} of the mantissa. If the base of the representationis @var{b}, then the precision is the number of base-@var{b} digits inthe mantissa. This is a constant for a particular representation.@cindex hidden bit (of floating point number mantissa)Many floating point representations have an implicit @dfn{hidden bit} inthe mantissa. This is a bit which is present virtually in the mantissa,but not stored in memory because its value is always 1 in a normalizednumber. The precision figure (see above) includes any hidden bits.Again, the GNU library provides no facilities for dealing with suchlow-level aspects of the representation.@end itemizeThe mantissa of a floating point number actually represents an implicitfraction whose denominator is the base raised to the power of theprecision. Since the largest representable mantissa is one less thanthis denominator, the value of the fraction is always strictly less than@code{1}. The mathematical value of a floating point number is then theproduct of this fraction, the sign, and the base raised to the exponent.@cindex normalized floating point numberWe say that the floating point number is @dfn{normalized} if thefraction is at least @code{1/@var{b}}, where @var{b} is the base. Inother words, the mantissa would be too large to fit if it weremultiplied by the base. Non-normalized numbers are sometimes called@dfn{denormal}; they contain less precision than the representationnormally can hold.If the number is not normalized, then you can subtract @code{1} from theexponent while multiplying the mantissa by the base, and get anotherfloating point number with the same value. @dfn{Normalization} consistsof doing this repeatedly until the number is normalized. Two distinctnormalized floating point numbers cannot be equal in value.(There is an exception to this rule: if the mantissa is zero, it isconsidered normalized. Another exception happens on certain machineswhere the exponent is as small as the representation can hold. Thenit is impossible to subtract @code{1} from the exponent, so a numbermay be normalized even if its fraction is less than @code{1/@var{b}}.)@node Floating Point Parameters@subsubsection Floating Point Parameters@pindex float.hThese macro definitions can be accessed by including the header file@file{float.h} in your program.Macro names starting with @samp{FLT_} refer to the @code{float} type,while names beginning with @samp{DBL_} refer to the @code{double} typeand names beginning with @samp{LDBL_} refer to the @code{long double}type. (Currently GCC does not support @code{long double} as a distinctdata type, so the values for the @samp{LDBL_} constants are equal to thecorresponding constants for the @code{double} type.)@refillOf these macros, only @code{FLT_RADIX} is guaranteed to be a constantexpression. The other macros listed here cannot be reliably used inplaces that require constant expressions, such as @samp{#if}preprocessing directives or in the dimensions of static arrays.Although the ANSI C standard specifies minimum and maximum values formost of these parameters, the GNU C implementation uses whatever valuesdescribe the floating point representation of the target machine. So inprinciple GNU C actually satisfies the ANSI C requirements only if thetarget machine is suitable. In practice, all the machines currentlysupported are suitable.@table @code@comment float.h@comment ANSI@item FLT_ROUNDSThis value characterizes the rounding mode for floating point addition.The following values indicate standard rounding modes:@need 750@table @code@item -1The mode is indeterminable.@item 0Rounding is towards zero.@item 1Rounding is to the nearest number.@item 2Rounding is towards positive infinity.@item 3Rounding is towards negative infinity.@end table@noindentAny other value represents a machine-dependent nonstandard roundingmode.On most machines, the value is @code{1}, in accordance with the IEEEstandard for floating point.Here is a table showing how certain values round for each possible valueof @code{FLT_ROUNDS}, if the other aspects of the representation matchthe IEEE single-precision standard.@smallexample 0 1 2 3 1.00000003 1.0 1.0 1.00000012 1.0 1.00000007 1.0 1.00000012 1.00000012 1.0-1.00000003 -1.0 -1.0 -1.0 -1.00000012-1.00000007 -1.0 -1.00000012 -1.0 -1.00000012@end smallexample@comment float.h@comment ANSI@item FLT_RADIXThis is the value of the base, or radix, of exponent representation.This is guaranteed to be a constant expression, unlike the other macrosdescribed in this section. The value is 2 on all machines we know ofexcept the IBM 360 and derivatives.@comment float.h@comment ANSI@item FLT_MANT_DIGThis is the number of base-@code{FLT_RADIX} digits in the floating pointmantissa for the @code{float} data type. The following expressionyields @code{1.0} (even though mathematically it should not) due to thelimited number of mantissa digits:@smallexamplefloat radix = FLT_RADIX;1.0f + 1.0f / radix / radix / @dots{} / radix@end smallexample@noindentwhere @code{radix} appears @code{FLT_MANT_DIG} times.@comment float.h@comment ANSI@item DBL_MANT_DIG@itemx LDBL_MANT_DIGThis is the number of base-@code{FLT_RADIX} digits in the floating pointmantissa for the data types @code{double} and @code{long double},respectively.@comment Extra blank lines make it look better.@comment float.h@comment ANSI@item FLT_DIGThis is the number of decimal digits of precision for the @code{float}data type. Technically, if @var{p} and @var{b} are the precision andbase (respectively) for the representation, then the decimal precision@var{q} is the maximum number of decimal digits such that any floatingpoint number with @var{q} base 10 digits can be rounded to a floatingpoint number with @var{p} base @var{b} digits and back again, withoutchange to the @var{q} decimal digits.The value of this macro is supposed to be at least @code{6}, to satisfyANSI C.@comment float.h@comment ANSI@item DBL_DIG@itemx LDBL_DIGThese are similar to @code{FLT_DIG}, but for the data types@code{double} and @code{long double}, respectively. The values of thesemacros are supposed to be at least @code{10}.@comment float.h@comment ANSI@item FLT_MIN_EXPThis is the smallest possible exponent value for type @code{float}.More precisely, is the minimum negative integer such that the value@code{FLT_RADIX} raised to this power minus 1 can be represented as anormalized floating point number of type @code{float}.@comment float.h@comment ANSI@item DBL_MIN_EXP@itemx LDBL_MIN_EXPThese are similar to @code{FLT_MIN_EXP}, but for the data types@code{double} and @code{long double}, respectively.@comment float.h@comment ANSI@item FLT_MIN_10_EXPThis is the minimum negative integer such that @code{10} raised to thispower minus 1 can be represented as a normalized floating point numberof type @code{float}. This is supposed to be @code{-37} or even less.@comment float.h@comment ANSI@item DBL_MIN_10_EXP@itemx LDBL_MIN_10_EXPThese are similar to @code{FLT_MIN_10_EXP}, but for the data types@code{double} and @code{long double}, respectively.@comment float.h@comment ANSI@item FLT_MAX_EXPThis is the largest possible exponent value for type @code{float}. Moreprecisely, this is the maximum positive integer such that value@code{FLT_RADIX} raised to this power minus 1 can be represented as afloating point number of type @code{float}.@comment float.h@comment ANSI@item DBL_MAX_EXP@itemx LDBL_MAX_EXPThese are similar to @code{FLT_MAX_EXP}, but for the data types@code{double} and @code{long double}, respectively.@comment float.h@comment ANSI@item FLT_MAX_10_EXPThis is the maximum positive integer such that @code{10} raised to thispower minus 1 can be represented as a normalized floating point numberof type @code{float}. This is supposed to be at least @code{37}.@comment float.h@comment ANSI@item DBL_MAX_10_EXP@itemx LDBL_MAX_10_EXPThese are similar to @code{FLT_MAX_10_EXP}, but for the data types@code{double} and @code{long double}, respectively.@comment float.h@comment ANSI@item FLT_MAXThe value of this macro is the maximum number representable in type@code{float}. It is supposed to be at least @code{1E+37}. The valuehas type @code{float}.The smallest representable number is @code{- FLT_MAX}.@comment float.h@comment ANSI@item DBL_MAX@itemx LDBL_MAXThese are similar to @code{FLT_MAX}, but for the data types@code{double} and @code{long double}, respectively. The type of themacro's value is the same as the type it describes.@comment float.h@comment ANSI@item FLT_MINThe value of this macro is the minimum normalized positive floatingpoint number that is representable in type @code{float}. It is supposedto be no more than @code{1E-37}.@comment float.h@comment ANSI@item DBL_MIN@itemx LDBL_MINThese are similar to @code{FLT_MIN}, but for the data types@code{double} and @code{long double}, respectively. The type of themacro's value is the same as the type it describes.@comment float.h@comment ANSI@item FLT_EPSILONThis is the minimum positive floating point number of type @code{float}such that @code{1.0 + FLT_EPSILON != 1.0} is true. It's supposed tobe no greater than @code{1E-5}.@comment float.h@comment ANSI@item DBL_EPSILON@itemx LDBL_EPSILONThese are similar to @code{FLT_EPSILON}, but for the data types@code{double} and @code{long double}, respectively. The type of themacro's value is the same as the type it describes. The values are notsupposed to be greater than @code{1E-9}.@end table@node IEEE Floating Point@subsubsection IEEE Floating Point@cindex IEEE floating point representation @cindex floating point, IEEEHere is an example showing how the floating type measurements come outfor the most common floating point representation, specified by the@cite{IEEE Standard for Binary Floating Point Arithmetic (ANSI/IEEE Std754-1985)}. Nearly all computers designed since the 1980s use thisformat.The IEEE single-precision float representation uses a base of 2. Thereis a sign bit, a mantissa with 23 bits plus one hidden bit (so the totalprecision is 24 base-2 digits), and an 8-bit exponent that can representvalues in the range -125 to 128, inclusive.So, for an implementation that uses this representation for the@code{float} data type, appropriate values for the correspondingparameters are:@smallexampleFLT_RADIX 2FLT_MANT_DIG 24FLT_DIG 6FLT_MIN_EXP -125FLT_MIN_10_EXP -37FLT_MAX_EXP 128FLT_MAX_10_EXP +38FLT_MIN 1.17549435E-38FFLT_MAX 3.40282347E+38FFLT_EPSILON 1.19209290E-07F@end smallexampleHere are the values for the @code{double} data type:@smallexampleDBL_MANT_DIG 53DBL_DIG 15DBL_MIN_EXP -1021DBL_MIN_10_EXP -307DBL_MAX_EXP 1024DBL_MAX_10_EXP 308DBL_MAX 1.7976931348623157E+308DBL_MIN 2.2250738585072014E-308DBL_EPSILON 2.2204460492503131E-016@end smallexample@node Structure Measurement@subsection Structure Field Offset MeasurementYou can use @code{offsetof} to measure the location within a structuretype of a particular structure member.@comment stddef.h@comment ANSI@deftypefn {Macro} size_t offsetof (@var{type}, @var{member})This expands to a integer constant expression that is the offset of thestructure member named @var{member} in a the structure type @var{type}.For example, @code{offsetof (struct s, elem)} is the offset, in bytes,of the member @code{elem} in a @code{struct s}.This macro won't work if @var{member} is a bit field; you get an errorfrom the C compiler in that case.@end deftypefn
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -