source: public/doc/gnu-c/Floating-Constants.html@ 02598c2

Last change on this file since 02598c2 was 02598c2, checked in by Mikhail Kirillov <w96k@…>, on Oct 6, 2022 at 12:36:29 PM

Add gnu-c

  • Property mode set to 100644
File size: 6.3 KB
Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<!-- Copyright (C) 2022 Richard Stallman and Free Software Foundation, Inc.
4
5(The work of Trevis Rothwell and Nelson Beebe has been assigned or
6licensed to the FSF.)
7
8Permission is granted to copy, distribute and/or modify this document
9under the terms of the GNU Free Documentation License, Version 1.3 or
10any later version published by the Free Software Foundation; with the
11Invariant Sections being "GNU General Public License," with the
12Front-Cover Texts being "A GNU Manual," and with the Back-Cover
13Texts as in (a) below. A copy of the license is included in the
14section entitled "GNU Free Documentation License."
15
16(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
17modify this GNU manual. Buying copies from the FSF supports it in
18developing GNU and promoting software freedom." -->
19<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
20<head>
21<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
22<title>Floating Constants (GNU C Language Manual)</title>
23
24<meta name="description" content="Floating Constants (GNU C Language Manual)">
25<meta name="keywords" content="Floating Constants (GNU C Language Manual)">
26<meta name="resource-type" content="document">
27<meta name="distribution" content="global">
28<meta name="Generator" content="makeinfo">
29<link href="index.html" rel="start" title="Top">
30<link href="Symbol-Index.html" rel="index" title="Symbol Index">
31<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
32<link href="Constants.html" rel="up" title="Constants">
33<link href="Imaginary-Constants.html" rel="next" title="Imaginary Constants">
34<link href="Integer-Const-Type.html" rel="prev" title="Integer Const Type">
35<style type="text/css">
36<!--
37a.summary-letter {text-decoration: none}
38blockquote.indentedblock {margin-right: 0em}
39div.display {margin-left: 3.2em}
40div.example {margin-left: 3.2em}
41div.lisp {margin-left: 3.2em}
42kbd {font-style: oblique}
43pre.display {font-family: inherit}
44pre.format {font-family: inherit}
45pre.menu-comment {font-family: serif}
46pre.menu-preformatted {font-family: serif}
47span.nolinebreak {white-space: nowrap}
48span.roman {font-family: initial; font-weight: normal}
49span.sansserif {font-family: sans-serif; font-weight: normal}
50ul.no-bullet {list-style: none}
51-->
52</style>
53
54
55</head>
56
57<body lang="en">
58<span id="Floating-Constants"></span><div class="header">
59<p>
60Next: <a href="Imaginary-Constants.html" accesskey="n" rel="next">Imaginary Constants</a>, Previous: <a href="Integer-Const-Type.html" accesskey="p" rel="prev">Integer Const Type</a>, Up: <a href="Constants.html" accesskey="u" rel="up">Constants</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
61</div>
62<hr>
63<span id="Floating_002dPoint-Constants"></span><h3 class="section">12.3 Floating-Point Constants</h3>
64<span id="index-floating_002dpoint-constants"></span>
65<span id="index-constants_002c-floating_002dpoint"></span>
66
67<p>A floating-point constant must have either a decimal point, an
68exponent-of-ten, or both; they distinguish it from an integer
69constant.
70</p>
71<p>To indicate an exponent, write &lsquo;<samp>e</samp>&rsquo; or &lsquo;<samp>E</samp>&rsquo;. The exponent
72value follows. It is always written as a decimal number; it can
73optionally start with a sign. The exponent <var>n</var> means to multiply
74the constant&rsquo;s value by ten to the <var>n</var>th power.
75</p>
76<p>Thus, &lsquo;<samp>1500.0</samp>&rsquo;, &lsquo;<samp>15e2</samp>&rsquo;, &lsquo;<samp>15e+2</samp>&rsquo;, &lsquo;<samp>15.0e2</samp>&rsquo;,
77&lsquo;<samp>1.5e+3</samp>&rsquo;, &lsquo;<samp>.15e4</samp>&rsquo;, and &lsquo;<samp>15000e-1</samp>&rsquo; are six ways of
78writing a floating-point number whose value is 1500. They are all
79equivalent.
80</p>
81<p>Here are more examples with decimal points:
82</p>
83<div class="example">
84<pre class="example">1.0
851000.
863.14159
87.05
88.0005
89</pre></div>
90
91<p>For each of them, here are some equivalent constants written with
92exponents:
93</p>
94<div class="example">
95<pre class="example">1e0, 1.0000e0
96100e1, 100e+1, 100E+1, 1e3, 10000e-1
973.14159e0
985e-2, .0005e+2, 5E-2, .0005E2
99.05e-2
100</pre></div>
101
102<p>A floating-point constant normally has type <code>double</code>. You can
103force it to type <code>float</code> by adding &lsquo;<samp>f</samp>&rsquo; or &lsquo;<samp>F</samp>&rsquo;
104at the end. For example,
105</p>
106<div class="example">
107<pre class="example">3.14159f
1083.14159e0f
1091000.f
110100E1F
111.0005f
112.05e-2f
113</pre></div>
114
115<p>Likewise, &lsquo;<samp>l</samp>&rsquo; or &lsquo;<samp>L</samp>&rsquo; at the end forces the constant
116to type <code>long double</code>.
117</p>
118<p>You can use exponents in hexadecimal floating constants, but since
119&lsquo;<samp>e</samp>&rsquo; would be interpreted as a hexadecimal digit, the character
120&lsquo;<samp>p</samp>&rsquo; or &lsquo;<samp>P</samp>&rsquo; (for &ldquo;power&rdquo;) indicates an exponent.
121</p>
122<p>The exponent in a hexadecimal floating constant is a possibly-signed
123decimal integer that specifies a power of 2 (<em>not</em> 10 or 16) to
124multiply into the number.
125</p>
126<p>Here are some examples:
127</p>
128<div class="example">
129<pre class="example">0xAp2 // <span class="roman">40 in decimal</span>
1300xAp-1 // <span class="roman">5 in decimal</span>
1310x2.0Bp4 // <span class="roman">16.75 decimal</span>
1320xE.2p3 // <span class="roman">121 decimal</span>
1330x123.ABCp0 // <span class="roman">291.6708984375 in decimal</span>
1340x123.ABCp4 // <span class="roman">4666.734375 in decimal</span>
1350x100p-8 // <span class="roman">1</span>
1360x10p-4 // <span class="roman">1</span>
1370x1p+4 // <span class="roman">16</span>
1380x1p+8 // <span class="roman">256</span>
139</pre></div>
140
141<p>See <a href="Floating_002dPoint-Data-Types.html">Floating-Point Data Types</a>.
142</p>
143<hr>
144<div class="header">
145<p>
146Next: <a href="Imaginary-Constants.html" accesskey="n" rel="next">Imaginary Constants</a>, Previous: <a href="Integer-Const-Type.html" accesskey="p" rel="prev">Integer Const Type</a>, Up: <a href="Constants.html" accesskey="u" rel="up">Constants</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
147</div>
148
149
150
151</body>
152</html>
Note: See TracBrowser for help on using the repository browser.