Stałe zmiennoprzecinkowe języka CC Floating-Point Constants
"Stała zmiennoprzecinkowa" jest liczbą dziesiętną, która reprezentuje podpisany numer rzeczywisty.A "floating-point constant" is a decimal number that represents a signed real number. Reprezentacja podpisanej liczby rzeczywistej zawiera część całkowitą, część ułamkową i wykładnik.The representation of a signed real number includes an integer portion, a fractional portion, and an exponent. Używaj stałych zmiennoprzecinkowych do reprezentowania wartości zmiennoprzecinkowych, których nie można zmienić.Use floating-point constants to represent floating-point values that cannot be changed.
SkładniaSyntax
zmiennoprzecinkowe — stała:floating-point-constant:
dwuargumentowy — wykładnik stałej —wybór sufiksu zmiennoprzecinkowego fractional-constant exponent-partopt floating-suffixopt
wykładnik sekwencji cyfr —wybór sufiksu zmiennoprzecinkowego części digit-sequence exponent-part floating-suffixopt
stała ułamkowa:fractional-constant:
wybór sekwencji cyfr . digit-sequenceopt . Sekwencja cyfrdigit-sequence
sekwencja cyfr . digit-sequence .
część wykładnika:exponent-part:
cyfra za podpisanie e -sekwencji e signopt digit-sequence
Cyfra za podpisanie E -sekwencji E signopt digit-sequence
znak: jedno zsign: one of
+ - + -
sekwencja cyfr:digit-sequence:
kontrol digit
cyfra cyfra digit-sequence digit
sufiks zmiennoprzecinkowy: jeden zfloating-suffix: one of
f l l f l F L
Możesz pominąć cyfry przed punktem dziesiętnym (część całkowitą wartości) lub cyfry po przecinku dziesiętnym (części ułamkowej), ale nie oba.You can omit either the digits before the decimal point (the integer portion of the value) or the digits after the decimal point (the fractional portion), but not both. Możesz opuścić punkt dziesiętny tylko wtedy, gdy dołączysz wykładnik.You can leave out the decimal point only if you include an exponent. Znaki odstępu nie mogą oddzielić cyfr ani znaków stałej.No white-space characters can separate the digits or characters of the constant.
Poniższe przykłady ilustrują niektóre formy stałych i wyrażeń zmiennoprzecinkowych:The following examples illustrate some forms of floating-point constants and expressions:
15.75
1.575E1 /* = 15.75 */
1575e-2 /* = 15.75 */
-2.5e-3 /* = -0.0025 */
25E-4 /* = 0.0025 */
Stałe zmiennoprzecinkowe są dodatnie, chyba że są poprzedzone znakiem minus ( - ).Floating-point constants are positive unless they are preceded by a minus sign (-). W takim przypadku znak minus jest traktowany jako jednoargumentowy operator negacji arytmetycznej.In this case, the minus sign is treated as a unary arithmetic negation operator. Stałe zmiennoprzecinkowe mają typ float
, double
lub long double
.Floating-point constants have type float
, double
, or long double
.
Stała zmiennoprzecinkowa bez sufiksu f, f, l lub l ma typ double
.A floating-point constant without an f, F, l, or L suffix has type double
. Jeśli litera f lub f jest sufiksem, stała ma typ float
.If the letter f or F is the suffix, the constant has type float
. Jeśli sufiks jest poprzedzony literą l lub l, ma typ long double
.If suffixed by the letter l or L, it has type long double
. Na przykład:For example:
10.0L /* Has type long double */
10.0F /* Has type float */
Należy zauważyć, że kompilator języka Microsoft C wewnętrznie reprezentuje ten long double
sam typ double
.Note that the Microsoft C compiler internally represents long double
the same as type double
. Zobacz Magazyn typów podstawowych , aby uzyskać informacje o typie double
, float
i long double
.See Storage of Basic Types for information about type double
, float
, and long double
.
Można pominąć część całkowitą stałej zmiennoprzecinkowej, jak pokazano w poniższych przykładach.You can omit the integer portion of the floating-point constant, as shown in the following examples. Liczba. 75 może być wyrażona na wiele sposobów, w tym:The number .75 can be expressed in many ways, including the following:
.0075e2
0.075e1
.075e1
75e-2