/usr/share/doc/libntl-dev/NTL/tools.cpp.html is in libntl-dev 9.9.1-3.
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 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>/Volumes/unix-files/u/ntl-new/ntl-9.9.0dev/doc/tools.cpp.html</title>
<meta name="Generator" content="Vim/7.1">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#ffffff" text="#000000"><font face="monospace">
<br>
<font color="#0000ed"><i>/*</i></font><font color="#0000ed"><i>*************************************************************************\</i></font><br>
<br>
<font color="#0000ed"><i>MODULE: tools</i></font><br>
<br>
<font color="#0000ed"><i>SUMMARY:</i></font><br>
<br>
<font color="#0000ed"><i>Some useful tools that are used throughout NTL.</i></font><br>
<br>
<font color="#0000ed"><i>\*************************************************************************</i></font><font color="#0000ed"><i>*/</i></font><br>
<br>
<font color="#1773cc">#include </font><font color="#4a6f8b"><cstdlib></font><br>
<font color="#1773cc">#include </font><font color="#4a6f8b"><cmath></font><br>
<font color="#1773cc">#include </font><font color="#4a6f8b"><iostream></font><br>
<br>
<font color="#1773cc">#include </font><font color="#4a6f8b"><NTL/config.h></font><br>
<font color="#1773cc">#include </font><font color="#4a6f8b"><NTL/mach_desc.h></font><br>
<br>
<br>
<br>
<br>
<font color="#008b00"><b>double</b></font> GetTime();<br>
<font color="#0000ed"><i>// returns number of seconds of CPU time used by this process;</i></font><br>
<br>
<font color="#008b00"><b>void</b></font> PrintTime(ostream& s, <font color="#008b00"><b>double</b></font> t);<br>
<font color="#0000ed"><i>// prints the time t (in seconds) to s in the format</i></font><br>
<font color="#0000ed"><i>// ss or mm:ss or hh:mm:ss,</i></font><br>
<font color="#0000ed"><i>// where the value t is first rounded to the nearest integer.</i></font><br>
<br>
<br>
<font color="#008b00"><b>long</b></font> IsWhiteSpace(<font color="#008b00"><b>long</b></font> c);<br>
<font color="#0000ed"><i>// returns 1 if c is "white space" (as defined by isspace is the</i></font><br>
<font color="#0000ed"><i>// standard library...usually blanks, tabs, newlines), and 0 otherwise.</i></font><br>
<br>
<font color="#008b00"><b>long</b></font> SkipWhiteSpace(istream& s);<br>
<font color="#0000ed"><i>// skips white space (as defined by IsWhiteSpace).</i></font><br>
<font color="#0000ed"><i>// Return value is 0 if end-of-file is reached; otherwise,</i></font><br>
<font color="#0000ed"><i>// return value is 1.</i></font><br>
<br>
<br>
<font color="#008b00"><b>long</b></font> IsEOFChar(<font color="#008b00"><b>long</b></font> c);<br>
<font color="#0000ed"><i>// test if c == EOF</i></font><br>
<br>
<br>
<font color="#008b00"><b>long</b></font> CharToIntVal(<font color="#008b00"><b>long</b></font> c);<br>
<font color="#0000ed"><i>// returns the hexidecimal value of c if c is '0'..'9', 'A'..'F', or 'a'..'f';</i></font><br>
<font color="#0000ed"><i>// otherwise, the return value is -1.</i></font><br>
<br>
<font color="#008b00"><b>char</b></font> IntValToChar(<font color="#008b00"><b>long</b></font> x);<br>
<font color="#0000ed"><i>// returns the hexadecimal digit '0'..'9', 'a'..'f' representing x;</i></font><br>
<font color="#0000ed"><i>// an error is raised if x < 0 or x > 15.</i></font><br>
<br>
<font color="#008b00"><b>long</b></font> IsFinite(<font color="#008b00"><b>double</b></font> *p);<br>
<font color="#0000ed"><i>// Returns 1 if *p is a "finite" floating point number.</i></font><br>
<font color="#0000ed"><i>// A pointer is used to ensure that the number is in memory,</i></font><br>
<font color="#0000ed"><i>// which on some architectures (notably x86/Pentium) can make a difference.</i></font><br>
<br>
<font color="#0000ed"><i>// some min/max and swap routines:</i></font><br>
<br>
<font color="#008b00"><b>int</b></font> min(<font color="#008b00"><b>int</b></font> a, <font color="#008b00"><b>int</b></font> b);<br>
<font color="#008b00"><b>int</b></font> max(<font color="#008b00"><b>int</b></font> a, <font color="#008b00"><b>int</b></font> b);<br>
<br>
<font color="#008b00"><b>long</b></font> min(<font color="#008b00"><b>long</b></font> a, <font color="#008b00"><b>long</b></font> b);<br>
<font color="#008b00"><b>long</b></font> max(<font color="#008b00"><b>long</b></font> a, <font color="#008b00"><b>long</b></font> b);<br>
<br>
<font color="#008b00"><b>long</b></font> min(<font color="#008b00"><b>int</b></font> a, <font color="#008b00"><b>long</b></font> b);<br>
<font color="#008b00"><b>long</b></font> max(<font color="#008b00"><b>int</b></font> a, <font color="#008b00"><b>long</b></font> b);<br>
<br>
<font color="#008b00"><b>long</b></font> min(<font color="#008b00"><b>long</b></font> a, <font color="#008b00"><b>int</b></font> b);<br>
<font color="#008b00"><b>long</b></font> max(<font color="#008b00"><b>long</b></font> a, <font color="#008b00"><b>int</b></font> b);<br>
<br>
<font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>int</b></font> min(<font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>int</b></font> a, <font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>int</b></font> b);<br>
<font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>int</b></font> max(<font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>int</b></font> a, <font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>int</b></font> b);<br>
<br>
<font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>long</b></font> min(<font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>long</b></font> a, <font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>long</b></font> b);<br>
<font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>long</b></font> max(<font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>long</b></font> a, <font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>long</b></font> b);<br>
<br>
<font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>long</b></font> min(<font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>int</b></font> a, <font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>long</b></font> b);<br>
<font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>long</b></font> max(<font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>int</b></font> a, <font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>long</b></font> b);<br>
<br>
<font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>long</b></font> min(<font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>long</b></font> a, <font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>int</b></font> b);<br>
<font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>long</b></font> max(<font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>long</b></font> a, <font color="#008b00"><b>unsigned</b></font> <font color="#008b00"><b>int</b></font> b);<br>
<br>
<br>
<font color="#008b00"><b>void</b></font> swap(<font color="#008b00"><b>long</b></font>& a, <font color="#008b00"><b>long</b></font>& b);<br>
<font color="#008b00"><b>void</b></font> swap(<font color="#008b00"><b>int</b></font>& a, <font color="#008b00"><b>int</b></font>& b);<br>
<br>
<br>
<font color="#0000ed"><i>// defined here are all the conversion routines among the types </i></font><br>
<font color="#0000ed"><i>// int, long, float, double. See conversions.txt for complete details.</i></font><br>
<br>
<br>
<br>
<font color="#0000ed"><i>// The following platform-dependent macros are defined:</i></font><br>
<br>
<font color="#1773cc">#define NTL_BITS_PER_LONG (...) </font><font color="#0000ed"><i>/*</i></font><font color="#0000ed"><i> bits in a long </i></font><font color="#0000ed"><i>*/</i></font><br>
<font color="#1773cc">#define NTL_MAX_LONG (...) </font><font color="#0000ed"><i>/*</i></font><font color="#0000ed"><i> max value of a long </i></font><font color="#0000ed"><i>*/</i></font><br>
<font color="#1773cc">#define NTL_MIN_LONG (...) </font><font color="#0000ed"><i>/*</i></font><font color="#0000ed"><i> min value of a long </i></font><font color="#0000ed"><i>*/</i></font><br>
<br>
<font color="#1773cc">#define NTL_BITS_PER_INT (...) </font><font color="#0000ed"><i>/*</i></font><font color="#0000ed"><i> bits in a int </i></font><font color="#0000ed"><i>*/</i></font><br>
<font color="#1773cc">#define NTL_MAX_INT (...) </font><font color="#0000ed"><i>/*</i></font><font color="#0000ed"><i> max value of a int </i></font><font color="#0000ed"><i>*/</i></font><br>
<font color="#1773cc">#define NTL_MIN_INT (...) </font><font color="#0000ed"><i>/*</i></font><font color="#0000ed"><i> min value of a int </i></font><font color="#0000ed"><i>*/</i></font><br>
<br>
<font color="#1773cc">#define NTL_DOUBLE_PRECISION (...) </font><font color="#0000ed"><i>/*</i></font><font color="#0000ed"><i> # of bits of precision in a double </i></font><font color="#0000ed"><i>*/</i></font><br>
<font color="#1773cc">#define NTL_FDOUBLE_PRECISION (...) </font><font color="#0000ed"><i>/*</i></font><font color="#0000ed"><i> the double value </i></font><br>
<font color="#0000ed"><i> 2^{NTL_DOUBLE_PRECISION-1} </i></font><font color="#0000ed"><i>*/</i></font><br>
<br>
<font color="#1773cc">#define NTL_ARITH_RIGHT_SHIFT (...) </font><font color="#0000ed"><i>/*</i></font><font color="#0000ed"><i> 1 if signed right-shift is</i></font><br>
<font color="#0000ed"><i> arithmetic; 0 otherwise </i></font><font color="#0000ed"><i>*/</i></font><br>
<br>
<font color="#1773cc">#define NTL_EXT_DOUBLE (...) </font><font color="#0000ed"><i>/*</i></font><font color="#0000ed"><i> 1 if platform has "extended" doubles;</i></font><br>
<font color="#0000ed"><i> 0 otherwise </i></font><font color="#0000ed"><i>*/</i></font><br>
<br>
<br>
<font color="#0000ed"><i>// ERROR HANDLING</i></font><br>
<br>
<font color="#008b00"><b>void</b></font> TerminalError(<font color="#008b00"><b>const</b></font> <font color="#008b00"><b>char</b></font> *s);<br>
<font color="#0000ed"><i>// print an error message and call abort</i></font><br>
<br>
<font color="#008b00"><b>extern</b></font> <font color="#008b00"><b>void</b></font> (*ErrorMsgCallback)(<font color="#008b00"><b>const</b></font> <font color="#008b00"><b>char</b></font> *);<br>
<font color="#008b00"><b>extern</b></font> <font color="#008b00"><b>void</b></font> (*ErrorCallback)();<br>
<font color="#0000ed"><i>// Pointers (initially NULL) to callback functions.</i></font><br>
<font color="#0000ed"><i>// Upon encountering an unrecoverable error with an error</i></font><br>
<font color="#0000ed"><i>// message s, the following happens:</i></font><br>
<font color="#0000ed"><i>//</i></font><br>
<font color="#0000ed"><i>// if (ErrorMsgCallback)</i></font><br>
<font color="#0000ed"><i>// (*ErrorMsgCallback)(s);</i></font><br>
<font color="#0000ed"><i>// else</i></font><br>
<font color="#0000ed"><i>// cerr << s << "\n";</i></font><br>
<font color="#0000ed"><i>// </i></font><br>
<font color="#0000ed"><i>// if (ErrorCallback) (*ErrorCallback)();</i></font><br>
<font color="#0000ed"><i>// abort();</i></font><br>
<font color="#0000ed"><i>//</i></font><br>
<font color="#0000ed"><i>// NOTE: if threads are enabled, these are actually thread_local variables.</i></font><br>
<br>
<br>
<br>
<font color="#0000ed"><i>// The following classes are defined even if exceptions are not</i></font><br>
<font color="#0000ed"><i>// enabled with NTL_EXCEPTIONS</i></font><br>
<br>
<font color="#008b00"><b>class</b></font> ErrorObject : <font color="#b02f60"><b>public</b></font> runtime_error {<br>
<font color="#b02f60"><b>public</b></font>:<br>
ErrorObject(<font color="#008b00"><b>const</b></font> <font color="#008b00"><b>char</b></font> *msg);<br>
};<br>
<br>
<font color="#008b00"><b>class</b></font> LogicErrorObject : <font color="#b02f60"><b>public</b></font> ErrorObject {<br>
<font color="#b02f60"><b>public</b></font>: <br>
LogicErrorObject(<font color="#008b00"><b>const</b></font> <font color="#008b00"><b>char</b></font> *msg);<br>
};<br>
<br>
<font color="#008b00"><b>class</b></font> ArithmeticErrorObject : <font color="#b02f60"><b>public</b></font> ErrorObject {<br>
<font color="#b02f60"><b>public</b></font>: <br>
ArithmeticErrorObject(<font color="#008b00"><b>const</b></font> <font color="#008b00"><b>char</b></font> *msg);<br>
};<br>
<br>
<font color="#008b00"><b>class</b></font> ResourceErrorObject : <font color="#b02f60"><b>public</b></font> ErrorObject {<br>
<font color="#b02f60"><b>public</b></font>: <br>
ResourceErrorObject(<font color="#008b00"><b>const</b></font> <font color="#008b00"><b>char</b></font> *msg);<br>
};<br>
<br>
<font color="#008b00"><b>class</b></font> FileErrorObject : <font color="#b02f60"><b>public</b></font> ErrorObject {<br>
<font color="#b02f60"><b>public</b></font>: <br>
FileErrorObject(<font color="#008b00"><b>const</b></font> <font color="#008b00"><b>char</b></font> *msg);<br>
};<br>
<br>
<font color="#008b00"><b>class</b></font> InputErrorObject : <font color="#b02f60"><b>public</b></font> ErrorObject {<br>
<font color="#b02f60"><b>public</b></font>: <br>
InputErrorObject(<font color="#008b00"><b>const</b></font> <font color="#008b00"><b>char</b></font> *msg);<br>
};<br>
<br>
<br>
<font color="#0000ed"><i>// The following functions throw the indicated exception if</i></font><br>
<font color="#0000ed"><i>// exceptions are enabled with NTL_EXCEPTIONS; otherwise,</i></font><br>
<font color="#0000ed"><i>// they simply invoke TerminalError.</i></font><br>
<br>
<font color="#008b00"><b>void</b></font> MemoryError();<br>
<font color="#0000ed"><i>// throws bad_alloc</i></font><br>
<br>
<font color="#008b00"><b>void</b></font> Error(<font color="#008b00"><b>const</b></font> <font color="#008b00"><b>char</b></font> *msg);<br>
<font color="#0000ed"><i>// throws ErrorObject</i></font><br>
<br>
<font color="#008b00"><b>void</b></font> LogicError(<font color="#008b00"><b>const</b></font> <font color="#008b00"><b>char</b></font> *msg);<br>
<font color="#0000ed"><i>// throws LogicErrorObject</i></font><br>
<br>
<font color="#008b00"><b>void</b></font> ArithmeticError(<font color="#008b00"><b>const</b></font> <font color="#008b00"><b>char</b></font> *msg);<br>
<font color="#0000ed"><i>// throws ArithmeticErrorObject</i></font><br>
<br>
<font color="#008b00"><b>void</b></font> ResourceError(<font color="#008b00"><b>const</b></font> <font color="#008b00"><b>char</b></font> *msg);<br>
<font color="#0000ed"><i>// throws ResourceErrorObject</i></font><br>
<br>
<font color="#008b00"><b>void</b></font> FileError(<font color="#008b00"><b>const</b></font> <font color="#008b00"><b>char</b></font> *msg);<br>
<font color="#0000ed"><i>// throws FileErrorObject</i></font><br>
<br>
<font color="#008b00"><b>void</b></font> InputError(<font color="#008b00"><b>const</b></font> <font color="#008b00"><b>char</b></font> *msg);<br>
<font color="#0000ed"><i>// throws InputErrorObject</i></font><br>
<br>
<br>
<br>
</font></body>
</html>
|