This file is indexed.

/usr/share/gap/doc/ref/chap19.html is in gap-doc 4r8p6-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
<?xml version="1.0" encoding="UTF-8"?>

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

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>GAP (ref) - Chapter 19: Floats</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="generator" content="GAPDoc2HTML" />
<link rel="stylesheet" type="text/css" href="manual.css" />
<script src="manual.js" type="text/javascript"></script>
<script type="text/javascript">overwriteStyle();</script>
</head>
<body class="chap19"  onload="jscontent()">


<div class="chlinktop"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a>  <a href="chap1.html">1</a>  <a href="chap2.html">2</a>  <a href="chap3.html">3</a>  <a href="chap4.html">4</a>  <a href="chap5.html">5</a>  <a href="chap6.html">6</a>  <a href="chap7.html">7</a>  <a href="chap8.html">8</a>  <a href="chap9.html">9</a>  <a href="chap10.html">10</a>  <a href="chap11.html">11</a>  <a href="chap12.html">12</a>  <a href="chap13.html">13</a>  <a href="chap14.html">14</a>  <a href="chap15.html">15</a>  <a href="chap16.html">16</a>  <a href="chap17.html">17</a>  <a href="chap18.html">18</a>  <a href="chap19.html">19</a>  <a href="chap20.html">20</a>  <a href="chap21.html">21</a>  <a href="chap22.html">22</a>  <a href="chap23.html">23</a>  <a href="chap24.html">24</a>  <a href="chap25.html">25</a>  <a href="chap26.html">26</a>  <a href="chap27.html">27</a>  <a href="chap28.html">28</a>  <a href="chap29.html">29</a>  <a href="chap30.html">30</a>  <a href="chap31.html">31</a>  <a href="chap32.html">32</a>  <a href="chap33.html">33</a>  <a href="chap34.html">34</a>  <a href="chap35.html">35</a>  <a href="chap36.html">36</a>  <a href="chap37.html">37</a>  <a href="chap38.html">38</a>  <a href="chap39.html">39</a>  <a href="chap40.html">40</a>  <a href="chap41.html">41</a>  <a href="chap42.html">42</a>  <a href="chap43.html">43</a>  <a href="chap44.html">44</a>  <a href="chap45.html">45</a>  <a href="chap46.html">46</a>  <a href="chap47.html">47</a>  <a href="chap48.html">48</a>  <a href="chap49.html">49</a>  <a href="chap50.html">50</a>  <a href="chap51.html">51</a>  <a href="chap52.html">52</a>  <a href="chap53.html">53</a>  <a href="chap54.html">54</a>  <a href="chap55.html">55</a>  <a href="chap56.html">56</a>  <a href="chap57.html">57</a>  <a href="chap58.html">58</a>  <a href="chap59.html">59</a>  <a href="chap60.html">60</a>  <a href="chap61.html">61</a>  <a href="chap62.html">62</a>  <a href="chap63.html">63</a>  <a href="chap64.html">64</a>  <a href="chap65.html">65</a>  <a href="chap66.html">66</a>  <a href="chap67.html">67</a>  <a href="chap68.html">68</a>  <a href="chap69.html">69</a>  <a href="chap70.html">70</a>  <a href="chap71.html">71</a>  <a href="chap72.html">72</a>  <a href="chap73.html">73</a>  <a href="chap74.html">74</a>  <a href="chap75.html">75</a>  <a href="chap76.html">76</a>  <a href="chap77.html">77</a>  <a href="chap78.html">78</a>  <a href="chap79.html">79</a>  <a href="chap80.html">80</a>  <a href="chap81.html">81</a>  <a href="chap82.html">82</a>  <a href="chap83.html">83</a>  <a href="chap84.html">84</a>  <a href="chap85.html">85</a>  <a href="chap86.html">86</a>  <a href="chap87.html">87</a>  <a href="chapBib.html">Bib</a>  <a href="chapInd.html">Ind</a>  </div>

<div class="chlinkprevnexttop">&nbsp;<a href="chap0.html">[Top of Book]</a>&nbsp;  <a href="chap0.html#contents">[Contents]</a>&nbsp;  &nbsp;<a href="chap18.html">[Previous Chapter]</a>&nbsp;  &nbsp;<a href="chap20.html">[Next Chapter]</a>&nbsp;  </div>

<p id="mathjaxlink" class="pcenter"><a href="chap19_mj.html">[MathJax on]</a></p>
<p><a id="X81AA901181CA568F" name="X81AA901181CA568F"></a></p>
<div class="ChapSects"><a href="chap19.html#X81AA901181CA568F">19 <span class="Heading">Floats</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap19.html#X7B4092CA7ABB93B0">19.1 <span class="Heading">A sample run</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap19.html#X8606FDCE878850EF">19.2 <span class="Heading">Methods</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap19.html#X87B6780178314628">19.2-1 <span class="Heading">Mathematical operations</span></a>
</span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap19.html#X7BD96E0585D5A1EE">19.2-2 EqFloat</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap19.html#X7B3133497DDE839B">19.2-3 PrecisionFloat</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap19.html#X7D085DA987B0BDA6">19.2-4 <span class="Heading">Interval operations</span></a>
</span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap19.html#X7DB3BC76836E6219">19.2-5 IsPInfinity</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap19.html#X819050BF8403806E">19.2-6 FLOAT</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap19.html#X873D56F67DD887C5">19.2-7 Float</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap19.html#X7BCD34DC7B5A0521">19.2-8 Rat</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap19.html#X7A962B0983FA66E8">19.2-9 SetFloats</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap19.html#X845ACF3A78BD2771">19.3 <span class="Heading">High-precision-specific methods</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap19.html#X7E8F6EFB87A65F78">19.4 <span class="Heading">Complex arithmetic</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap19.html#X7E57B09C80136484">19.5 <span class="Heading">Interval-specific methods</span></a>
</span>
</div>
</div>

<h3>19 <span class="Heading">Floats</span></h3>

<p>Starting with version 4.5, <strong class="pkg">GAP</strong> has built-in support for floating-point numbers in machine format, and allows package to implement arbitrary-precision floating-point arithmetic in a uniform manner. For now, one such package, <strong class="pkg">Float</strong> exists, and is based on the arbitrary-precision routines in <strong class="pkg">mpfr</strong>.</p>

<p>A word of caution: <strong class="pkg">GAP</strong> deals primarily with algebraic objects, which can be represented exactly in a computer. Numerical imprecision means that floating-point numbers do not form a ring in the strict <strong class="pkg">GAP</strong> sense, because addition is in general not associative (<code class="code">(1.0e-100+1.0)-1.0</code> is not the same as <code class="code">1.0e-100+(1.0-1.0)</code>, in the default precision setting).</p>

<p>Most algorithms in <strong class="pkg">GAP</strong> which require ring elements will therefore not be applicable to floating-point elements. In some cases, such a notion would not even make any sense (what is the greatest common divisor of two floating-point numbers?)</p>

<p><a id="X7B4092CA7ABB93B0" name="X7B4092CA7ABB93B0"></a></p>

<h4>19.1 <span class="Heading">A sample run</span></h4>

<p>Floating-point numbers can be input into <strong class="pkg">GAP</strong> in the standard floating-point notation:</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">3.14;</span>
3.14
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">last^2/6;</span>
1.64327
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">h := 6.62606896e-34;</span>
6.62607e-34
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">pi := 4*Atan(1.0);</span>
3.14159
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">hbar := h/(2*pi);</span>
1.05457e-34
</pre></div>

<p>Floating-point numbers can also be created using <code class="code">Float</code>, from strings or rational numbers; and can be converted back using <code class="code">String,Rat,Int</code>.</p>

<p><strong class="pkg">GAP</strong> allows rational and floating-point numbers to be mixed in the elementary operations <code class="code">+,-,*,/</code>. However, floating-point numbers and rational numbers may not be compared. Conversions are performed using the creator <code class="code">Float</code>:</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Float("3.1416");</span>
3.1416
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Float(355/113);</span>
3.14159
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Rat(last);</span>
355/113
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Rat(0.33333);</span>
1/3
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Int(1.e10);</span>
10000000000
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Int(1.e20);</span>
100000000000000000000
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Int(1.e30);</span>
1000000000000000019884624838656
</pre></div>

<p><a id="X8606FDCE878850EF" name="X8606FDCE878850EF"></a></p>

<h4>19.2 <span class="Heading">Methods</span></h4>

<p>Floating-point numbers may be directly input, as in any usual mathematical software or language; with the exception that every floating-point number must contain a decimal digit. Therefore <code class="code">.1</code>, <code class="code">.1e1</code>, <code class="code">-.999</code> etc. are all valid <strong class="pkg">GAP</strong> inputs.</p>

<p>Floating-point numbers so entered in <strong class="pkg">GAP</strong> are stored as strings. They are converted to floating-point when they are first used. This means that, if the floating-point precision is increased, the constants are reevaluated to fit the new format.</p>

<p>Floating-point numbers may be followed by an underscore, as in <code class="code">1._</code>. This means that they are to be immediately converted to the current floating-point format. The underscore may be followed by a single letter, which specifies which format/precision to use. By default, <strong class="pkg">GAP</strong> has a single floating-point handler, with fixed (53 bits) precision, and its format specifier is <code class="code">'l'</code> as in <code class="code">1._l</code>. Higher-precision floating-point computations is available via external packages; <strong class="pkg">float</strong> for example.</p>

<p>A record, <code class="func">FLOAT</code> (<a href="chap19.html#X819050BF8403806E"><span class="RefLink">19.2-6</span></a>), contains all relevant constants for the current floating-point format; see its documentation for details. Typical fields are <code class="code">FLOAT.MANT_DIG=53</code>, the constant <code class="code">FLOAT.VIEW_DIG=6</code> specifying the number of digits to view, and <code class="code">FLOAT.PI</code> for the constant <span class="SimpleMath">π</span>. The constants have the same name as their C counterparts, except for the missing initial <code class="code">DBL_</code> or <code class="code">M_</code>.</p>

<p>Floating-point numbers may be created using the single function <code class="func">Float</code> (<a href="chap19.html#X873D56F67DD887C5"><span class="RefLink">19.2-7</span></a>), which accepts as arguments rational, string, or floating-point numbers. Floating-point numbers may also be created, in any floating-point representation, using <code class="func">NewFloat</code> (<a href="chap19.html#X873D56F67DD887C5"><span class="RefLink">19.2-7</span></a>) as in <code class="code">NewFloat(IsIEEE754FloatRep,355/113)</code>, by supplying the category filter of the desired new floating-point number; or using <code class="func">MakeFloat</code> (<a href="chap19.html#X873D56F67DD887C5"><span class="RefLink">19.2-7</span></a>) as in <code class="code">NewFloat(1.0,355/113)</code>, by supplying a sample floating-point number.</p>

<p>Floating-point numbers may also be converted to other <strong class="pkg">GAP</strong> formats using the usual commands <code class="func">Int</code> (<a href="chap14.html#X87CA734380B5F68C"><span class="RefLink">14.2-3</span></a>), <code class="func">Rat</code> (<a href="chap17.html#X7EB4C646806A2BDE"><span class="RefLink">17.2-6</span></a>), <code class="func">String</code> (<a href="chap27.html#X81FB5BE27903EC32"><span class="RefLink">27.7-6</span></a>).</p>

<p>Exact conversion to and from floating-point format may be done using external representations. The "external representation" of a floating-point number <code class="code">x</code> is a pair <code class="code">[m,e]</code> of integers, such that <code class="code">x=m*2^(-1+e-LogInt(AbsInt(m),2))</code>. Conversion to and from external representation is performed as usual using <code class="func">ExtRepOfObj</code> (<a href="chap79.html#X8542B32A8206118C"><span class="RefLink">79.16-1</span></a>) and <code class="func">ObjByExtRep</code> (<a href="chap79.html#X8542B32A8206118C"><span class="RefLink">79.16-1</span></a>):</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ExtRepOfObj(3.14);</span>
[ 7070651414971679, 2 ]
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ObjByExtRep(IEEE754FloatsFamily,last);</span>
3.14
</pre></div>

<p>Computations with floating-point numbers never raise any error. Division by zero is allowed, and produces a signed infinity. Illegal operations, such as <code class="code">0./0.</code>, produce <code class="keyw">NaN</code>'s (not-a-number); this is the only floating-point number <code class="code">x</code> such that <code class="code">not EqFloat(x+0.0,x)</code>.</p>

<p>The IEEE754 standard requires <code class="keyw">NaN</code> to be non-equal to itself. On the other hand, <strong class="pkg">GAP</strong> requires every object to be equal to itself. To respect the IEEE754 standard, the function <code class="func">EqFloat</code> (<a href="chap19.html#X7BD96E0585D5A1EE"><span class="RefLink">19.2-2</span></a>) should be used instead of <code class="code">=</code>.</p>

<p>The category a floating-point belongs to can be checked using the filters <code class="func">IsFinite</code> (<a href="chap30.html#X808A4061809A6E67"><span class="RefLink">30.4-2</span></a>), <code class="func">IsPInfinity</code> (<a href="chap19.html#X7DB3BC76836E6219"><span class="RefLink">19.2-5</span></a>), <code class="func">IsNInfinity</code> (<a href="chap19.html#X7DB3BC76836E6219"><span class="RefLink">19.2-5</span></a>), <code class="func">IsXInfinity</code> (<a href="chap19.html#X7DB3BC76836E6219"><span class="RefLink">19.2-5</span></a>), <code class="func">IsNaN</code> (<a href="chap19.html#X7DB3BC76836E6219"><span class="RefLink">19.2-5</span></a>).</p>

<p>Comparisons between floating-point numbers and rationals are explicitly forbidden. The rationale is that objects belonging to different families should in general not be comparable in <strong class="pkg">GAP</strong>. Floating-point numbers are also approximations of real numbers, and don't follow the same rules; consider for example, using the default <strong class="pkg">GAP</strong> implementation of floating-point numbers,</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">1.0/3.0 = Float(1/3);</span>
true
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">(1.0/3.0)^5 = Float((1/3)^5);</span>
false
</pre></div>

<p><a id="X87B6780178314628" name="X87B6780178314628"></a></p>

<h5>19.2-1 <span class="Heading">Mathematical operations</span></h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Cos</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Sin</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; SinCos</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Tan</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Sec</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Csc</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Cot</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Asin</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Acos</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Atan</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Atan2</code>( <var class="Arg">y</var>, <var class="Arg">x</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Cosh</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Sinh</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Tanh</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Sech</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Csch</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Coth</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Asinh</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Acosh</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Atanh</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Log</code>( <var class="Arg">x</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Log2</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Log10</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Log1p</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Exp</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Exp2</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Exp10</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Expm1</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; CubeRoot</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Square</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Hypothenuse</code>( <var class="Arg">x</var>, <var class="Arg">y</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Ceil</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Floor</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Round</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Trunc</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Frac</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; SignFloat</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Argument</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Erf</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Zeta</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Gamma</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; ComplexI</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<p>Usual mathematical functions.</p>

<p><a id="X7BD96E0585D5A1EE" name="X7BD96E0585D5A1EE"></a></p>

<h5>19.2-2 EqFloat</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; EqFloat</code>( <var class="Arg">x</var>, <var class="Arg">y</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<p>Returns: Whether the floateans <var class="Arg">x</var> and <var class="Arg">y</var> are equal</p>

<p>This function compares two floating-point numbers, and returns <code class="keyw">true</code> if they are equal, and <code class="keyw">false</code> otherwise; with the exception that <code class="keyw">NaN</code> is always considered to be different from itself.</p>

<p><a id="X7B3133497DDE839B" name="X7B3133497DDE839B"></a></p>

<h5>19.2-3 PrecisionFloat</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; PrecisionFloat</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<p>Returns: The precision of <var class="Arg">x</var></p>

<p>This function returns the precision, counted in number of binary digits, of the floating-point number <var class="Arg">x</var>.</p>

<p><a id="X7D085DA987B0BDA6" name="X7D085DA987B0BDA6"></a></p>

<h5>19.2-4 <span class="Heading">Interval operations</span></h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Sup</code>( <var class="Arg">interval</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Inf</code>( <var class="Arg">interval</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Mid</code>( <var class="Arg">interval</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; AbsoluteDiameter</code>( <var class="Arg">interval</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; RelativeDiameter</code>( <var class="Arg">interval</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Overlaps</code>( <var class="Arg">interval1</var>, <var class="Arg">interval2</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsDisjoint</code>( <var class="Arg">interval1</var>, <var class="Arg">interval2</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IncreaseInterval</code>( <var class="Arg">interval</var>, <var class="Arg">delta</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; BlowupInterval</code>( <var class="Arg">interval</var>, <var class="Arg">ratio</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; BisectInterval</code>( <var class="Arg">interval</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<p>Most are self-explanatory. <code class="code">BlowupInterval</code> returns an interval with same midpoint but relative diameter increased by <var class="Arg">ratio</var>; <code class="code">IncreaseInterval</code> returns an interval with same midpoint but absolute diameter increased by <var class="Arg">delta</var>; <code class="code">BisectInterval</code> returns a list of two intervals whose union equals <var class="Arg">interval</var>.</p>

<p><a id="X7DB3BC76836E6219" name="X7DB3BC76836E6219"></a></p>

<h5>19.2-5 IsPInfinity</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsPInfinity</code>( <var class="Arg">x</var> )</td><td class="tdright">( property )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsNInfinity</code>( <var class="Arg">x</var> )</td><td class="tdright">( property )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsXInfinity</code>( <var class="Arg">x</var> )</td><td class="tdright">( property )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsFinite</code>( <var class="Arg">x</var> )</td><td class="tdright">( property )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsNaN</code>( <var class="Arg">x</var> )</td><td class="tdright">( property )</td></tr></table></div>
<p>Returns <code class="keyw">true</code> if the floating-point number <var class="Arg">x</var> is respectively <span class="SimpleMath">+∞</span>, <span class="SimpleMath">-∞</span>, <span class="SimpleMath">±∞</span>, finite, or `not a number', such as the result of <code class="code">0.0/0.0</code>.</p>

<p><a id="X819050BF8403806E" name="X819050BF8403806E"></a></p>

<h5>19.2-6 FLOAT</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; FLOAT</code></td><td class="tdright">( global variable )</td></tr></table></div>
<p>This record contains useful floating-point constants:</p>


<dl>
<dt><strong class="Mark">DECIMAL_DIG</strong></dt>
<dd><p>Maximal number of useful digits;</p>

</dd>
<dt><strong class="Mark">DIG</strong></dt>
<dd><p>Number of significant digits;</p>

</dd>
<dt><strong class="Mark">VIEW_DIG</strong></dt>
<dd><p>Number of digits to print in short view;</p>

</dd>
<dt><strong class="Mark">EPSILON</strong></dt>
<dd><p>Smallest number such that <span class="SimpleMath">1≠1+ϵ</span>;</p>

</dd>
<dt><strong class="Mark">MANT_DIG</strong></dt>
<dd><p>Number of bits in the mantissa;</p>

</dd>
<dt><strong class="Mark">MAX</strong></dt>
<dd><p>Maximal representable number;</p>

</dd>
<dt><strong class="Mark">MAX_10_EXP</strong></dt>
<dd><p>Maximal decimal exponent;</p>

</dd>
<dt><strong class="Mark">MAX_EXP</strong></dt>
<dd><p>Maximal binary exponent;</p>

</dd>
<dt><strong class="Mark">MIN</strong></dt>
<dd><p>Minimal positive representable number;</p>

</dd>
<dt><strong class="Mark">MIN_10_EXP</strong></dt>
<dd><p>Minimal decimal exponent;</p>

</dd>
<dt><strong class="Mark">MIN_EXP</strong></dt>
<dd><p>Minimal exponent;</p>

</dd>
<dt><strong class="Mark">INFINITY</strong></dt>
<dd><p>Positive infinity;</p>

</dd>
<dt><strong class="Mark">NINFINITY</strong></dt>
<dd><p>Negative infinity;</p>

</dd>
<dt><strong class="Mark">NAN</strong></dt>
<dd><p>Not-a-number,</p>

</dd>
</dl>
<p>as well as mathematical constants <code class="code">E</code>, <code class="code">LOG2E</code>, <code class="code">LOG10E</code>, <code class="code">LN2</code>, <code class="code">LN10</code>, <code class="code">PI</code>, <code class="code">PI_2</code>, <code class="code">PI_4</code>, <code class="code">1_PI</code>, <code class="code">2_PI</code>, <code class="code">2_SQRTPI</code>, <code class="code">SQRT2</code>, <code class="code">SQRT1_2</code>.</p>

<p><a id="X873D56F67DD887C5" name="X873D56F67DD887C5"></a></p>

<h5>19.2-7 Float</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Float</code>( <var class="Arg">obj</var> )</td><td class="tdright">( function )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; NewFloat</code>( <var class="Arg">filter</var>, <var class="Arg">obj</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; MakeFloat</code>( <var class="Arg">sample</var>, <var class="Arg">obj</var>, <var class="Arg">obj</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<p>Returns: A new floating-point number, based on <var class="Arg">obj</var></p>

<p>This function creates a new floating-point number.</p>

<p>If <var class="Arg">obj</var> is a rational number, the created number is created with sufficient precision so that the number can (usually) be converted back to the original number (see <code class="func">Rat</code> (<a href="../../doc/ref/chap17.html#X7EB4C646806A2BDE"><span class="RefLink">Reference: Rat</span></a>) and <code class="func">Rat</code> (<a href="chap17.html#X7EB4C646806A2BDE"><span class="RefLink">17.2-6</span></a>)). For an integer, the precision, if unspecified, is chosen sufficient so that <code class="code">Int(Float(obj))=obj</code> always holds, but at least 64 bits.</p>

<p><var class="Arg">obj</var> may also be a string, which may be of the form <code class="code">"3.14e0"</code> or <code class="code">".314e1"</code> or <code class="code">".314@1"</code> etc.</p>

<p>An option may be passed to specify, it bits, a desired precision. The format is <code class="code">Float("3.14":PrecisionFloat:=1000)</code> to create a 1000-bit approximation of <span class="SimpleMath">3.14</span>.</p>

<p>In particular, if <var class="Arg">obj</var> is already a floating-point number, then <code class="code">Float(obj:PrecisionFloat:=prec)</code> creates a copy of <var class="Arg">obj</var> with a new precision. prec</p>

<p><a id="X7BCD34DC7B5A0521" name="X7BCD34DC7B5A0521"></a></p>

<h5>19.2-8 Rat</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Rat</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<p>Returns: A rational approximation to <var class="Arg">f</var></p>

<p>This command constructs a rational approximation to the floating-point number <var class="Arg">f</var>. Of course, it is not guaranteed to return the original rational number <var class="Arg">f</var> was created from, though it returns the most `reasonable' one given the precision of <var class="Arg">f</var>.</p>

<p>Two options control the precision of the rational approximation: In the form <code class="code">Rat(f:maxdenom:=md,maxpartial:=mp)</code>, the rational returned is such that the denominator is at most <var class="Arg">md</var> and the partials in its continued fraction expansion are at most <var class="Arg">mp</var>. The default values are <code class="code">maxpartial:=10000</code> and <code class="code">maxdenom:=2^(precision/2)</code>.</p>

<p><a id="X7A962B0983FA66E8" name="X7A962B0983FA66E8"></a></p>

<h5>19.2-9 SetFloats</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; SetFloats</code>( <var class="Arg">rec</var>[, <var class="Arg">bits</var>][, <var class="Arg">install</var>] )</td><td class="tdright">( function )</td></tr></table></div>
<p>Installs a new interface to floating-point numbers in <strong class="pkg">GAP</strong>, optionally with a desired precision <var class="Arg">bits</var> in binary digits. The last optional argument <var class="Arg">install</var> is a boolean value; if false, it only installs the eager handler and the precision for the floateans, without making them the default.</p>

<p><a id="X845ACF3A78BD2771" name="X845ACF3A78BD2771"></a></p>

<h4>19.3 <span class="Heading">High-precision-specific methods</span></h4>

<p><strong class="pkg">GAP</strong> provides a mechanism for packages to implement new floating-point numerical interfaces. The following describes that mechanism, actual examples of packages are documented separately.</p>

<p>A package must create a record with fields (all optional)</p>


<dl>
<dt><strong class="Mark">creator</strong></dt>
<dd><p>a function converting strings to floating-point;</p>

</dd>
<dt><strong class="Mark">eager</strong></dt>
<dd><p>a character allowing immediate conversion to floating-point;</p>

</dd>
<dt><strong class="Mark">objbyextrep</strong></dt>
<dd><p>a function creating a floating-point number out of a list <code class="code">[mantissa,exponent]</code>;</p>

</dd>
<dt><strong class="Mark">filter</strong></dt>
<dd><p>a filter for the new floating-point objects;</p>

</dd>
<dt><strong class="Mark">constants</strong></dt>
<dd><p>a record containing numerical constants, such as <code class="code">MANT_DIG</code>, <code class="code">MAX</code>, <code class="code">MIN</code>, <code class="code">NAN</code>.</p>

</dd>
</dl>
<p>The package must install methods <code class="code">Int</code>, <code class="code">Rat</code>, <code class="code">String</code> for its objects, and creators <code class="code">NewFloat(filter,IsRat)</code>, <code class="code">NewFloat(IsString)</code>.</p>

<p>It must then install methods for all arithmetic and numerical operations: <code class="code">PLUS</code>, <code class="code">Exp</code>, ...</p>

<p>The user chooses that implementation by calling <code class="func">SetFloats</code> (<a href="chap19.html#X7A962B0983FA66E8"><span class="RefLink">19.2-9</span></a>) with the record as argument, and with an optional second argument requesting a precision in binary digits.</p>

<p><a id="X7E8F6EFB87A65F78" name="X7E8F6EFB87A65F78"></a></p>

<h4>19.4 <span class="Heading">Complex arithmetic</span></h4>

<p>Complex arithmetic may be implemented in packages, and is present in <strong class="pkg">float</strong>. Complex numbers are treated as usual numbers; they may be input with an extra "i" as in <code class="code">-0.5+0.866i</code>.</p>

<p>Methods should then be implemented for <code class="code">Norm</code>, <code class="code">RealPart</code>, <code class="code">ImaginaryPart</code>, <code class="code">ComplexConjugate</code>, ...</p>

<p><a id="X7E57B09C80136484" name="X7E57B09C80136484"></a></p>

<h4>19.5 <span class="Heading">Interval-specific methods</span></h4>

<p>Interval arithmetic may also be implemented in packages. Intervals are in fact efficient implementations of sets of real numbers. The only non-trivial issue is how they should be compared. The standard <code class="code">EQ</code> tests if the intervals are equal; however, it is usually more useful to know if intervals overlap, or are disjoint, or are contained in each other. The methods provided by the package should include <code class="code">Sup,Inf,Mid,DiameterOfInterval,Overlaps,IsSubset,IsDisjoint</code>.</p>

<p>Note the usual convention that intervals are compared as in <span class="SimpleMath">[a,b]le[c,d]</span> if and only if <span class="SimpleMath">ale c</span> and <span class="SimpleMath">ble d</span>.</p>


<div class="chlinkprevnextbot">&nbsp;<a href="chap0.html">[Top of Book]</a>&nbsp;  <a href="chap0.html#contents">[Contents]</a>&nbsp;  &nbsp;<a href="chap18.html">[Previous Chapter]</a>&nbsp;  &nbsp;<a href="chap20.html">[Next Chapter]</a>&nbsp;  </div>


<div class="chlinkbot"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a>  <a href="chap1.html">1</a>  <a href="chap2.html">2</a>  <a href="chap3.html">3</a>  <a href="chap4.html">4</a>  <a href="chap5.html">5</a>  <a href="chap6.html">6</a>  <a href="chap7.html">7</a>  <a href="chap8.html">8</a>  <a href="chap9.html">9</a>  <a href="chap10.html">10</a>  <a href="chap11.html">11</a>  <a href="chap12.html">12</a>  <a href="chap13.html">13</a>  <a href="chap14.html">14</a>  <a href="chap15.html">15</a>  <a href="chap16.html">16</a>  <a href="chap17.html">17</a>  <a href="chap18.html">18</a>  <a href="chap19.html">19</a>  <a href="chap20.html">20</a>  <a href="chap21.html">21</a>  <a href="chap22.html">22</a>  <a href="chap23.html">23</a>  <a href="chap24.html">24</a>  <a href="chap25.html">25</a>  <a href="chap26.html">26</a>  <a href="chap27.html">27</a>  <a href="chap28.html">28</a>  <a href="chap29.html">29</a>  <a href="chap30.html">30</a>  <a href="chap31.html">31</a>  <a href="chap32.html">32</a>  <a href="chap33.html">33</a>  <a href="chap34.html">34</a>  <a href="chap35.html">35</a>  <a href="chap36.html">36</a>  <a href="chap37.html">37</a>  <a href="chap38.html">38</a>  <a href="chap39.html">39</a>  <a href="chap40.html">40</a>  <a href="chap41.html">41</a>  <a href="chap42.html">42</a>  <a href="chap43.html">43</a>  <a href="chap44.html">44</a>  <a href="chap45.html">45</a>  <a href="chap46.html">46</a>  <a href="chap47.html">47</a>  <a href="chap48.html">48</a>  <a href="chap49.html">49</a>  <a href="chap50.html">50</a>  <a href="chap51.html">51</a>  <a href="chap52.html">52</a>  <a href="chap53.html">53</a>  <a href="chap54.html">54</a>  <a href="chap55.html">55</a>  <a href="chap56.html">56</a>  <a href="chap57.html">57</a>  <a href="chap58.html">58</a>  <a href="chap59.html">59</a>  <a href="chap60.html">60</a>  <a href="chap61.html">61</a>  <a href="chap62.html">62</a>  <a href="chap63.html">63</a>  <a href="chap64.html">64</a>  <a href="chap65.html">65</a>  <a href="chap66.html">66</a>  <a href="chap67.html">67</a>  <a href="chap68.html">68</a>  <a href="chap69.html">69</a>  <a href="chap70.html">70</a>  <a href="chap71.html">71</a>  <a href="chap72.html">72</a>  <a href="chap73.html">73</a>  <a href="chap74.html">74</a>  <a href="chap75.html">75</a>  <a href="chap76.html">76</a>  <a href="chap77.html">77</a>  <a href="chap78.html">78</a>  <a href="chap79.html">79</a>  <a href="chap80.html">80</a>  <a href="chap81.html">81</a>  <a href="chap82.html">82</a>  <a href="chap83.html">83</a>  <a href="chap84.html">84</a>  <a href="chap85.html">85</a>  <a href="chap86.html">86</a>  <a href="chap87.html">87</a>  <a href="chapBib.html">Bib</a>  <a href="chapInd.html">Ind</a>  </div>

<hr />
<p class="foot">generated by <a href="http://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
</body>
</html>