1 | |
---|
2 | #ifndef NTL_tools__H |
---|
3 | #define NTL_tools__H |
---|
4 | |
---|
5 | #include <NTL/config.h> |
---|
6 | #include <NTL/mach_desc.h> |
---|
7 | |
---|
8 | #if (defined(NTL_STD_CXX) || defined(NTL_PSTD_NHF)) |
---|
9 | |
---|
10 | // new header files |
---|
11 | |
---|
12 | #include <cstdlib> |
---|
13 | #include <cmath> |
---|
14 | #include <iostream> |
---|
15 | |
---|
16 | #else |
---|
17 | |
---|
18 | // old header files |
---|
19 | |
---|
20 | #include <stdlib.h> |
---|
21 | #include <math.h> |
---|
22 | #include <iostream.h> |
---|
23 | |
---|
24 | #endif |
---|
25 | |
---|
26 | #if (defined(NTL_STD_CXX) || defined(NTL_PSTD_NHF)) |
---|
27 | |
---|
28 | #define NTL_SNS std :: |
---|
29 | #define NTL_USE_SNS using namespace std; |
---|
30 | |
---|
31 | #elif (defined(NTL_PSTD_NNS)) |
---|
32 | |
---|
33 | #define NTL_SNS :: |
---|
34 | #define NTL_USE_SNS |
---|
35 | |
---|
36 | #else |
---|
37 | |
---|
38 | #define NTL_SNS |
---|
39 | #define NTL_USE_SNS |
---|
40 | |
---|
41 | #endif |
---|
42 | |
---|
43 | #if (defined(NTL_STD_CXX) || defined(NTL_PSTD_NNS)) |
---|
44 | |
---|
45 | #define NTL_NAMESPACE NTL |
---|
46 | #define NTL_OPEN_NNS namespace NTL_NAMESPACE { |
---|
47 | #define NTL_CLOSE_NNS } |
---|
48 | #define NTL_USE_NNS using namespace NTL_NAMESPACE; |
---|
49 | #define NTL_NNS NTL_NAMESPACE :: |
---|
50 | |
---|
51 | // To make things work, we have to apply using declarations of all std |
---|
52 | // functions that are both overloaded by NTL and are used in |
---|
53 | // the implementation of NTL. |
---|
54 | |
---|
55 | #define NTL_START_IMPL NTL_USE_SNS NTL_OPEN_NNS \ |
---|
56 | using NTL_SNS abs; \ |
---|
57 | using NTL_SNS ceil; \ |
---|
58 | using NTL_SNS exp; \ |
---|
59 | using NTL_SNS fabs; \ |
---|
60 | using NTL_SNS floor; \ |
---|
61 | using NTL_SNS ldexp; \ |
---|
62 | using NTL_SNS log; \ |
---|
63 | using NTL_SNS sqrt; |
---|
64 | |
---|
65 | #define NTL_END_IMPL NTL_CLOSE_NNS |
---|
66 | |
---|
67 | #else |
---|
68 | |
---|
69 | #define NTL_NAMESPACE |
---|
70 | #define NTL_OPEN_NNS |
---|
71 | #define NTL_CLOSE_NNS |
---|
72 | #define NTL_USE_NNS |
---|
73 | #define NTL_NNS |
---|
74 | |
---|
75 | #define NTL_START_IMPL |
---|
76 | #define NTL_END_IMPL |
---|
77 | |
---|
78 | #endif |
---|
79 | |
---|
80 | #define NTL_CLIENT NTL_USE_SNS NTL_USE_NNS |
---|
81 | |
---|
82 | |
---|
83 | |
---|
84 | #if 0 |
---|
85 | namespace foo_bar { |
---|
86 | |
---|
87 | class ostream; |
---|
88 | class istream; |
---|
89 | |
---|
90 | typedef unsigned int size_t; |
---|
91 | |
---|
92 | double floor(double); |
---|
93 | float floor(float); |
---|
94 | |
---|
95 | } |
---|
96 | #endif |
---|
97 | |
---|
98 | |
---|
99 | #include <NTL/IsFinite.h> |
---|
100 | |
---|
101 | #if (!defined(NTL_CXX_ONLY)) |
---|
102 | extern "C" |
---|
103 | #endif |
---|
104 | double _ntl_GetTime(); |
---|
105 | |
---|
106 | typedef unsigned long _ntl_ulong; |
---|
107 | typedef _ntl_ulong *_ntl_ulong_ptr; |
---|
108 | // I made these have "obscure" names to avoid conflict with |
---|
109 | // (non-standard but common) definitions in standard headers. |
---|
110 | // Putting u_long inside namespace NTL only tends to creates ambiguities, |
---|
111 | // for no good reason. |
---|
112 | |
---|
113 | |
---|
114 | |
---|
115 | NTL_OPEN_NNS |
---|
116 | |
---|
117 | struct INIT_SIZE_STRUCT { }; |
---|
118 | const INIT_SIZE_STRUCT INIT_SIZE = INIT_SIZE_STRUCT(); |
---|
119 | typedef const INIT_SIZE_STRUCT& INIT_SIZE_TYPE; |
---|
120 | |
---|
121 | struct INIT_VAL_STRUCT { }; |
---|
122 | const INIT_VAL_STRUCT INIT_VAL = INIT_VAL_STRUCT(); |
---|
123 | typedef const INIT_VAL_STRUCT& INIT_VAL_TYPE; |
---|
124 | |
---|
125 | struct INIT_TRANS_STRUCT { }; |
---|
126 | const INIT_TRANS_STRUCT INIT_TRANS = INIT_TRANS_STRUCT(); |
---|
127 | typedef const INIT_TRANS_STRUCT& INIT_TRANS_TYPE; |
---|
128 | |
---|
129 | |
---|
130 | struct INIT_LOOP_HOLE_STRUCT { }; |
---|
131 | const INIT_LOOP_HOLE_STRUCT INIT_LOOP_HOLE = INIT_LOOP_HOLE_STRUCT(); |
---|
132 | typedef const INIT_LOOP_HOLE_STRUCT& INIT_LOOP_HOLE_TYPE; |
---|
133 | |
---|
134 | struct INIT_FFT_STRUCT { }; |
---|
135 | const INIT_FFT_STRUCT INIT_FFT = INIT_FFT_STRUCT(); |
---|
136 | typedef const INIT_FFT_STRUCT& INIT_FFT_TYPE; |
---|
137 | |
---|
138 | |
---|
139 | #ifdef NTL_NO_INIT_TRANS |
---|
140 | #define NTL_OPT_RETURN(t, x) return x |
---|
141 | #else |
---|
142 | #define NTL_OPT_RETURN(t, x) return t(x, INIT_TRANS) |
---|
143 | #endif |
---|
144 | |
---|
145 | |
---|
146 | #ifndef NTL_NO_MIN_MAX |
---|
147 | |
---|
148 | inline int min(int a, int b) { return (a < b) ? a : b; } |
---|
149 | inline int max(int a, int b) { return (a < b) ? b : a; } |
---|
150 | |
---|
151 | inline long min(long a, long b) { return (a < b) ? a : b; } |
---|
152 | inline long max(long a, long b) { return (a < b) ? b : a; } |
---|
153 | |
---|
154 | inline long min(int a, long b) { return (a < b) ? long(a) : b; } |
---|
155 | inline long max(int a, long b) { return (a < b) ? b : long(a); } |
---|
156 | |
---|
157 | inline long min(long a, int b) { return (a < b) ? a : long(b); } |
---|
158 | inline long max(long a, int b) { return (a < b) ? long(b) : a; } |
---|
159 | |
---|
160 | #endif |
---|
161 | |
---|
162 | |
---|
163 | inline void swap(long& a, long& b) { long t; t = a; a = b; b = t; } |
---|
164 | inline void swap(int& a, int& b) { int t; t = a; a = b; b = t; } |
---|
165 | |
---|
166 | inline void conv(int& x, int a) { x = a; } |
---|
167 | inline void conv(int& x, long a) { x = int(a); } |
---|
168 | inline void conv(int& x, float a) { x = int(NTL_SNS floor(double(a))); } |
---|
169 | inline void conv(int& x, double a) { x = int(NTL_SNS floor(a)); } |
---|
170 | |
---|
171 | inline int to_int(int a) { return a; } |
---|
172 | inline int to_int(long a) { return int(a); } |
---|
173 | inline int to_int(float a) { return int(NTL_SNS floor(double(a))); } |
---|
174 | inline int to_int(double a) { return int(NTL_SNS floor(a)); } |
---|
175 | |
---|
176 | |
---|
177 | inline void conv(long& x, int a) { x = a; } |
---|
178 | inline void conv(long& x, long a) { x = a; } |
---|
179 | inline void conv(long& x, float a) { x = long(NTL_SNS floor(double(a))); } |
---|
180 | inline void conv(long& x, double a) { x = long(NTL_SNS floor(a)); } |
---|
181 | |
---|
182 | inline long to_long(int a) { return a; } |
---|
183 | inline long to_long(long a) { return a; } |
---|
184 | inline long to_long(float a) { return long(NTL_SNS floor(double(a))); } |
---|
185 | inline long to_long(double a) { return long(NTL_SNS floor(a)); } |
---|
186 | |
---|
187 | inline void conv(float& x, int a) { x = float(a); } |
---|
188 | inline void conv(float& x, long a) { x = float(a); } |
---|
189 | inline void conv(float& x, float a) { x = a; } |
---|
190 | inline void conv(float& x, double a) { x = float(a); } |
---|
191 | |
---|
192 | inline float to_float(int a) { return float(a); } |
---|
193 | inline float to_float(long a) { return float(a); } |
---|
194 | inline float to_float(float a) { return a; } |
---|
195 | inline float to_float(double a) { return float(a); } |
---|
196 | |
---|
197 | inline void conv(double& x, int a) { x = double(a); } |
---|
198 | inline void conv(double& x, long a) { x = double(a); } |
---|
199 | inline void conv(double& x, float a) { x = double(a); } |
---|
200 | inline void conv(double& x, double a) { x = a; } |
---|
201 | |
---|
202 | inline double to_double(int a) { return double(a); } |
---|
203 | inline double to_double(long a) { return double(a); } |
---|
204 | inline double to_double(float a) { return double(a); } |
---|
205 | inline double to_double(double a) { return a; } |
---|
206 | |
---|
207 | |
---|
208 | long SkipWhiteSpace(NTL_SNS istream& s); |
---|
209 | |
---|
210 | |
---|
211 | |
---|
212 | void Error(const char *s); |
---|
213 | |
---|
214 | |
---|
215 | inline double GetTime() { return _ntl_GetTime(); } |
---|
216 | |
---|
217 | inline long IsFinite(double *p) { return _ntl_IsFinite(p); } |
---|
218 | inline void ForceToMem(double *p) { _ntl_ForceToMem(p); } |
---|
219 | |
---|
220 | |
---|
221 | |
---|
222 | void PrintTime(NTL_SNS ostream& s, double t); |
---|
223 | |
---|
224 | NTL_CLOSE_NNS |
---|
225 | |
---|
226 | |
---|
227 | #endif |
---|
228 | |
---|