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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>~/ntl-11.4.2/doc/xdouble.cpp.html</title>
<meta name="Generator" content="Vim/8.0">
<meta name="plugin-version" content="vim7.4_v2">
<meta name="syntax" content="cpp">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="macvim">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #ffffff; }
body { font-family: monospace; color: #000000; background-color: #ffffff; }
* { font-size: 1em; }
.String { color: #4a708b; }
.PreProc { color: #1874cd; }
.Statement { color: #b03060; font-weight: bold; }
.Comment { color: #0000ee; font-style: italic; }
.Type { color: #008b00; font-weight: bold; }
-->
</style>
<script type='text/javascript'>
<!--
-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">/*</span><span class="Comment">*************************************************************************\</span>
<span class="Comment">MODULE: xdouble </span>
<span class="Comment">SUMMARY:</span>
<span class="Comment">The class xdouble is used to represent floating point numbers with the</span>
<span class="Comment">same precision as a 'double', but with extended exponent range</span>
<span class="Comment">(offering a few more bits than that of a 'long' for the exponent).</span>
<span class="Comment">The programming interface for xdoubles is almost identical to that of</span>
<span class="Comment">ordinary doubles.</span>
<span class="Comment">\*************************************************************************</span><span class="Comment">*/</span>
<span class="PreProc">#include </span><span class="String"><NTL/ZZ.h></span>
<span class="Type">class</span> xdouble {
<span class="Statement">public</span>:
xdouble(); <span class="Comment">// = 0</span>
xdouble(<span class="Type">const</span> xdouble& a); <span class="Comment">// copy constructor</span>
<span class="Type">explicit</span> xdouble(<span class="Type">double</span> a); <span class="Comment">// promotion constructor</span>
xdouble& <span class="Statement">operator</span>=(<span class="Type">const</span> xdouble& a); <span class="Comment">// assignment operator</span>
xdouble& <span class="Statement">operator</span>=(<span class="Type">double</span> a);
~xdouble();
<span class="Type">double</span> mantissa() <span class="Type">const</span>; <span class="Comment">// read-only access to mantissa</span>
<span class="Type">long</span> exponent() <span class="Type">const</span>; <span class="Comment">// read-only access to exponenent</span>
<span class="Type">static</span> <span class="Type">void</span> SetOutputPrecision(<span class="Type">long</span> p);
<span class="Comment">// This sets the number of decimal digits to be output. Default is</span>
<span class="Comment">// 10.</span>
<span class="Type">static</span> <span class="Type">long</span> OutputPrecision();
<span class="Comment">// returns current output precision.</span>
};
<span class="Comment">/*</span><span class="Comment">*************************************************************************\</span>
<span class="Comment"> Arithmetic Operations</span>
<span class="Comment">The following are the standard arithmetic operators, whose meaning should </span>
<span class="Comment">be clear.</span>
<span class="Comment">\*************************************************************************</span><span class="Comment">*/</span>
xdouble <span class="Statement">operator</span>+(<span class="Type">const</span> xdouble& a, <span class="Type">const</span> xdouble& b);
xdouble <span class="Statement">operator</span>-(<span class="Type">const</span> xdouble& a, <span class="Type">const</span> xdouble& b);
xdouble <span class="Statement">operator</span>*(<span class="Type">const</span> xdouble& a, <span class="Type">const</span> xdouble& b);
xdouble <span class="Statement">operator</span>/(<span class="Type">const</span> xdouble& a, <span class="Type">const</span> xdouble& b);
<span class="Comment">// PROMOTIONS: +, -, *, / promote double to xdouble on (a, b).</span>
xdouble <span class="Statement">operator</span>-(<span class="Type">const</span> xdouble& a);
xdouble& <span class="Statement">operator</span>+=(xdouble& a, <span class="Type">const</span> xdouble& b);
xdouble& <span class="Statement">operator</span>+=(xdouble& a, <span class="Type">double</span> b);
xdouble& <span class="Statement">operator</span>-=(xdouble& a, <span class="Type">const</span> xdouble& b);
xdouble& <span class="Statement">operator</span>-=(xdouble& a, <span class="Type">double</span> b);
xdouble& <span class="Statement">operator</span>*=(xdouble& a, <span class="Type">const</span> xdouble& b);
xdouble& <span class="Statement">operator</span>*=(xdouble& a, <span class="Type">double</span> b);
xdouble& <span class="Statement">operator</span>/=(xdouble& a, <span class="Type">const</span> xdouble& b);
xdouble& <span class="Statement">operator</span>/=(xdouble& a, xdouble b);
xdouble& <span class="Statement">operator</span>++(xdouble& a); <span class="Comment">// prefix</span>
<span class="Type">void</span> <span class="Statement">operator</span>++(xdouble& a, <span class="Type">int</span>); <span class="Comment">// postfix</span>
xdouble& <span class="Statement">operator</span>--(xdouble& a); <span class="Comment">// prefix</span>
<span class="Type">void</span> <span class="Statement">operator</span>--(xdouble& a, <span class="Type">int</span>); <span class="Comment">// postfix</span>
<span class="Comment">/*</span><span class="Comment">*************************************************************************\</span>
<span class="Comment"> Comparison</span>
<span class="Comment">\*************************************************************************</span><span class="Comment">*/</span>
<span class="Type">long</span> sign(<span class="Type">const</span> xdouble& a);
<span class="Comment">// returns sign (+1, -1, 0) of a</span>
<span class="Type">long</span> compare(<span class="Type">const</span> xdouble& a, <span class="Type">const</span> xdouble& b);
<span class="Comment">// returns sign of a - b</span>
<span class="Type">long</span> <span class="Statement">operator</span>==(<span class="Type">const</span> xdouble& a, <span class="Type">const</span> xdouble& b);
<span class="Type">long</span> <span class="Statement">operator</span>!=(<span class="Type">const</span> xdouble& a, <span class="Type">const</span> xdouble& b);
<span class="Type">long</span> <span class="Statement">operator</span><=(<span class="Type">const</span> xdouble& a, <span class="Type">const</span> xdouble& b);
<span class="Type">long</span> <span class="Statement">operator</span>>=(<span class="Type">const</span> xdouble& a, <span class="Type">const</span> xdouble& b);
<span class="Type">long</span> <span class="Statement">operator</span> <(<span class="Type">const</span> xdouble& a, <span class="Type">const</span> xdouble& b);
<span class="Type">long</span> <span class="Statement">operator</span> >(<span class="Type">const</span> xdouble& a, <span class="Type">const</span> xdouble& b);
<span class="Comment">// PROMOTIONS: compare and operators ==, ..., > promote double to xdouble</span>
<span class="Comment">// on (a, b).</span>
<span class="Comment">/*</span><span class="Comment">*************************************************************************\</span>
<span class="Comment"> Input/Output</span>
<span class="Comment">Input Syntax:</span>
<span class="Comment"><number>: [ "-" ] <unsigned-number></span>
<span class="Comment"><unsigned-number>: <dotted-number> [ <e-part> ] | <e-part></span>
<span class="Comment"><dotted-number>: <digits> | <digits> "." <digits> | "." <digits> | <digits> "."</span>
<span class="Comment"><digits>: <digit> <digits> | <digit></span>
<span class="Comment"><digit>: "0" | ... | "9"</span>
<span class="Comment"><e-part>: ( "E" | "e" ) [ "+" | "-" ] <digits></span>
<span class="Comment">Examples of valid input:</span>
<span class="Comment">17 1.5 0.5 .5 5. -.5 e10 e-10 e+10 1.5e10 .5e10 .5E10</span>
<span class="Comment">Note that the number of decimal digits of precision that are used</span>
<span class="Comment">for output can be set to any number p >= 1 by calling</span>
<span class="Comment">the routine xdouble::SetOutputPrecision(p). </span>
<span class="Comment">The default value of p is 10.</span>
<span class="Comment">The current value of p is returned by a call to xdouble::OutputPrecision().</span>
<span class="Comment">\*************************************************************************</span><span class="Comment">*/</span>
ostream& <span class="Statement">operator</span><<(ostream& s, <span class="Type">const</span> xdouble& a);
istream& <span class="Statement">operator</span>>>(istream& s, xdouble& x);
<span class="Comment">/*</span><span class="Comment">*************************************************************************\</span>
<span class="Comment"> Miscellaneous</span>
<span class="Comment">\*************************************************************************</span><span class="Comment">*/</span>
xdouble trunc(<span class="Type">const</span> xdouble& a); <span class="Comment">// returns integer obtained by truncating</span>
xdouble floor(<span class="Type">const</span> xdouble& a); <span class="Comment">// returns greatest integer <= a</span>
xdouble ceil(<span class="Type">const</span> xdouble& a); <span class="Comment">// returns smallest integer >= a</span>
xdouble fabs(<span class="Type">const</span> xdouble& a); <span class="Comment">// returns |a|</span>
xdouble sqrt(<span class="Type">const</span> xdouble& a); <span class="Comment">// returns a^{1/2}; error is raised if a < 0</span>
<span class="Type">double</span> log(<span class="Type">const</span> xdouble& a); <span class="Comment">// returns log(a) (note return val is double!)</span>
xdouble xexp(<span class="Type">double</span> a); <span class="Comment">// returns exp(a) (note argument is double!)</span>
xdouble exp(<span class="Type">const</span> <span class="Type">double</span>& a); <span class="Comment">// equivalent to xexp(to_double(a))</span>
<span class="Type">void</span> power(xdouble& z, <span class="Type">const</span> xdouble& a, <span class="Type">const</span> ZZ& e);
xdouble power(<span class="Type">const</span> xdouble& a, <span class="Type">const</span> ZZ& e);
<span class="Type">void</span> power(xdouble& z, <span class="Type">const</span> xdouble& a, <span class="Type">long</span> e);
xdouble power(<span class="Type">const</span> xdouble& a, <span class="Type">long</span> e);
<span class="Comment">// z = a^e, e may be negative</span>
<span class="Type">void</span> power2(xdouble& z, <span class="Type">long</span> e);
xdouble power2_xdouble(<span class="Type">long</span> e);
<span class="Comment">// z = 2^e, e may be negative</span>
<span class="Type">void</span> MulAdd(xdouble& z, <span class="Type">const</span> xdouble& a, <span class="Type">const</span> xdouble& b, <span class="Type">const</span> xdouble& c);
xdouble MulAdd(<span class="Type">const</span> xdouble& a, <span class="Type">const</span> xdouble& b, <span class="Type">const</span> xdouble& c);
<span class="Comment">// z = a + b*c, but faster</span>
<span class="Type">void</span> MulSub(xdouble& z, <span class="Type">const</span> xdouble& a, <span class="Type">const</span> xdouble& b, <span class="Type">const</span> xdouble& c);
xdouble MulSub(<span class="Type">const</span> xdouble& a, <span class="Type">const</span> xdouble& b, <span class="Type">const</span> xdouble& c);
<span class="Comment">// z = a - b*c, but faster</span>
<span class="Comment">/*</span><span class="Comment">*************************************************************************\</span>
<span class="Comment">Implementation details:</span>
<span class="Comment">An xdouble is represented as a mantissa/exponent pair (x, e), where x</span>
<span class="Comment">is a double and e is a long. The real number represented by (x, e) is</span>
<span class="Comment">x * NTL_XD_BOUND^e, where</span>
<span class="Comment"> NTL_XD_BOUND = NTL_XD_HBOUND^2, and</span>
<span class="Comment"> NTL_XD_HBOUND = 2^{(max(NTL_DOUBLE_PRECISION,NTL_BITS_PER_LONG)+4)}.</span>
<span class="Comment">Also, the mantissa x satisfies 1/NTL_XD_HBOUND <= |x| <= NTL_XD_HBOUND, except</span>
<span class="Comment">that the number 0 is always represented as (0, 0). </span>
<span class="Comment">Both NTL_XD_BOUND and NTL_XD_HBOUND are macros defined in <NTL/xdouble.h>.</span>
<span class="Comment">SIZE INVARIANT: |e| < 2^(NTL_BITS_PER_LONG-4).</span>
<span class="Comment">\*************************************************************************</span><span class="Comment">*/</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->
|