⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 library_28.html

📁 linux_c函数,linux下编程必备的
💻 HTML
📖 第 1 页 / 共 4 页
字号:
floating point number with the same value.  <DFN>Normalization</DFN> consists
of doing this repeatedly until the number is normalized.  Two distinct
normalized floating point numbers cannot be equal in value.
<P>
(There is an exception to this rule: if the mantissa is zero, it is
considered normalized.  Another exception happens on certain machines
where the exponent is as small as the representation can hold.  Then
it is impossible to subtract <CODE>1</CODE> from the exponent, so a number
may be normalized even if its fraction is less than <CODE>1/<VAR>b</VAR></CODE>.)
<P>
<H4><A NAME="SEC489" HREF="library_toc.html#SEC489" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC489">Floating Point Parameters</A></H4>
<A NAME="IDX1974"></A>
<P>
These macro definitions can be accessed by including the header file
<TT>`float.h'</TT> in your program.
<P>
Macro names starting with <SAMP>`FLT_'</SAMP> refer to the <CODE>float</CODE> type,
while names beginning with <SAMP>`DBL_'</SAMP> refer to the <CODE>double</CODE> type
and names beginning with <SAMP>`LDBL_'</SAMP> refer to the <CODE>long double</CODE>
type.  (Currently GCC does not support <CODE>long double</CODE> as a distinct
data type, so the values for the <SAMP>`LDBL_'</SAMP> constants are equal to the
corresponding constants for the <CODE>double</CODE> type.)<P>
Of these macros, only <CODE>FLT_RADIX</CODE> is guaranteed to be a constant
expression.  The other macros listed here cannot be reliably used in
places that require constant expressions, such as <SAMP>`#if'</SAMP>
preprocessing directives or in the dimensions of static arrays.
<P>
Although the ANSI C standard specifies minimum and maximum values for
most of these parameters, the GNU C implementation uses whatever values
describe the floating point representation of the target machine.  So in
principle GNU C actually satisfies the ANSI C requirements only if the
target machine is suitable.  In practice, all the machines currently
supported are suitable.
<P>
<DL COMPACT>
<DT><CODE>FLT_ROUNDS</CODE>
<DD>This value characterizes the rounding mode for floating point addition.
The following values indicate standard rounding modes:
<P>
<DL COMPACT>
<DT><CODE>-1</CODE>
<DD>The mode is indeterminable.
<DT><CODE>0</CODE>
<DD>Rounding is towards zero.
<DT><CODE>1</CODE>
<DD>Rounding is to the nearest number.
<DT><CODE>2</CODE>
<DD>Rounding is towards positive infinity.
<DT><CODE>3</CODE>
<DD>Rounding is towards negative infinity.
</DL>
<P>
Any other value represents a machine-dependent nonstandard rounding
mode.
<P>
On most machines, the value is <CODE>1</CODE>, in accordance with the IEEE
standard for floating point.
<P>
Here is a table showing how certain values round for each possible value
of <CODE>FLT_ROUNDS</CODE>, if the other aspects of the representation match
the IEEE single-precision standard.
<P>
<PRE>
                 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
</PRE>
<P>
<LI>FLT_RADIX
This is the value of the base, or radix, of exponent representation.
This is guaranteed to be a constant expression, unlike the other macros
described in this section.  The value is 2 on all machines we know of
except the IBM 360 and derivatives.
<P>
<LI>FLT_MANT_DIG
This is the number of base-<CODE>FLT_RADIX</CODE> digits in the floating point
mantissa for the <CODE>float</CODE> data type.  The following expression
yields <CODE>1.0</CODE> (even though mathematically it should not) due to the
limited number of mantissa digits:
<P>
<PRE>
float radix = FLT_RADIX;

1.0f + 1.0f / radix / radix / ... / radix
</PRE>
<P>
where <CODE>radix</CODE> appears <CODE>FLT_MANT_DIG</CODE> times.
<P>
<LI>DBL_MANT_DIG
<LI>LDBL_MANT_DIG
This is the number of base-<CODE>FLT_RADIX</CODE> digits in the floating point
mantissa for the data types <CODE>double</CODE> and <CODE>long double</CODE>,
respectively.
<P>
<LI>FLT_DIG
<P>
This is the number of decimal digits of precision for the <CODE>float</CODE>
data type.  Technically, if <VAR>p</VAR> and <VAR>b</VAR> are the precision and
base (respectively) for the representation, then the decimal precision
<VAR>q</VAR> is the maximum number of decimal digits such that any floating
point number with <VAR>q</VAR> base 10 digits can be rounded to a floating
point number with <VAR>p</VAR> base <VAR>b</VAR> digits and back again, without
change to the <VAR>q</VAR> decimal digits.
<P>
The value of this macro is supposed to be at least <CODE>6</CODE>, to satisfy
ANSI C.
<P>
<LI>DBL_DIG
<LI>LDBL_DIG
<P>
These are similar to <CODE>FLT_DIG</CODE>, but for the data types
<CODE>double</CODE> and <CODE>long double</CODE>, respectively.  The values of these
macros are supposed to be at least <CODE>10</CODE>.
<P>
<LI>FLT_MIN_EXP
This is the smallest possible exponent value for type <CODE>float</CODE>.
More precisely, is the minimum negative integer such that the value
<CODE>FLT_RADIX</CODE> raised to this power minus 1 can be represented as a
normalized floating point number of type <CODE>float</CODE>.
<P>
<LI>DBL_MIN_EXP
<LI>LDBL_MIN_EXP
<P>
These are similar to <CODE>FLT_MIN_EXP</CODE>, but for the data types
<CODE>double</CODE> and <CODE>long double</CODE>, respectively.
<P>
<LI>FLT_MIN_10_EXP
This is the minimum negative integer such that <CODE>10</CODE> raised to this
power minus 1 can be represented as a normalized floating point number
of type <CODE>float</CODE>.  This is supposed to be <CODE>-37</CODE> or even less.
<P>
<LI>DBL_MIN_10_EXP
<LI>LDBL_MIN_10_EXP
These are similar to <CODE>FLT_MIN_10_EXP</CODE>, but for the data types
<CODE>double</CODE> and <CODE>long double</CODE>, respectively.
<P>
<LI>FLT_MAX_EXP
This is the largest possible exponent value for type <CODE>float</CODE>.  More
precisely, this is the maximum positive integer such that value
<CODE>FLT_RADIX</CODE> raised to this power minus 1 can be represented as a
floating point number of type <CODE>float</CODE>.
<P>
<LI>DBL_MAX_EXP
<LI>LDBL_MAX_EXP
These are similar to <CODE>FLT_MAX_EXP</CODE>, but for the data types
<CODE>double</CODE> and <CODE>long double</CODE>, respectively.
<P>
<LI>FLT_MAX_10_EXP
This is the maximum positive integer such that <CODE>10</CODE> raised to this
power minus 1 can be represented as a normalized floating point number
of type <CODE>float</CODE>.  This is supposed to be at least <CODE>37</CODE>.
<P>
<LI>DBL_MAX_10_EXP
<LI>LDBL_MAX_10_EXP
These are similar to <CODE>FLT_MAX_10_EXP</CODE>, but for the data types
<CODE>double</CODE> and <CODE>long double</CODE>, respectively.
<P>
<LI>FLT_MAX
<P>
The value of this macro is the maximum number representable in type
<CODE>float</CODE>.  It is supposed to be at least <CODE>1E+37</CODE>.  The value
has type <CODE>float</CODE>.
<P>
The smallest representable number is <CODE>- FLT_MAX</CODE>.
<P>
<LI>DBL_MAX
<LI>LDBL_MAX
<P>
These are similar to <CODE>FLT_MAX</CODE>, but for the data types
<CODE>double</CODE> and <CODE>long double</CODE>, respectively.  The type of the
macro's value is the same as the type it describes.
<P>
<LI>FLT_MIN
<P>
The value of this macro is the minimum normalized positive floating
point number that is representable in type <CODE>float</CODE>.  It is supposed
to be no more than <CODE>1E-37</CODE>.
<P>
<LI>DBL_MIN
<LI>LDBL_MIN
<P>
These are similar to <CODE>FLT_MIN</CODE>, but for the data types
<CODE>double</CODE> and <CODE>long double</CODE>, respectively.  The type of the
macro's value is the same as the type it describes.
<P>
<LI>FLT_EPSILON
<P>
This is the minimum positive floating point number of type <CODE>float</CODE>
such that <CODE>1.0 + FLT_EPSILON != 1.0</CODE> is true.  It's supposed to
be no greater than <CODE>1E-5</CODE>.
<P>
<LI>DBL_EPSILON
<LI>LDBL_EPSILON
<P>
These are similar to <CODE>FLT_EPSILON</CODE>, but for the data types
<CODE>double</CODE> and <CODE>long double</CODE>, respectively.  The type of the
macro's value is the same as the type it describes.  The values are not
supposed to be greater than <CODE>1E-9</CODE>.
</DL>
<P>
<A NAME="IDX1975"></A>
<A NAME="IDX1976"></A>
<H4><A NAME="SEC490" HREF="library_toc.html#SEC490" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC490">IEEE Floating Point</A></H4>
<P>
Here is an example showing how the floating type measurements come out
for the most common floating point representation, specified by the
<CITE>IEEE Standard for Binary Floating Point Arithmetic (ANSI/IEEE Std
754-1985)</CITE>.  Nearly all computers designed since the 1980s use this
format.
<P>
The IEEE single-precision float representation uses a base of 2.  There
is a sign bit, a mantissa with 23 bits plus one hidden bit (so the total
precision is 24 base-2 digits), and an 8-bit exponent that can represent
values in the range -125 to 128, inclusive.
<P>
So, for an implementation that uses this representation for the
<CODE>float</CODE> data type, appropriate values for the corresponding
parameters are:
<P>
<PRE>
FLT_RADIX                             2
FLT_MANT_DIG                         24
FLT_DIG                               6
FLT_MIN_EXP                        -125
FLT_MIN_10_EXP                      -37
FLT_MAX_EXP                         128
FLT_MAX_10_EXP                      +38
FLT_MIN                 1.17549435E-38F
FLT_MAX                 3.40282347E+38F
FLT_EPSILON             1.19209290E-07F
</PRE>
<P>
Here are the values for the <CODE>double</CODE> data type:
<P>
<PRE>
DBL_MANT_DIG                         53
DBL_DIG                              15
DBL_MIN_EXP                       -1021
DBL_MIN_10_EXP                     -307
DBL_MAX_EXP                        1024
DBL_MAX_10_EXP                      308
DBL_MAX         1.7976931348623157E+308
DBL_MIN         2.2250738585072014E-308
DBL_EPSILON     2.2204460492503131E-016
</PRE>
<P>
<H3><A NAME="SEC491" HREF="library_toc.html#SEC491" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC491">Structure Field Offset Measurement</A></H3>
<P>
You can use <CODE>offsetof</CODE> to measure the location within a structure
type of a particular structure member.
<P>
<A NAME="IDX1977"></A>
<U>Macro:</U> size_t <B>offsetof</B> <I>(<VAR>type</VAR>, <VAR>member</VAR>)</I><P>
This expands to a integer constant expression that is the offset of the
structure member named <VAR>member</VAR> in a the structure type <VAR>type</VAR>.
For example, <CODE>offsetof (struct s, elem)</CODE> is the offset, in bytes,
of the member <CODE>elem</CODE> in a <CODE>struct s</CODE>.
<P>
This macro won't work if <VAR>member</VAR> is a bit field; you get an error
from the C compiler in that case.
<P>
<P>Go to the <A HREF="library_27.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_27.html">previous</A>, <A HREF="library_29.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_29.html">next</A> section.<P>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -