]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/doc/html/math_toolkit/exact_typdefs.html
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / math / doc / html / math_toolkit / exact_typdefs.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Exact-Width Floating-Point typedefs</title>
5 <link rel="stylesheet" href="../math.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
7 <link rel="home" href="../index.html" title="Math Toolkit 2.5.1">
8 <link rel="up" href="../cstdfloat.html" title="Chapter&#160;3.&#160;Specified-width floating-point typedefs">
9 <link rel="prev" href="rationale.html" title="Rationale">
10 <link rel="next" href="minimum_typdefs.html" title="Minimum-width floating-point typedefs">
11 </head>
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
15 <td align="center"><a href="../../../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../../../more/index.htm">More</a></td>
20 </tr></table>
21 <hr>
22 <div class="spirit-nav">
23 <a accesskey="p" href="rationale.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../cstdfloat.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="minimum_typdefs.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
24 </div>
25 <div class="section">
26 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
27 <a name="math_toolkit.exact_typdefs"></a><a class="link" href="exact_typdefs.html" title="Exact-Width Floating-Point typedefs">Exact-Width Floating-Point
28 <code class="computeroutput"><span class="keyword">typedef</span></code>s</a>
29 </h2></div></div></div>
30 <p>
31 The <code class="computeroutput"><span class="keyword">typedef</span> <span class="keyword">float</span><span class="special">#</span><span class="identifier">_t</span></code>, with
32 # replaced by the width, designates a floating-point type of exactly # bits.
33 For example <code class="computeroutput"><span class="identifier">float32_t</span></code> denotes
34 a single-precision floating-point type with approximately 7 decimal digits
35 of precision (equivalent to binary32 in <a href="http://en.wikipedia.org/wiki/IEEE_floating_point" target="_top">IEEE_floating_point</a>).
36 </p>
37 <p>
38 Floating-point types in C and C++ are specified to be allowed to have (optionally)
39 implementation-specific widths and formats. However, if a platform supports
40 underlying floating-point types (conformant with <a href="http://en.wikipedia.org/wiki/IEEE_floating_point" target="_top">IEEE_floating_point</a>)
41 with widths of 16, 32, 64, 80, 128 bits, or any combination thereof, then
42 <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">cstdfloat</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
43 does provide the corresponding <code class="computeroutput"><span class="keyword">typedef</span></code>s
44 <code class="computeroutput"><span class="identifier">float16_t</span><span class="special">,</span>
45 <span class="identifier">float32_t</span><span class="special">,</span>
46 <span class="identifier">float64_t</span><span class="special">,</span>
47 <span class="identifier">float80_t</span><span class="special">,</span>
48 <span class="identifier">float128_t</span><span class="special">,</span></code>
49 their corresponding least and fast types, and the corresponding maximum-width
50 type.
51 </p>
52 <h5>
53 <a name="math_toolkit.exact_typdefs.h0"></a>
54 <span class="phrase"><a name="math_toolkit.exact_typdefs.how_to_tell_which_widths_are_sup"></a></span><a class="link" href="exact_typdefs.html#math_toolkit.exact_typdefs.how_to_tell_which_widths_are_sup">How to
55 tell which widths are supported</a>
56 </h5>
57 <p>
58 The definition (or not) of a <a class="link" href="macros.html" title="Floating-Point Constant Macros">floating-point
59 constant macro</a> is a way to test if a <span class="bold"><strong>specific
60 width floating-point</strong></span> is available on a platform.
61 </p>
62 <pre class="programlisting"><span class="preprocessor">#if</span> <span class="identifier">defined</span><span class="special">(</span><span class="identifier">BOOST_FLOAT16_C</span><span class="special">)</span>
63 <span class="comment">// Can use boost::float16_t, perhaps a proposed __short_float.</span>
64 <span class="comment">// P0192R1, Adding Fundamental Type for Short Float,</span>
65 <span class="comment">// Boris Fomitchev, Sergei Nikolaev, Olivier Giroux, Lawrence Crowl, 2016 Feb14</span>
66 <span class="comment">// http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2016.pdf</span>
67 <span class="preprocessor">#endif</span>
68
69 <span class="preprocessor">#if</span> <span class="identifier">defined</span><span class="special">(</span><span class="identifier">BOOST_FLOAT32_C</span><span class="special">)</span>
70 <span class="comment">// Can use boost::float32_t, usually type `float`.</span>
71 <span class="preprocessor">#endif</span>
72
73 <span class="preprocessor">#if</span> <span class="identifier">defined</span><span class="special">(</span><span class="identifier">BOOST_FLOAT64_C</span><span class="special">)</span>
74 <span class="comment">// Can use boost::float64_t, usually type `double`, and sometimes also type `long double`.</span>
75 <span class="preprocessor">#endif</span>
76
77 <span class="preprocessor">#if</span> <span class="identifier">defined</span><span class="special">(</span><span class="identifier">BOOST_FLOAT80_C</span><span class="special">)</span>
78 <span class="comment">// Can use boost::float80_t, sometimes type `long double`.</span>
79 <span class="preprocessor">#endif</span>
80
81 <span class="preprocessor">#if</span> <span class="identifier">defined</span><span class="special">(</span><span class="identifier">BOOST_FLOAT128_C</span><span class="special">)</span>
82 <span class="comment">// Can use boost::float128_t. Sometimes type `__float128` or `_Quad`.</span>
83 <span class="preprocessor">#endif</span>
84 </pre>
85 <p>
86 This can be used to write code which will compile and run (albeit differently)
87 on several platforms. Without these tests, if a width, say <code class="computeroutput"><span class="identifier">float128_t</span></code>
88 is not supported, then compilation would fail. (It is, of course, rare for
89 <code class="computeroutput"><span class="identifier">float64_t</span></code> or <code class="computeroutput"><span class="identifier">float32_t</span></code> not to be supported).
90 </p>
91 <p>
92 The number of bits in just the significand can be determined using:
93 </p>
94 <pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">floatmax_t</span><span class="special">&gt;::</span><span class="identifier">digits</span>
95 </pre>
96 <p>
97 and from this one can safely infer the total number of bits because the type
98 must be IEEE754 format, <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">floatmax_t</span><span class="special">&gt;::</span><span class="identifier">is_iec559</span>
99 <span class="special">==</span> <span class="keyword">true</span></code>,
100 so, for example, if <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">floatmax_t</span><span class="special">&gt;::</span><span class="identifier">digits</span> <span class="special">==</span> <span class="number">113</span></code>, then
101 <code class="computeroutput"><span class="identifier">floatmax_t</span></code> must be<code class="computeroutput"> <span class="identifier">float128_t</span></code>.
102 </p>
103 <p>
104 The <span class="bold"><strong>total</strong></span> number of bits using <code class="computeroutput"><span class="identifier">floatmax_t</span></code> can be found thus:
105 </p>
106 <pre class="programlisting"><span class="keyword">const</span> <span class="keyword">int</span> <span class="identifier">fpbits</span> <span class="special">=</span>
107 <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">floatmax_t</span><span class="special">&gt;::</span><span class="identifier">digits</span> <span class="special">==</span> <span class="number">113</span><span class="special">)</span> <span class="special">?</span> <span class="number">128</span> <span class="special">:</span>
108 <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">floatmax_t</span><span class="special">&gt;::</span><span class="identifier">digits</span> <span class="special">==</span> <span class="number">64</span><span class="special">)</span> <span class="special">?</span> <span class="number">80</span> <span class="special">:</span>
109 <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">floatmax_t</span><span class="special">&gt;::</span><span class="identifier">digits</span> <span class="special">==</span> <span class="number">53</span><span class="special">)</span> <span class="special">?</span> <span class="number">64</span> <span class="special">:</span>
110 <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">floatmax_t</span><span class="special">&gt;::</span><span class="identifier">digits</span> <span class="special">==</span> <span class="number">24</span><span class="special">)</span> <span class="special">?</span> <span class="number">32</span> <span class="special">:</span>
111 <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">floatmax_t</span><span class="special">&gt;::</span><span class="identifier">digits</span> <span class="special">==</span> <span class="number">11</span><span class="special">)</span> <span class="special">?</span> <span class="number">16</span> <span class="special">:</span>
112 <span class="number">0</span><span class="special">;</span> <span class="comment">// Unknown - not IEEE754 format.</span>
113 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">fpbits</span> <span class="special">&lt;&lt;</span> <span class="string">" bits."</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
114 </pre>
115 <p>
116 and the number of 'guaranteed' decimal digits using
117 </p>
118 <pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">floatmax_t</span><span class="special">&gt;::</span><span class="identifier">digits10</span>
119 </pre>
120 <p>
121 and the maximum number of possibly significant decimal digits using
122 </p>
123 <pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">floatmax_t</span><span class="special">&gt;::</span><span class="identifier">max_digits10</span>
124 </pre>
125 <div class="tip"><table border="0" summary="Tip">
126 <tr>
127 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../../../doc/src/images/tip.png"></td>
128 <th align="left">Tip</th>
129 </tr>
130 <tr><td align="left" valign="top"><p>
131 <code class="computeroutput"><span class="identifier">max_digits10</span></code> is not always
132 supported, but can be calculated at compile-time using the Kahan formula,
133 <code class="computeroutput"><span class="number">2</span> <span class="special">+</span>
134 <span class="identifier">binary_digits</span> <span class="special">*</span>
135 <span class="number">0.3010</span></code> which can be calculated <span class="bold"><strong>at compile time</strong></span> using <code class="computeroutput"><span class="number">2</span>
136 <span class="special">+</span> <span class="identifier">binary_digits</span>
137 <span class="special">*</span> <span class="number">3010</span><span class="special">/</span><span class="number">10000</span></code>.
138 </p></td></tr>
139 </table></div>
140 <div class="note"><table border="0" summary="Note">
141 <tr>
142 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td>
143 <th align="left">Note</th>
144 </tr>
145 <tr><td align="left" valign="top">
146 <p>
147 One could test that
148 </p>
149 <p>
150 std::is_same&lt;boost::floatmax_t, boost::float128_t&gt;::value == true
151 </p>
152 <p>
153 but this would fail to compile on a platform where <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">float128_t</span></code>
154 is not defined. So it is better to use the MACROs <code class="computeroutput"><span class="identifier">BOOST_FLOATnnn_C</span></code>.
155 </p>
156 </td></tr>
157 </table></div>
158 </div>
159 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
160 <td align="left"></td>
161 <td align="right"><div class="copyright-footer">Copyright &#169; 2006-2010, 2012-2014 Nikhar Agrawal,
162 Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert
163 Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;de, Gautam Sewani,
164 Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang<p>
165 Distributed under the Boost Software License, Version 1.0. (See accompanying
166 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
167 </p>
168 </div></td>
169 </tr></table>
170 <hr>
171 <div class="spirit-nav">
172 <a accesskey="p" href="rationale.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../cstdfloat.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="minimum_typdefs.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
173 </div>
174 </body>
175 </html>