File: ieee754.html

package info (click to toggle)
speedcrunch 0.12.0-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 14,160 kB
  • sloc: cpp: 17,603; ansic: 14,719; python: 569; sh: 236; xml: 135; makefile: 23
file content (267 lines) | stat: -rw-r--r-- 11,129 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" lang="en_US">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>IEEE-754 Functions</title>
    
    <link rel="stylesheet" href="../_static/quark.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="../" type="text/css" />
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="top" title="SpeedCrunch 0.12 documentation" href="../contents.html" />
    <link rel="up" title="Reference" href="index.html" />
    <link rel="next" title="Constants" href="constants.html" />
    <link rel="prev" title="Statistical Functions" href="statistical.html" /> 
  </head>
  <body role="document">
  <table class="navbar navbar-top">
    
  <tr>
    <td width="50%">
      <a class="nav-item nav-item-0" 
         href="../contents.html">SpeedCrunch 0.12 documentation</a> &#187; <a class="nav-item nav-item-1"
             href="index.html">Reference</a>
          
    </td>

    <td align="right" width="50%">
      <a class="rel-item rel-item-1"
           href="statistical.html"
           title="Statistical Functions"
           accesskey="P">previous</a>
         | 
      <a class="rel-item rel-item-2"
           href="constants.html"
           title="Constants"
           accesskey="N">next</a>
         | 
      <a class="rel-item rel-item-3"
           href="../sc-functionindex.html"
           title="Function Index"
           >functions</a>
         | 
      <a class="rel-item rel-item-4"
           href="../genindex.html"
           title="General Index"
           accesskey="I">index</a>
        
      
    </td>

  </tr>

  </table>


    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <div class="section" id="ieee-754-functions">
<h1>IEEE-754 Functions</h1>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.12.</span></p>
</div>
<p>IEEE-754 is a standard for the representation of and computations with floating point
numbers in binary systems. It is widely used by floating point implementations in
CPUs. These functions implement encoding and decoding binary representations of floating point
numbers according to IEEE-754.</p>
<p>An IEEE-754 binary float consists of three parts: a sign bit, the exponent and the significand
(sometimes called the mantissa). From these parts, the value is then calculated using the
following formula: <code class="docutils literal"><span class="pre">-1</span> <span class="pre">^</span> <span class="pre">sign</span> <span class="pre">*</span> <span class="pre">2</span> <span class="pre">^</span> <span class="pre">(exponent</span> <span class="pre">-</span> <span class="pre">bias)</span> <span class="pre">*</span> <span class="pre">1.significand</span></code>.  The standard defines
multiple binary formats of different sizes that all follow these rules, but differ in
the number of bits allocated for the exponent and significand. The bias for the default
formats is defined as <code class="docutils literal"><span class="pre">bias</span> <span class="pre">=</span> <span class="pre">(2</span> <span class="pre">^</span> <span class="pre">(exponent_bits</span> <span class="pre">-</span> <span class="pre">1))</span> <span class="pre">-</span> <span class="pre">1</span></code>.
See <a class="reference external" href="http://chrishecker.com/images/f/fb/Gdmfp.pdf">this article</a> for a more detailed introduction into the subject.</p>
<p>The following binary float formats are defined by the standard:</p>
<table border="1" class="docutils">
<colgroup>
<col width="22%" />
<col width="30%" />
<col width="22%" />
<col width="27%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Name</th>
<th class="head">Also known as</th>
<th class="head">Exponent bits</th>
<th class="head">Significand bits</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><code class="docutils literal"><span class="pre">binary16</span></code></td>
<td>Half precision</td>
<td>5</td>
<td>10</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">binary32</span></code></td>
<td>Single precision</td>
<td>8</td>
<td>23</td>
</tr>
<tr class="row-even"><td><code class="docutils literal"><span class="pre">binary64</span></code></td>
<td>Double precision</td>
<td>11</td>
<td>52</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">binary128</span></code></td>
<td>Quad precision</td>
<td>15</td>
<td>112</td>
</tr>
</tbody>
</table>
<p>In many programming languages, the <code class="docutils literal"><span class="pre">binary32</span></code> format is available as <code class="docutils literal"><span class="pre">float</span></code>
and <code class="docutils literal"><span class="pre">binary64</span></code> is available as <code class="docutils literal"><span class="pre">double</span></code>.</p>
<dl class="function">
<dt id="sc.ieee754_encode">
<code class="descname">ieee754_encode</code><span class="sig-paren">(</span><em>x</em>; <em>exponent_bits</em>; <em>significand_bits</em><span class="optional">[</span>; <em>exponent_bias</em><span class="optional">]</span><span class="sig-paren">)</span></dt>
<dd><p>Encode a floating point number into a IEEE-754 binary representation.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>x</strong> &#8211; The floating point value to encode.</li>
<li><strong>exponent_bits</strong> &#8211; The length of the exponent part, in bits.</li>
<li><strong>significand_bits</strong> &#8211; The length of the significand part, in bits.</li>
<li><strong>exponent_bias</strong> &#8211; The exponent bias to use. Derived from the length of the
exponent if not specified.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="sc.ieee754_decode">
<code class="descname">ieee754_decode</code><span class="sig-paren">(</span><em>x</em>; <em>exponent_bits</em>; <em>significand_bits</em><span class="optional">[</span>; <em>exponent_bias</em><span class="optional">]</span><span class="sig-paren">)</span></dt>
<dd><p>Calculate the value of an IEEE-754 binary float.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>x</strong> &#8211; The binary float to decode.</li>
<li><strong>exponent_bits</strong> &#8211; The length of the exponent part, in bits.</li>
<li><strong>significand_bits</strong> &#8211; The length of the significand part, in bits.</li>
<li><strong>exponent_bias</strong> &#8211; The exponent bias to use. Derived from the length of the
exponent if not specified.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="sc.ieee754_half_encode">
<code class="descname">ieee754_half_encode</code><span class="sig-paren">(</span><em>x</em><span class="sig-paren">)</span></dt>
<dd><p>Encode <code class="docutils literal"><span class="pre">x</span></code> in the half-precision binary format.</p>
</dd></dl>

<dl class="function">
<dt id="sc.ieee754_half_decode">
<code class="descname">ieee754_half_decode</code><span class="sig-paren">(</span><em>x</em><span class="sig-paren">)</span></dt>
<dd><p>Decode the half-precision binary float <code class="docutils literal"><span class="pre">x</span></code>.</p>
</dd></dl>

<dl class="function">
<dt id="sc.ieee754_single_encode">
<code class="descname">ieee754_single_encode</code><span class="sig-paren">(</span><em>x</em><span class="sig-paren">)</span></dt>
<dd><p>Encode <code class="docutils literal"><span class="pre">x</span></code> in the single-precision binary format.</p>
</dd></dl>

<dl class="function">
<dt id="sc.ieee754_single_decode">
<code class="descname">ieee754_single_decode</code><span class="sig-paren">(</span><em>x</em><span class="sig-paren">)</span></dt>
<dd><p>Decode the single-precision binary float <code class="docutils literal"><span class="pre">x</span></code>.</p>
</dd></dl>

<dl class="function">
<dt id="sc.ieee754_double_encode">
<code class="descname">ieee754_double_encode</code><span class="sig-paren">(</span><em>x</em><span class="sig-paren">)</span></dt>
<dd><p>Encode <code class="docutils literal"><span class="pre">x</span></code> in the double-precision binary format.</p>
</dd></dl>

<dl class="function">
<dt id="sc.ieee754_double_decode">
<code class="descname">ieee754_double_decode</code><span class="sig-paren">(</span><em>x</em><span class="sig-paren">)</span></dt>
<dd><p>Decode the double-precision binary float <code class="docutils literal"><span class="pre">x</span></code>.</p>
</dd></dl>

<dl class="function">
<dt id="sc.ieee754_quad_encode">
<code class="descname">ieee754_quad_encode</code><span class="sig-paren">(</span><em>x</em><span class="sig-paren">)</span></dt>
<dd><p>Encode <code class="docutils literal"><span class="pre">x</span></code> in the quad-precision binary format.</p>
</dd></dl>

<dl class="function">
<dt id="sc.ieee754_quad_decode">
<code class="descname">ieee754_quad_decode</code><span class="sig-paren">(</span><em>x</em><span class="sig-paren">)</span></dt>
<dd><p>Decode the quad-precision binary float <code class="docutils literal"><span class="pre">x</span></code>.</p>
</dd></dl>

</div>


          </div>
      </div>
      <div class="clearer"></div>
    </div>
  <table class="navbar navbar-bottom">
    
  <tr>
    <td width="50%">
      <a class="nav-item nav-item-0" 
         href="../contents.html">SpeedCrunch 0.12 documentation</a> &#187; <a class="nav-item nav-item-1"
             href="index.html">Reference</a>
          
    </td>

    <td align="right" width="50%">
      <a class="rel-item rel-item-1"
           href="statistical.html"
           title="Statistical Functions"
           >previous</a>
         | 
      <a class="rel-item rel-item-2"
           href="constants.html"
           title="Constants"
           >next</a>
         | 
      <a class="rel-item rel-item-3"
           href="../sc-functionindex.html"
           title="Function Index"
           >functions</a>
         | 
      <a class="rel-item rel-item-4"
           href="../genindex.html"
           title="General Index"
           >index</a>
        
      
    </td>

  </tr>

    <tr>
      <td colspan="2" align="center">
        
    <div class="footer" role="contentinfo">
        &#169; Copyright 2016, The SpeedCrunch Developers.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.8.
    </div>
      </td>
    </tr>
  </table>

  </body>
</html>