1 | |
---|
2 | /**************************************************************************\ |
---|
3 | |
---|
4 | MODULE: tools |
---|
5 | |
---|
6 | SUMMARY: |
---|
7 | |
---|
8 | Some useful tools that are used throughout NTL. |
---|
9 | |
---|
10 | \**************************************************************************/ |
---|
11 | |
---|
12 | |
---|
13 | #include <NTL/config.h> |
---|
14 | |
---|
15 | #include <stdlib.h> |
---|
16 | #include <math.h> |
---|
17 | #include <iostream.h> |
---|
18 | |
---|
19 | |
---|
20 | double GetTime(); |
---|
21 | // returns number of seconds of CPU time used by this process; |
---|
22 | |
---|
23 | void PrintTime(ostream& s, double t); |
---|
24 | // prints the time t (in seconds) to s in the format |
---|
25 | // ss or mm:ss or hh:mm:ss, |
---|
26 | // where the value t is first rounded to the nearest integer. |
---|
27 | |
---|
28 | void Error(const char *s); |
---|
29 | // print an error message and call abort |
---|
30 | |
---|
31 | long SkipWhiteSpace(istream& s); |
---|
32 | // skips white space (blanks, tabs, newlines). |
---|
33 | // Return value is 0 if end-of-file is reached; otherwise, |
---|
34 | // return value is 1. |
---|
35 | |
---|
36 | // This routine is useful in conjuction with input routines, |
---|
37 | // like NTL's, that raise an error if an input item is |
---|
38 | // ill-formed or missing. |
---|
39 | |
---|
40 | long IsFinite(double *p); |
---|
41 | // Returns 1 if *p is a "finite" floating point number. |
---|
42 | // A pointer is used to ensure that the number is in memory, |
---|
43 | // which on some architectures (notably x86/Pentium) can make a difference. |
---|
44 | |
---|
45 | // some min/max and swap routines: |
---|
46 | |
---|
47 | int min(int a, int b); |
---|
48 | int max(int a, int b); |
---|
49 | |
---|
50 | long min(long a, long b); |
---|
51 | long max(long a, long b); |
---|
52 | |
---|
53 | long min(int a, long b); |
---|
54 | long max(int a, long b); |
---|
55 | |
---|
56 | long min(long a, int b); |
---|
57 | long max(long a, int b); |
---|
58 | |
---|
59 | void swap(long& a, long& b); |
---|
60 | void swap(int& a, int& b); |
---|
61 | |
---|
62 | |
---|
63 | // defined here are all the conversion routines among the types |
---|
64 | // int, long, float, double. See conversions.txt for complete details. |
---|
65 | |
---|
66 | |
---|
67 | // The following platform-dependent macros are defined: |
---|
68 | |
---|
69 | #define NTL_BITS_PER_LONG (...) /* bits in a long */ |
---|
70 | #define NTL_MAX_LONG (...) /* max value of a long */ |
---|
71 | #define NTL_MIN_LONG (...) /* min value of a long */ |
---|
72 | |
---|
73 | #define NTL_BITS_PER_INT (...) /* bits in a int */ |
---|
74 | #define NTL_MAX_INT (...) /* max value of a int */ |
---|
75 | #define NTL_MIN_INT (...) /* min value of a int */ |
---|
76 | |
---|
77 | #define NTL_DOUBLE_PRECISION (...) /* # of bits of precision in a double */ |
---|
78 | #define NTL_FDOUBLE_PRECISION (...) /* the double value |
---|
79 | 2^{NTL_DOUBLE_PRECISION-1} */ |
---|
80 | |
---|
81 | #define NTL_ARITH_RIGHT_SHIFT (...) /* 1 if signed right-shift is |
---|
82 | arithmetic; 0 otherwise */ |
---|
83 | |
---|
84 | #define NTL_EXT_DOUBLE (...) /* 1 if platform has "extended" doubles; |
---|
85 | 0 otherwise */ |
---|
86 | |
---|