| 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | |
| 3 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
| 4 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 5 | |
| 6 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> |
| 7 | <head> |
| 8 | <title>GAP (ref) - Chapter 19: Floats</title> |
| 9 | <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> |
| 10 | <meta name="generator" content="GAPDoc2HTML" /> |
| 11 | <link rel="stylesheet" type="text/css" href="manual.css" /> |
| 12 | <script src="manual.js" type="text/javascript"></script> |
| 13 | <script type="text/javascript">overwriteStyle();</script> |
| 14 | </head> |
| 15 | <body class="chap19" onload="jscontent()"> |
| 16 | |
| 17 | |
| 18 | <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> |
| 19 | |
| 20 | <div class="chlinkprevnexttop"> <a href="chap0.html">[Top of Book]</a> <a href="chap0.html#contents">[Contents]</a> <a href="chap18.html">[Previous Chapter]</a> <a href="chap20.html">[Next Chapter]</a> </div> |
| 21 | |
| 22 | <p id="mathjaxlink" class="pcenter"><a href="chap19_mj.html">[MathJax on]</a></p> |
| 23 | <p><a id="X81AA901181CA568F" name="X81AA901181CA568F"></a></p> |
| 24 | <div class="ChapSects"><a href="chap19.html#X81AA901181CA568F">19 <span class="Heading">Floats</span></a> |
| 25 | <div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap19.html#X7B4092CA7ABB93B0">19.1 <span class="Heading">A sample run</span></a> |
| 26 | </span> |
| 27 | </div> |
| 28 | <div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap19.html#X8606FDCE878850EF">19.2 <span class="Heading">Methods</span></a> |
| 29 | </span> |
| 30 | <div class="ContSSBlock"> |
| 31 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X86D5EA93813FB6C4">19.2-1 <span class="Heading">Float creators</span></a> |
| 32 | </span> |
| 33 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X7BCD34DC7B5A0521">19.2-2 Rat</a></span> |
| 34 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X7D1EAE11844625F4">19.2-3 Cyc</a></span> |
| 35 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X7A962B0983FA66E8">19.2-4 SetFloats</a></span> |
| 36 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X819050BF8403806E">19.2-5 FLOAT</a></span> |
| 37 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X7BD96E0585D5A1EE">19.2-6 EqFloat</a></span> |
| 38 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X7B3133497DDE839B">19.2-7 PrecisionFloat</a></span> |
| 39 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X801753137949DD78">19.2-8 SignBit</a></span> |
| 40 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X7935C65D7B0F47C7">19.2-9 SinCos</a></span> |
| 41 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X846E1196844B9E11">19.2-10 Atan2</a></span> |
| 42 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X7981510D826EE3E5">19.2-11 Log1p</a></span> |
| 43 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X86073E147FB3C0EA">19.2-12 Erf</a></span> |
| 44 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X7E03FDEE824D1E8E">19.2-13 <span class="Heading">Infinity testers</span></a> |
| 45 | </span> |
| 46 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X8151581186F75BA3">19.2-14 <span class="Heading">Standard mathematical operations</span></a> |
| 47 | </span> |
| 48 | </div></div> |
| 49 | <div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap19.html#X845ACF3A78BD2771">19.3 <span class="Heading">High-precision-specific methods</span></a> |
| 50 | </span> |
| 51 | </div> |
| 52 | <div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap19.html#X7E8F6EFB87A65F78">19.4 <span class="Heading">Complex arithmetic</span></a> |
| 53 | </span> |
| 54 | <div class="ContSSBlock"> |
| 55 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X7B0269D983F96677">19.4-1 Argument</a></span> |
| 56 | </div></div> |
| 57 | <div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap19.html#X7E57B09C80136484">19.5 <span class="Heading">Interval-specific methods</span></a> |
| 58 | </span> |
| 59 | <div class="ContSSBlock"> |
| 60 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X7C34D1D185802F2F">19.5-1 Sup</a></span> |
| 61 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X78F1E457814FD1FD">19.5-2 Inf</a></span> |
| 62 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X829581A485F55996">19.5-3 Mid</a></span> |
| 63 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X7FE540B387B0012C">19.5-4 AbsoluteDiameter</a></span> |
| 64 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X7CA771757F441592">19.5-5 RelativeDiameter</a></span> |
| 65 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X86D22AE57E2D84B2">19.5-6 IsDisjoint</a></span> |
| 66 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X7A5E0C3E79837EB8">19.5-7 IsSubset</a></span> |
| 67 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X85191E1679936CE9">19.5-8 IncreaseInterval</a></span> |
| 68 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X879EE14282DD1539">19.5-9 BlowupInterval</a></span> |
| 69 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap19.html#X7EC15DAE7CBBB42E">19.5-10 BisectInterval</a></span> |
| 70 | </div></div> |
| 71 | </div> |
| 72 | |
| 73 | <h3>19 <span class="Heading">Floats</span></h3> |
| 74 | |
| 75 | <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> |
| 76 | |
| 77 | <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> |
| 78 | |
| 79 | <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> |
| 80 | |
| 81 | <p><a id="X7B4092CA7ABB93B0" name="X7B4092CA7ABB93B0"></a></p> |
| 82 | |
| 83 | <h4>19.1 <span class="Heading">A sample run</span></h4> |
| 84 | |
| 85 | <p>Floating-point numbers can be input into <strong class="pkg">GAP</strong> in the standard floating-point notation:</p> |
| 86 | |
| 87 | |
| 88 | <div class="example"><pre> |
| 89 | <span class="GAPprompt">gap></span> <span class="GAPinput">3.14;</span> |
| 90 | 3.14 |
| 91 | <span class="GAPprompt">gap></span> <span class="GAPinput">last^2/6;</span> |
| 92 | 1.64327 |
| 93 | <span class="GAPprompt">gap></span> <span class="GAPinput">h := 6.62606896e-34;</span> |
| 94 | 6.62607e-34 |
| 95 | <span class="GAPprompt">gap></span> <span class="GAPinput">pi := 4*Atan(1.0);</span> |
| 96 | 3.14159 |
| 97 | <span class="GAPprompt">gap></span> <span class="GAPinput">hbar := h/(2*pi);</span> |
| 98 | 1.05457e-34 |
| 99 | </pre></div> |
| 100 | |
| 101 | <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> |
| 102 | |
| 103 | <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> |
| 104 | |
| 105 | |
| 106 | <div class="example"><pre> |
| 107 | <span class="GAPprompt">gap></span> <span class="GAPinput">Float("3.1416");</span> |
| 108 | 3.1416 |
| 109 | <span class="GAPprompt">gap></span> <span class="GAPinput">Float(355/113);</span> |
| 110 | 3.14159 |
| 111 | <span class="GAPprompt">gap></span> <span class="GAPinput">Rat(last);</span> |
| 112 | 355/113 |
| 113 | <span class="GAPprompt">gap></span> <span class="GAPinput">Rat(0.33333);</span> |
| 114 | 1/3 |
| 115 | <span class="GAPprompt">gap></span> <span class="GAPinput">Int(1.e10);</span> |
| 116 | 10000000000 |
| 117 | <span class="GAPprompt">gap></span> <span class="GAPinput">Int(1.e20);</span> |
| 118 | 100000000000000000000 |
| 119 | <span class="GAPprompt">gap></span> <span class="GAPinput">Int(1.e30);</span> |
| 120 | 1000000000000000019884624838656 |
| 121 | </pre></div> |
| 122 | |
| 123 | <p><a id="X8606FDCE878850EF" name="X8606FDCE878850EF"></a></p> |
| 124 | |
| 125 | <h4>19.2 <span class="Heading">Methods</span></h4> |
| 126 | |
| 127 | <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> |
| 128 | |
| 129 | <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> |
| 130 | |
| 131 | <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> |
| 132 | |
| 133 | <p>A record, <code class="func">FLOAT</code> (<a href="chap19.html#X819050BF8403806E"><span class="RefLink">19.2-5</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> |
| 134 | |
| 135 | <p>Floating-point numbers may be created using the single function <code class="func">Float</code> (<a href="chap19.html#X86D5EA93813FB6C4"><span class="RefLink">19.2-1</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#X86D5EA93813FB6C4"><span class="RefLink">19.2-1</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#X86D5EA93813FB6C4"><span class="RefLink">19.2-1</span></a>) as in <code class="code">MakeFloat(1.0,355/113)</code>, by supplying a sample floating-point number.</p> |
| 136 | |
| 137 | <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> |
| 138 | |
| 139 | <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.8-1</span></a>) and <code class="func">ObjByExtRep</code> (<a href="chap79.html#X8542B32A8206118C"><span class="RefLink">79.8-1</span></a>):</p> |
| 140 | |
| 141 | |
| 142 | <div class="example"><pre> |
| 143 | <span class="GAPprompt">gap></span> <span class="GAPinput">ExtRepOfObj(3.14);</span> |
| 144 | [ 7070651414971679, 2 ] |
| 145 | <span class="GAPprompt">gap></span> <span class="GAPinput">ObjByExtRep(IEEE754FloatsFamily,last);</span> |
| 146 | 3.14 |
| 147 | </pre></div> |
| 148 | |
| 149 | <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> |
| 150 | |
| 151 | <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-6</span></a>) should be used instead of <code class="code">=</code>.</p> |
| 152 | |
| 153 | <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#X7E03FDEE824D1E8E"><span class="RefLink">19.2-13</span></a>), <code class="func">IsNInfinity</code> (<a href="chap19.html#X7E03FDEE824D1E8E"><span class="RefLink">19.2-13</span></a>), <code class="func">IsXInfinity</code> (<a href="chap19.html#X7E03FDEE824D1E8E"><span class="RefLink">19.2-13</span></a>), <code class="func">IsNaN</code> (<a href="chap19.html#X7E03FDEE824D1E8E"><span class="RefLink">19.2-13</span></a>).</p> |
| 154 | |
| 155 | <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> |
| 156 | |
| 157 | |
| 158 | <div class="example"><pre> |
| 159 | <span class="GAPprompt">gap></span> <span class="GAPinput">1.0/3.0 = Float(1/3);</span> |
| 160 | true |
| 161 | <span class="GAPprompt">gap></span> <span class="GAPinput">(1.0/3.0)^5 = Float((1/3)^5);</span> |
| 162 | false |
| 163 | </pre></div> |
| 164 | |
| 165 | <p><a id="X86D5EA93813FB6C4" name="X86D5EA93813FB6C4"></a></p> |
| 166 | |
| 167 | <h5>19.2-1 <span class="Heading">Float creators</span></h5> |
| 168 | |
| 169 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Float</code>( <var class="Arg">obj</var> )</td><td class="tdright">( function )</td></tr></table></div> |
| 170 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ NewFloat</code>( <var class="Arg">filter</var>, <var class="Arg">obj</var> )</td><td class="tdright">( constructor )</td></tr></table></div> |
| 171 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ 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> |
| 172 | <p>Returns: A new floating-point number, based on <var class="Arg">obj</var></p> |
| 173 | |
| 174 | <p>This function creates a new floating-point number.</p> |
| 175 | |
| 176 | <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> (<span class="RefLink">Reference: Rat</span>) 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> |
| 177 | |
| 178 | <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> |
| 179 | |
| 180 | <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> |
| 181 | |
| 182 | <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> |
| 183 | |
| 184 | <p><a id="X7BCD34DC7B5A0521" name="X7BCD34DC7B5A0521"></a></p> |
| 185 | |
| 186 | <h5>19.2-2 Rat</h5> |
| 187 | |
| 188 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Rat</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 189 | <p>Returns: A rational approximation to <var class="Arg">f</var></p> |
| 190 | |
| 191 | <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> |
| 192 | |
| 193 | <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> |
| 194 | |
| 195 | <p><a id="X7D1EAE11844625F4" name="X7D1EAE11844625F4"></a></p> |
| 196 | |
| 197 | <h5>19.2-3 Cyc</h5> |
| 198 | |
| 199 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Cyc</code>( <var class="Arg">f</var>[, <var class="Arg">degree</var>] )</td><td class="tdright">( operation )</td></tr></table></div> |
| 200 | <p>Returns: A cyclotomic approximation to <var class="Arg">f</var></p> |
| 201 | |
| 202 | <p>This command constructs a cyclotomic 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>. An optional argument <var class="Arg">degree</var> specifies the maximal degree of the cyclotomic to be constructed.</p> |
| 203 | |
| 204 | <p>The method used is LLL lattice reduction.</p> |
| 205 | |
| 206 | <p><a id="X7A962B0983FA66E8" name="X7A962B0983FA66E8"></a></p> |
| 207 | |
| 208 | <h5>19.2-4 SetFloats</h5> |
| 209 | |
| 210 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ 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> |
| 211 | <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> |
| 212 | |
| 213 | <p><a id="X819050BF8403806E" name="X819050BF8403806E"></a></p> |
| 214 | |
| 215 | <h5>19.2-5 FLOAT</h5> |
| 216 | |
| 217 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ FLOAT</code></td><td class="tdright">( global variable )</td></tr></table></div> |
| 218 | <p>This record contains useful floating-point constants:</p> |
| 219 | |
| 220 | |
| 221 | <dl> |
| 222 | <dt><strong class="Mark">DECIMAL_DIG</strong></dt> |
| 223 | <dd><p>Maximal number of useful digits;</p> |
| 224 | |
| 225 | </dd> |
| 226 | <dt><strong class="Mark">DIG</strong></dt> |
| 227 | <dd><p>Number of significant digits;</p> |
| 228 | |
| 229 | </dd> |
| 230 | <dt><strong class="Mark">VIEW_DIG</strong></dt> |
| 231 | <dd><p>Number of digits to print in short view;</p> |
| 232 | |
| 233 | </dd> |
| 234 | <dt><strong class="Mark">EPSILON</strong></dt> |
| 235 | <dd><p>Smallest number such that <span class="SimpleMath">1≠1+ϵ</span>;</p> |
| 236 | |
| 237 | </dd> |
| 238 | <dt><strong class="Mark">MANT_DIG</strong></dt> |
| 239 | <dd><p>Number of bits in the mantissa;</p> |
| 240 | |
| 241 | </dd> |
| 242 | <dt><strong class="Mark">MAX</strong></dt> |
| 243 | <dd><p>Maximal representable number;</p> |
| 244 | |
| 245 | </dd> |
| 246 | <dt><strong class="Mark">MAX_10_EXP</strong></dt> |
| 247 | <dd><p>Maximal decimal exponent;</p> |
| 248 | |
| 249 | </dd> |
| 250 | <dt><strong class="Mark">MAX_EXP</strong></dt> |
| 251 | <dd><p>Maximal binary exponent;</p> |
| 252 | |
| 253 | </dd> |
| 254 | <dt><strong class="Mark">MIN</strong></dt> |
| 255 | <dd><p>Minimal positive representable number;</p> |
| 256 | |
| 257 | </dd> |
| 258 | <dt><strong class="Mark">MIN_10_EXP</strong></dt> |
| 259 | <dd><p>Minimal decimal exponent;</p> |
| 260 | |
| 261 | </dd> |
| 262 | <dt><strong class="Mark">MIN_EXP</strong></dt> |
| 263 | <dd><p>Minimal exponent;</p> |
| 264 | |
| 265 | </dd> |
| 266 | <dt><strong class="Mark">INFINITY</strong></dt> |
| 267 | <dd><p>Positive infinity;</p> |
| 268 | |
| 269 | </dd> |
| 270 | <dt><strong class="Mark">NINFINITY</strong></dt> |
| 271 | <dd><p>Negative infinity;</p> |
| 272 | |
| 273 | </dd> |
| 274 | <dt><strong class="Mark">NAN</strong></dt> |
| 275 | <dd><p>Not-a-number,</p> |
| 276 | |
| 277 | </dd> |
| 278 | </dl> |
| 279 | <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> |
| 280 | |
| 281 | <p><a id="X7BD96E0585D5A1EE" name="X7BD96E0585D5A1EE"></a></p> |
| 282 | |
| 283 | <h5>19.2-6 EqFloat</h5> |
| 284 | |
| 285 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ EqFloat</code>( <var class="Arg">x</var>, <var class="Arg">y</var> )</td><td class="tdright">( operation )</td></tr></table></div> |
| 286 | <p>Returns: Whether the floateans <var class="Arg">x</var> and <var class="Arg">y</var> are equal</p> |
| 287 | |
| 288 | <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> |
| 289 | |
| 290 | <p><a id="X7B3133497DDE839B" name="X7B3133497DDE839B"></a></p> |
| 291 | |
| 292 | <h5>19.2-7 PrecisionFloat</h5> |
| 293 | |
| 294 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ PrecisionFloat</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 295 | <p>Returns: The precision of <var class="Arg">x</var></p> |
| 296 | |
| 297 | <p>This function returns the precision, counted in number of binary digits, of the floating-point number <var class="Arg">x</var>.</p> |
| 298 | |
| 299 | <p><a id="X801753137949DD78" name="X801753137949DD78"></a></p> |
| 300 | |
| 301 | <h5>19.2-8 SignBit</h5> |
| 302 | |
| 303 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ SignBit</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 304 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ SignFloat</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 305 | <p>Returns: The sign of <var class="Arg">x</var>.</p> |
| 306 | |
| 307 | <p>The first function <code class="code">SignBit</code> returns the sign bit of the floating-point number <var class="Arg">x</var>: <code class="keyw">true</code> if <var class="Arg">x</var> is negative (including <code class="code">-0.</code>) and <code class="keyw">false</code> otherwise.</p> |
| 308 | |
| 309 | <p>The second function <code class="code">SignFloat</code> returns the integer <code class="keyw">-1</code> if <var class="Arg">x<0</var>, <code class="keyw">0</code> if <var class="Arg">x=0</var> and <code class="keyw">1</code> if <var class="Arg">x>0</var>.</p> |
| 310 | |
| 311 | <p><a id="X7935C65D7B0F47C7" name="X7935C65D7B0F47C7"></a></p> |
| 312 | |
| 313 | <h5>19.2-9 SinCos</h5> |
| 314 | |
| 315 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ SinCos</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 316 | <p>Returns: The list <code class="code">[sin(x), cos(x)]</code>.</p> |
| 317 | |
| 318 | <p>The function returns a list with <code class="code">sin</code> and <code class="code">cos</code> of <var class="Arg">x</var>.</p> |
| 319 | |
| 320 | <p><a id="X846E1196844B9E11" name="X846E1196844B9E11"></a></p> |
| 321 | |
| 322 | <h5>19.2-10 Atan2</h5> |
| 323 | |
| 324 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Atan2</code>( <var class="Arg">y</var>, <var class="Arg">x</var> )</td><td class="tdright">( operation )</td></tr></table></div> |
| 325 | <p>Returns: The polar angle of <var class="Arg">(x, y)</var> in the plane as float.</p> |
| 326 | |
| 327 | <p>Returns the principal value of the argument (polar angle) of <span class="SimpleMath">(<var class="Arg">x</var>, <var class="Arg">y</var>)</span> in the plane. The returned value will always be in <span class="SimpleMath">(-π , π]</span> and is not defined on <span class="SimpleMath">(0,0)</span>. This function is defined in accordance with IEEE 1788-2015 and imported from IEEE 754.</p> |
| 328 | |
| 329 | <p><a id="X7981510D826EE3E5" name="X7981510D826EE3E5"></a></p> |
| 330 | |
| 331 | <h5>19.2-11 Log1p</h5> |
| 332 | |
| 333 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Log1p</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 334 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Expm1</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 335 | <p>Returns: The natural logarithm of <span class="SimpleMath"><var class="Arg">x</var>+1</span> or exponential <span class="SimpleMath">-1</span> of <var class="Arg">x</var> respectively.</p> |
| 336 | |
| 337 | <p>The first function <code class="code">Log1p</code> returns the natural logarithm <span class="SimpleMath">log(<var class="Arg">x</var>+1)</span>.</p> |
| 338 | |
| 339 | <p>The second function <code class="code">Expm1</code> returns the exponential function <span class="SimpleMath">exp(<var class="Arg">x</var>)-1</span></p> |
| 340 | |
| 341 | <p>These two functions are inverse to each other.</p> |
| 342 | |
| 343 | <p><a id="X86073E147FB3C0EA" name="X86073E147FB3C0EA"></a></p> |
| 344 | |
| 345 | <h5>19.2-12 Erf</h5> |
| 346 | |
| 347 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Erf</code>( <var class="Arg">x</var> )</td><td class="tdright">( operation )</td></tr></table></div> |
| 348 | <p>Returns: The error function given by the Gaussian integral</p> |
| 349 | |
| 350 | <p>Returns the error function imported from IEEE 754 given by the formula:</p> |
| 351 | |
| 352 | <p class="pcenter"> Erf(x) := \frac{2}{\sqrt{\pi}} \int_{0}^{x} exp(- t^2 ) dt </p> |
| 353 | |
| 354 | <p><a id="X7E03FDEE824D1E8E" name="X7E03FDEE824D1E8E"></a></p> |
| 355 | |
| 356 | <h5>19.2-13 <span class="Heading">Infinity testers</span></h5> |
| 357 | |
| 358 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsPInfinity</code>( <var class="Arg">x</var> )</td><td class="tdright">( property )</td></tr></table></div> |
| 359 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsNInfinity</code>( <var class="Arg">x</var> )</td><td class="tdright">( property )</td></tr></table></div> |
| 360 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsXInfinity</code>( <var class="Arg">x</var> )</td><td class="tdright">( property )</td></tr></table></div> |
| 361 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsFinite</code>( <var class="Arg">x</var> )</td><td class="tdright">( property )</td></tr></table></div> |
| 362 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsNaN</code>( <var class="Arg">x</var> )</td><td class="tdright">( property )</td></tr></table></div> |
| 363 | <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> |
| 364 | |
| 365 | <p><a id="X8151581186F75BA3" name="X8151581186F75BA3"></a></p> |
| 366 | |
| 367 | <h5>19.2-14 <span class="Heading">Standard mathematical operations</span></h5> |
| 368 | |
| 369 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Sin</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 370 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Cos</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 371 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Tan</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 372 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Sec</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 373 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Csc</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 374 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Cot</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 375 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Asin</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 376 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Acos</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 377 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Atan</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 378 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Sinh</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 379 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Cosh</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 380 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Tanh</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 381 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Sech</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 382 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Csch</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 383 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Coth</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 384 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Asinh</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 385 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Acosh</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 386 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Atanh</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 387 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Log</code>( <var class="Arg">f</var> )</td><td class="tdright">( operation )</td></tr></table></div> |
| 388 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Log2</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 389 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Log10</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 390 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Exp</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 391 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Exp2</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 392 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Exp10</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 393 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ CubeRoot</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 394 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Square</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 395 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Hypothenuse</code>( <var class="Arg">x</var>, <var class="Arg">y</var> )</td><td class="tdright">( operation )</td></tr></table></div> |
| 396 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Ceil</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 397 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Floor</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 398 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Round</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 399 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Trunc</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 400 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ FrExp</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 401 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ LdExp</code>( <var class="Arg">f</var>, <var class="Arg">exp</var> )</td><td class="tdright">( operation )</td></tr></table></div> |
| 402 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ AbsoluteValue</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 403 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Norm</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 404 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Frac</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 405 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Zeta</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 406 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Gamma</code>( <var class="Arg">f</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 407 | <p>Standard math functions. Functions ending in an integer like <code class="code">Log2</code>, <code class="code">Log10</code>, <code class="code">Exp2</code> and <code class="code">Exp10</code> indicate the base used, in <code class="code">log</code> and <code class="code">exp</code> the natural base is used, i.e. <span class="SimpleMath">e</span>.</p> |
| 408 | |
| 409 | <p><a id="X845ACF3A78BD2771" name="X845ACF3A78BD2771"></a></p> |
| 410 | |
| 411 | <h4>19.3 <span class="Heading">High-precision-specific methods</span></h4> |
| 412 | |
| 413 | <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> |
| 414 | |
| 415 | <p>A package must create a record with fields (all optional)</p> |
| 416 | |
| 417 | |
| 418 | <dl> |
| 419 | <dt><strong class="Mark">creator</strong></dt> |
| 420 | <dd><p>a function converting strings to floating-point;</p> |
| 421 | |
| 422 | </dd> |
| 423 | <dt><strong class="Mark">eager</strong></dt> |
| 424 | <dd><p>a character allowing immediate conversion to floating-point;</p> |
| 425 | |
| 426 | </dd> |
| 427 | <dt><strong class="Mark">objbyextrep</strong></dt> |
| 428 | <dd><p>a function creating a floating-point number out of a list <code class="code">[mantissa,exponent]</code>;</p> |
| 429 | |
| 430 | </dd> |
| 431 | <dt><strong class="Mark">filter</strong></dt> |
| 432 | <dd><p>a filter for the new floating-point objects;</p> |
| 433 | |
| 434 | </dd> |
| 435 | <dt><strong class="Mark">constants</strong></dt> |
| 436 | <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> |
| 437 | |
| 438 | </dd> |
| 439 | </dl> |
| 440 | <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> |
| 441 | |
| 442 | <p>It must then install methods for all arithmetic and numerical operations: <code class="code">SUM</code>, <code class="code">Exp</code>, ...</p> |
| 443 | |
| 444 | <p>The user chooses that implementation by calling <code class="func">SetFloats</code> (<a href="chap19.html#X7A962B0983FA66E8"><span class="RefLink">19.2-4</span></a>) with the record as argument, and with an optional second argument requesting a precision in binary digits.</p> |
| 445 | |
| 446 | <p><a id="X7E8F6EFB87A65F78" name="X7E8F6EFB87A65F78"></a></p> |
| 447 | |
| 448 | <h4>19.4 <span class="Heading">Complex arithmetic</span></h4> |
| 449 | |
| 450 | <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>. They may also be created using <code class="func">NewFloat</code> (<a href="chap19.html#X86D5EA93813FB6C4"><span class="RefLink">19.2-1</span></a>) with three arguments: the float filter, the real part, and the imaginary part.</p> |
| 451 | |
| 452 | <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> |
| 453 | |
| 454 | <p><a id="X7B0269D983F96677" name="X7B0269D983F96677"></a></p> |
| 455 | |
| 456 | <h5>19.4-1 Argument</h5> |
| 457 | |
| 458 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Argument</code>( <var class="Arg">z</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 459 | <p>Returns the argument of the complex number <var class="Arg">z</var>, namely the value <code class="code">Atan2(ImaginaryPart(z),RealPart(z))</code>.</p> |
| 460 | |
| 461 | <p><a id="X7E57B09C80136484" name="X7E57B09C80136484"></a></p> |
| 462 | |
| 463 | <h4>19.5 <span class="Heading">Interval-specific methods</span></h4> |
| 464 | |
| 465 | <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.</p> |
| 466 | |
| 467 | <p>Note the usual convention that intervals are compared as in <span class="SimpleMath">[a,b]≤[c,d]</span> if and only if <span class="SimpleMath">a≤ c</span> and <span class="SimpleMath">b≤ d</span>.</p> |
| 468 | |
| 469 | <p><a id="X7C34D1D185802F2F" name="X7C34D1D185802F2F"></a></p> |
| 470 | |
| 471 | <h5>19.5-1 Sup</h5> |
| 472 | |
| 473 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Sup</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 474 | <p>Returns the supremum of the interval <var class="Arg">x</var>.</p> |
| 475 | |
| 476 | <p><a id="X78F1E457814FD1FD" name="X78F1E457814FD1FD"></a></p> |
| 477 | |
| 478 | <h5>19.5-2 Inf</h5> |
| 479 | |
| 480 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Inf</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 481 | <p>Returns the infimum of the interval <var class="Arg">x</var>.</p> |
| 482 | |
| 483 | <p><a id="X829581A485F55996" name="X829581A485F55996"></a></p> |
| 484 | |
| 485 | <h5>19.5-3 Mid</h5> |
| 486 | |
| 487 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Mid</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 488 | <p>Returns the midpoint of the interval <var class="Arg">x</var>.</p> |
| 489 | |
| 490 | <p><a id="X7FE540B387B0012C" name="X7FE540B387B0012C"></a></p> |
| 491 | |
| 492 | <h5>19.5-4 AbsoluteDiameter</h5> |
| 493 | |
| 494 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ AbsoluteDiameter</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 495 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Diameter</code>( <var class="Arg">x</var> )</td><td class="tdright">( operation )</td></tr></table></div> |
| 496 | <p>Returns the absolute diameter of the interval <var class="Arg">x</var>, namely the difference <code class="code">Sup(x)-Inf(x)</code>.</p> |
| 497 | |
| 498 | <p><a id="X7CA771757F441592" name="X7CA771757F441592"></a></p> |
| 499 | |
| 500 | <h5>19.5-5 RelativeDiameter</h5> |
| 501 | |
| 502 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ RelativeDiameter</code>( <var class="Arg">x</var> )</td><td class="tdright">( attribute )</td></tr></table></div> |
| 503 | <p>Returns the relative diameter of the interval <var class="Arg">x</var>, namely <code class="code">(Sup(x)-Inf(x))/AbsoluteValue(Min(x))</code>.</p> |
| 504 | |
| 505 | <p><a id="X86D22AE57E2D84B2" name="X86D22AE57E2D84B2"></a></p> |
| 506 | |
| 507 | <h5>19.5-6 IsDisjoint</h5> |
| 508 | |
| 509 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsDisjoint</code>( <var class="Arg">x1</var>, <var class="Arg">x2</var> )</td><td class="tdright">( operation )</td></tr></table></div> |
| 510 | <p>Returns <code class="keyw">true</code> if the two intervals <var class="Arg">x1</var>, <var class="Arg">x2</var> are disjoint.</p> |
| 511 | |
| 512 | <p><a id="X7A5E0C3E79837EB8" name="X7A5E0C3E79837EB8"></a></p> |
| 513 | |
| 514 | <h5>19.5-7 IsSubset</h5> |
| 515 | |
| 516 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsSubset</code>( <var class="Arg">x1</var>, <var class="Arg">x2</var> )</td><td class="tdright">( operation )</td></tr></table></div> |
| 517 | <p>Returns <code class="keyw">true</code> if the interval <var class="Arg">x1</var> contains <var class="Arg">x2</var>.</p> |
| 518 | |
| 519 | <p><a id="X85191E1679936CE9" name="X85191E1679936CE9"></a></p> |
| 520 | |
| 521 | <h5>19.5-8 IncreaseInterval</h5> |
| 522 | |
| 523 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IncreaseInterval</code>( <var class="Arg">x</var>, <var class="Arg">delta</var> )</td><td class="tdright">( operation )</td></tr></table></div> |
| 524 | <p>Returns an interval with same midpoint as <var class="Arg">x</var> but absolute diameter increased by <var class="Arg">delta</var>.</p> |
| 525 | |
| 526 | <p><a id="X879EE14282DD1539" name="X879EE14282DD1539"></a></p> |
| 527 | |
| 528 | <h5>19.5-9 BlowupInterval</h5> |
| 529 | |
| 530 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ BlowupInterval</code>( <var class="Arg">x</var>, <var class="Arg">ratio</var> )</td><td class="tdright">( operation )</td></tr></table></div> |
| 531 | <p>Returns an interval with same midpoint as <var class="Arg">x</var> but relative diameter increased by <var class="Arg">ratio</var>.</p> |
| 532 | |
| 533 | <p><a id="X7EC15DAE7CBBB42E" name="X7EC15DAE7CBBB42E"></a></p> |
| 534 | |
| 535 | <h5>19.5-10 BisectInterval</h5> |
| 536 | |
| 537 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ BisectInterval</code>( <var class="Arg">x</var> )</td><td class="tdright">( operation )</td></tr></table></div> |
| 538 | <p>Returns a list of two intervals whose union equals the interval <var class="Arg">x</var>.</p> |
| 539 | |
| 540 | |
| 541 | <div class="chlinkprevnextbot"> <a href="chap0.html">[Top of Book]</a> <a href="chap0.html#contents">[Contents]</a> <a href="chap18.html">[Previous Chapter]</a> <a href="chap20.html">[Next Chapter]</a> </div> |
| 542 | |
| 543 | |
| 544 | <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> |
| 545 | |
| 546 | <hr /> |
| 547 | <p class="foot">generated by <a href="https://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p> |
| 548 | </body> |
| 549 | </html> |