1 | |
---|
2 | /**************************************************************************\ |
---|
3 | |
---|
4 | MODULE: tools |
---|
5 | |
---|
6 | SUMMARY: |
---|
7 | |
---|
8 | Some useful tools that are used throughout NTL. |
---|
9 | |
---|
10 | \**************************************************************************/ |
---|
11 | |
---|
12 | #include <cstdlib> |
---|
13 | #include <cmath> |
---|
14 | #include <iostream> |
---|
15 | |
---|
16 | #include <NTL/config.h> |
---|
17 | #include <NTL/mach_desc.h> |
---|
18 | |
---|
19 | |
---|
20 | |
---|
21 | |
---|
22 | double GetTime(); |
---|
23 | // returns number of seconds of CPU time used by this process; |
---|
24 | |
---|
25 | void PrintTime(ostream& s, double t); |
---|
26 | // prints the time t (in seconds) to s in the format |
---|
27 | // ss or mm:ss or hh:mm:ss, |
---|
28 | // where the value t is first rounded to the nearest integer. |
---|
29 | |
---|
30 | void Error(const char *s); |
---|
31 | // print an error message and call abort |
---|
32 | |
---|
33 | extern void (*ErrorCallback)(); |
---|
34 | // A pointer (initially NULL) to a callback function. |
---|
35 | // This function will be called by the Error function, |
---|
36 | // as well as other functions, before calling abort(). |
---|
37 | // Note that the callback function is expected to have |
---|
38 | // C++ linkage, as it is called directly by a C++ function, |
---|
39 | // even though the latter function may be called from a |
---|
40 | // C function. |
---|
41 | |
---|
42 | long IsWhiteSpace(long c); |
---|
43 | // returns 1 if c is "wite space" (as defined by isspace is the |
---|
44 | // standard library...usually blanks, tabs, newlines), and 0 otherwise. |
---|
45 | |
---|
46 | long SkipWhiteSpace(istream& s); |
---|
47 | // skips white space (as defined by IsWhiteSpace). |
---|
48 | // Return value is 0 if end-of-file is reached; otherwise, |
---|
49 | // return value is 1. |
---|
50 | |
---|
51 | // This routine is useful in conjuction with input routines, |
---|
52 | // like NTL's, that raise an error if an input item is |
---|
53 | // ill-formed or missing. |
---|
54 | |
---|
55 | long IsEOFChar(long c); |
---|
56 | // test if c == EOF |
---|
57 | |
---|
58 | |
---|
59 | long CharToIntVal(long c); |
---|
60 | // returns the hexidecimal value of c if c is '0'..'9', 'A'..'F', or 'a'..'f'; |
---|
61 | // otherwise, the return value is -1. |
---|
62 | |
---|
63 | char IntValToChar(long x); |
---|
64 | // returns the hexadecimal digit '0'..'9', 'a'..'f' representing x; |
---|
65 | // an error is raised if x < 0 or x > 15. |
---|
66 | |
---|
67 | long IsFinite(double *p); |
---|
68 | // Returns 1 if *p is a "finite" floating point number. |
---|
69 | // A pointer is used to ensure that the number is in memory, |
---|
70 | // which on some architectures (notably x86/Pentium) can make a difference. |
---|
71 | |
---|
72 | // some min/max and swap routines: |
---|
73 | |
---|
74 | int min(int a, int b); |
---|
75 | int max(int a, int b); |
---|
76 | |
---|
77 | long min(long a, long b); |
---|
78 | long max(long a, long b); |
---|
79 | |
---|
80 | long min(int a, long b); |
---|
81 | long max(int a, long b); |
---|
82 | |
---|
83 | long min(long a, int b); |
---|
84 | long max(long a, int b); |
---|
85 | |
---|
86 | void swap(long& a, long& b); |
---|
87 | void swap(int& a, int& b); |
---|
88 | |
---|
89 | |
---|
90 | // defined here are all the conversion routines among the types |
---|
91 | // int, long, float, double. See conversions.txt for complete details. |
---|
92 | |
---|
93 | |
---|
94 | // The following platform-dependent macros are defined: |
---|
95 | |
---|
96 | #define NTL_BITS_PER_LONG (...) /* bits in a long */ |
---|
97 | #define NTL_MAX_LONG (...) /* max value of a long */ |
---|
98 | #define NTL_MIN_LONG (...) /* min value of a long */ |
---|
99 | |
---|
100 | #define NTL_BITS_PER_INT (...) /* bits in a int */ |
---|
101 | #define NTL_MAX_INT (...) /* max value of a int */ |
---|
102 | #define NTL_MIN_INT (...) /* min value of a int */ |
---|
103 | |
---|
104 | #define NTL_DOUBLE_PRECISION (...) /* # of bits of precision in a double */ |
---|
105 | #define NTL_FDOUBLE_PRECISION (...) /* the double value |
---|
106 | 2^{NTL_DOUBLE_PRECISION-1} */ |
---|
107 | |
---|
108 | #define NTL_ARITH_RIGHT_SHIFT (...) /* 1 if signed right-shift is |
---|
109 | arithmetic; 0 otherwise */ |
---|
110 | |
---|
111 | #define NTL_EXT_DOUBLE (...) /* 1 if platform has "extended" doubles; |
---|
112 | 0 otherwise */ |
---|
113 | |
---|
114 | |
---|
115 | |
---|