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
|
<!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/tools.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: tools</span>
<span class="Comment">SUMMARY:</span>
<span class="Comment">Some useful tools that are used throughout NTL.</span>
<span class="Comment">\*************************************************************************</span><span class="Comment">*/</span>
<span class="PreProc">#include </span><span class="String"><cstdlib></span>
<span class="PreProc">#include </span><span class="String"><cmath></span>
<span class="PreProc">#include </span><span class="String"><cstring></span>
<span class="PreProc">#include </span><span class="String"><utility></span>
<span class="PreProc">#include </span><span class="String"><iostream></span>
<span class="PreProc">#include </span><span class="String"><new></span>
<span class="PreProc">#include </span><span class="String"><stdexcept></span>
<span class="PreProc">#include </span><span class="String"><NTL/config.h></span>
<span class="PreProc">#include </span><span class="String"><NTL/mach_desc.h></span>
<span class="Type">double</span> GetTime();
<span class="Comment">// returns number of seconds of CPU time used by this process.</span>
<span class="Type">double</span> GetWallTime();
<span class="Comment">// returns the "wall clock" time, measured since the beginning</span>
<span class="Comment">// of some unspecified epoch. This is useful for measuring the</span>
<span class="Comment">// performance of multi-threaded code, since in this case,</span>
<span class="Comment">// GetTime does not return very useful information in that case.</span>
<span class="Type">void</span> PrintTime(ostream& s, <span class="Type">double</span> t);
<span class="Comment">// prints the time t (in seconds) to s in the format</span>
<span class="Comment">// ss or mm:ss or hh:mm:ss,</span>
<span class="Comment">// where the value t is first rounded to the nearest integer.</span>
<span class="Type">long</span> IsWhiteSpace(<span class="Type">long</span> c);
<span class="Comment">// returns 1 if c is "white space" (as defined by isspace is the</span>
<span class="Comment">// standard library...usually blanks, tabs, newlines), and 0 otherwise.</span>
<span class="Type">long</span> SkipWhiteSpace(istream& s);
<span class="Comment">// skips white space (as defined by IsWhiteSpace).</span>
<span class="Comment">// Return value is 0 if end-of-file is reached; otherwise,</span>
<span class="Comment">// return value is 1.</span>
<span class="Type">long</span> IsEOFChar(<span class="Type">long</span> c);
<span class="Comment">// test if c == EOF</span>
<span class="Type">long</span> CharToIntVal(<span class="Type">long</span> c);
<span class="Comment">// returns the hexidecimal value of c if c is '0'..'9', 'A'..'F', or 'a'..'f';</span>
<span class="Comment">// otherwise, the return value is -1.</span>
<span class="Type">char</span> IntValToChar(<span class="Type">long</span> x);
<span class="Comment">// returns the hexadecimal digit '0'..'9', 'a'..'f' representing x;</span>
<span class="Comment">// an error is raised if x < 0 or x > 15.</span>
<span class="Type">long</span> IsFinite(<span class="Type">double</span> *p);
<span class="Comment">// Returns 1 if *p is a "finite" floating point number.</span>
<span class="Comment">// A pointer is used to ensure that the number is in memory,</span>
<span class="Comment">// which on some architectures (notably x86/Pentium) can make a difference.</span>
<span class="Comment">// some min/max and swap routines:</span>
<span class="Type">int</span> min(<span class="Type">int</span> a, <span class="Type">int</span> b);
<span class="Type">int</span> max(<span class="Type">int</span> a, <span class="Type">int</span> b);
<span class="Type">long</span> min(<span class="Type">long</span> a, <span class="Type">long</span> b);
<span class="Type">long</span> max(<span class="Type">long</span> a, <span class="Type">long</span> b);
<span class="Type">long</span> min(<span class="Type">int</span> a, <span class="Type">long</span> b);
<span class="Type">long</span> max(<span class="Type">int</span> a, <span class="Type">long</span> b);
<span class="Type">long</span> min(<span class="Type">long</span> a, <span class="Type">int</span> b);
<span class="Type">long</span> max(<span class="Type">long</span> a, <span class="Type">int</span> b);
<span class="Type">unsigned</span> <span class="Type">int</span> min(<span class="Type">unsigned</span> <span class="Type">int</span> a, <span class="Type">unsigned</span> <span class="Type">int</span> b);
<span class="Type">unsigned</span> <span class="Type">int</span> max(<span class="Type">unsigned</span> <span class="Type">int</span> a, <span class="Type">unsigned</span> <span class="Type">int</span> b);
<span class="Type">unsigned</span> <span class="Type">long</span> min(<span class="Type">unsigned</span> <span class="Type">long</span> a, <span class="Type">unsigned</span> <span class="Type">long</span> b);
<span class="Type">unsigned</span> <span class="Type">long</span> max(<span class="Type">unsigned</span> <span class="Type">long</span> a, <span class="Type">unsigned</span> <span class="Type">long</span> b);
<span class="Type">unsigned</span> <span class="Type">long</span> min(<span class="Type">unsigned</span> <span class="Type">int</span> a, <span class="Type">unsigned</span> <span class="Type">long</span> b);
<span class="Type">unsigned</span> <span class="Type">long</span> max(<span class="Type">unsigned</span> <span class="Type">int</span> a, <span class="Type">unsigned</span> <span class="Type">long</span> b);
<span class="Type">unsigned</span> <span class="Type">long</span> min(<span class="Type">unsigned</span> <span class="Type">long</span> a, <span class="Type">unsigned</span> <span class="Type">int</span> b);
<span class="Type">unsigned</span> <span class="Type">long</span> max(<span class="Type">unsigned</span> <span class="Type">long</span> a, <span class="Type">unsigned</span> <span class="Type">int</span> b);
<span class="Type">void</span> swap(<span class="Type">long</span>& a, <span class="Type">long</span>& b);
<span class="Type">void</span> swap(<span class="Type">int</span>& a, <span class="Type">int</span>& b);
<span class="Comment">// defined here are all the conversion routines among the types </span>
<span class="Comment">// int, long, float, double. See conversions.txt for complete details.</span>
<span class="Comment">// The following platform-dependent macros are defined:</span>
<span class="PreProc">#define NTL_BITS_PER_LONG (...) </span><span class="Comment">/*</span><span class="Comment"> bits in a long </span><span class="Comment">*/</span>
<span class="PreProc">#define NTL_MAX_LONG (...) </span><span class="Comment">/*</span><span class="Comment"> max value of a long </span><span class="Comment">*/</span>
<span class="PreProc">#define NTL_MIN_LONG (...) </span><span class="Comment">/*</span><span class="Comment"> min value of a long </span><span class="Comment">*/</span>
<span class="PreProc">#define NTL_BITS_PER_INT (...) </span><span class="Comment">/*</span><span class="Comment"> bits in a int </span><span class="Comment">*/</span>
<span class="PreProc">#define NTL_MAX_INT (...) </span><span class="Comment">/*</span><span class="Comment"> max value of a int </span><span class="Comment">*/</span>
<span class="PreProc">#define NTL_MIN_INT (...) </span><span class="Comment">/*</span><span class="Comment"> min value of a int </span><span class="Comment">*/</span>
<span class="PreProc">#define NTL_DOUBLE_PRECISION (...) </span><span class="Comment">/*</span><span class="Comment"> # of bits of precision in a double </span><span class="Comment">*/</span>
<span class="PreProc">#define NTL_FDOUBLE_PRECISION (...) </span><span class="Comment">/*</span><span class="Comment"> the double value </span>
<span class="Comment"> 2^{NTL_DOUBLE_PRECISION-1} </span><span class="Comment">*/</span>
<span class="PreProc">#define NTL_ARITH_RIGHT_SHIFT (...) </span><span class="Comment">/*</span><span class="Comment"> 1 if signed right-shift is</span>
<span class="Comment"> arithmetic; 0 otherwise </span><span class="Comment">*/</span>
<span class="PreProc">#define NTL_EXT_DOUBLE (...) </span><span class="Comment">/*</span><span class="Comment"> 1 if platform has "extended" doubles;</span>
<span class="Comment"> 0 otherwise </span><span class="Comment">*/</span>
<span class="Comment">// ERROR HANDLING</span>
<span class="Type">void</span> TerminalError(<span class="Type">const</span> <span class="Type">char</span> *s);
<span class="Comment">// print an error message and call abort</span>
<span class="Type">extern</span> <span class="Type">thread_local</span> <span class="Type">void</span> (*ErrorMsgCallback)(<span class="Type">const</span> <span class="Type">char</span> *);
<span class="Type">extern</span> <span class="Type">thread_local</span> <span class="Type">void</span> (*ErrorCallback)();
<span class="Comment">// Pointers (initially NULL) to callback functions.</span>
<span class="Comment">// Upon encountering an unrecoverable error with an error</span>
<span class="Comment">// message s, the following happens:</span>
<span class="Comment">//</span>
<span class="Comment">// if (ErrorMsgCallback)</span>
<span class="Comment">// (*ErrorMsgCallback)(s);</span>
<span class="Comment">// else</span>
<span class="Comment">// cerr << s << "\n";</span>
<span class="Comment">// </span>
<span class="Comment">// if (ErrorCallback) (*ErrorCallback)();</span>
<span class="Comment">// abort();</span>
<span class="Comment">//</span>
<span class="Comment">// NOTE: if threads are enabled, these are actually thread_local variables.</span>
<span class="Comment">// The following classes are defined even if exceptions are not</span>
<span class="Comment">// enabled with NTL_EXCEPTIONS</span>
<span class="Type">class</span> ErrorObject : <span class="Statement">public</span> runtime_error {
<span class="Statement">public</span>:
ErrorObject(<span class="Type">const</span> <span class="Type">char</span> *msg);
};
<span class="Type">class</span> LogicErrorObject : <span class="Statement">public</span> ErrorObject {
<span class="Statement">public</span>:
LogicErrorObject(<span class="Type">const</span> <span class="Type">char</span> *msg);
};
<span class="Type">class</span> ArithmeticErrorObject : <span class="Statement">public</span> ErrorObject {
<span class="Statement">public</span>:
ArithmeticErrorObject(<span class="Type">const</span> <span class="Type">char</span> *msg);
};
<span class="Type">class</span> ResourceErrorObject : <span class="Statement">public</span> ErrorObject {
<span class="Statement">public</span>:
ResourceErrorObject(<span class="Type">const</span> <span class="Type">char</span> *msg);
};
<span class="Type">class</span> FileErrorObject : <span class="Statement">public</span> ErrorObject {
<span class="Statement">public</span>:
FileErrorObject(<span class="Type">const</span> <span class="Type">char</span> *msg);
};
<span class="Type">class</span> InputErrorObject : <span class="Statement">public</span> ErrorObject {
<span class="Statement">public</span>:
InputErrorObject(<span class="Type">const</span> <span class="Type">char</span> *msg);
};
<span class="Comment">// The following functions throw the indicated exception if</span>
<span class="Comment">// exceptions are enabled with NTL_EXCEPTIONS; otherwise,</span>
<span class="Comment">// they simply invoke TerminalError.</span>
<span class="Type">void</span> MemoryError();
<span class="Comment">// throws bad_alloc</span>
<span class="Type">void</span> Error(<span class="Type">const</span> <span class="Type">char</span> *msg);
<span class="Comment">// throws ErrorObject</span>
<span class="Type">void</span> LogicError(<span class="Type">const</span> <span class="Type">char</span> *msg);
<span class="Comment">// throws LogicErrorObject</span>
<span class="Type">void</span> ArithmeticError(<span class="Type">const</span> <span class="Type">char</span> *msg);
<span class="Comment">// throws ArithmeticErrorObject</span>
<span class="Type">void</span> ResourceError(<span class="Type">const</span> <span class="Type">char</span> *msg);
<span class="Comment">// throws ResourceErrorObject</span>
<span class="Type">void</span> FileError(<span class="Type">const</span> <span class="Type">char</span> *msg);
<span class="Comment">// throws FileErrorObject</span>
<span class="Type">void</span> InputError(<span class="Type">const</span> <span class="Type">char</span> *msg);
<span class="Comment">// throws InputErrorObject</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->
|