source: git/ntl/include/NTL/tools.h @ a703156

spielwiese
Last change on this file since a703156 was a703156, checked in by Hans Schönemann <hannes@…>, 17 years ago
*hannes: iostream strikes again on freebsd, gcc 3.4.5 git-svn-id: file:///usr/local/Singular/svn/trunk@9910 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 6.8 KB
Line 
1
2#ifndef NTL_tools__H
3#define NTL_tools__H
4
5#include <NTL/ctools.h>
6
7#if (defined(NTL_STD_CXX) || defined(NTL_PSTD_NHF))
8
9// new header files
10
11#include <cstdlib>
12#include <cmath>
13#ifndef NOSTREAMIO
14#include <iostream>
15#endif
16
17#else
18
19// old header files
20
21#include <stdlib.h>
22#include <math.h>
23#ifndef NOSTREAMIO
24#include <iostream.h>
25#endif
26
27#endif
28
29#if (defined(NTL_STD_CXX) || defined(NTL_PSTD_NHF))
30
31#define NTL_SNS std ::
32#define NTL_USE_SNS using namespace std;
33
34#elif (defined(NTL_PSTD_NNS))
35
36#define NTL_SNS ::
37#define NTL_USE_SNS
38
39#else
40
41#define NTL_SNS
42#define NTL_USE_SNS
43
44#endif
45
46#if (defined(NTL_STD_CXX) || defined(NTL_PSTD_NNS))
47
48#define NTL_NAMESPACE NTL
49#define NTL_OPEN_NNS namespace NTL_NAMESPACE {
50#define NTL_CLOSE_NNS  }
51#define NTL_USE_NNS using namespace NTL_NAMESPACE;
52#define NTL_NNS NTL_NAMESPACE ::
53
54// To make things work, we have to apply using declarations of all std
55// functions that are both overloaded by NTL and are used in
56// the implementation of NTL.
57
58#define NTL_START_IMPL NTL_USE_SNS NTL_OPEN_NNS \
59   using NTL_SNS abs; \
60   using NTL_SNS ceil; \
61   using NTL_SNS exp; \
62   using NTL_SNS fabs; \
63   using NTL_SNS floor; \
64   using NTL_SNS ldexp; \
65   using NTL_SNS log; \
66   using NTL_SNS sqrt;
67
68#define NTL_END_IMPL NTL_CLOSE_NNS
69
70#else
71
72#define NTL_NAMESPACE
73#define NTL_OPEN_NNS
74#define NTL_CLOSE_NNS
75#define NTL_USE_NNS
76#define NTL_NNS
77
78#define NTL_START_IMPL
79#define NTL_END_IMPL
80
81#endif
82
83#define NTL_CLIENT NTL_USE_SNS NTL_USE_NNS
84
85
86
87#if 0
88
89// This is for debugging purposes only.
90
91namespace foo_bar {
92
93class ostream;
94class istream;
95
96typedef unsigned int size_t;
97
98double floor(double);
99float floor(float);
100
101}
102#endif
103
104
105
106#if (!defined(NTL_CXX_ONLY))
107extern "C"
108#endif
109double _ntl_GetTime();
110
111typedef unsigned long _ntl_ulong;
112typedef _ntl_ulong *_ntl_ulong_ptr;
113// I made these have "obscure" names to avoid conflict with
114// (non-standard but common) definitions in standard headers.
115// Putting u_long inside namespace NTL only tends to creates ambiguities,
116// for no good reason.
117
118
119
120NTL_OPEN_NNS
121
122struct INIT_SIZE_STRUCT { };
123const INIT_SIZE_STRUCT INIT_SIZE = INIT_SIZE_STRUCT();
124typedef const INIT_SIZE_STRUCT& INIT_SIZE_TYPE;
125
126struct INIT_VAL_STRUCT { };
127const INIT_VAL_STRUCT INIT_VAL = INIT_VAL_STRUCT();
128typedef const INIT_VAL_STRUCT& INIT_VAL_TYPE;
129
130struct INIT_TRANS_STRUCT { };
131const INIT_TRANS_STRUCT INIT_TRANS = INIT_TRANS_STRUCT();
132typedef const INIT_TRANS_STRUCT& INIT_TRANS_TYPE;
133
134
135struct INIT_LOOP_HOLE_STRUCT { };
136const INIT_LOOP_HOLE_STRUCT INIT_LOOP_HOLE = INIT_LOOP_HOLE_STRUCT();
137typedef const INIT_LOOP_HOLE_STRUCT& INIT_LOOP_HOLE_TYPE;
138
139struct INIT_FFT_STRUCT { };
140const INIT_FFT_STRUCT INIT_FFT = INIT_FFT_STRUCT();
141typedef const INIT_FFT_STRUCT& INIT_FFT_TYPE;
142
143
144#ifdef NTL_NO_INIT_TRANS
145#define NTL_OPT_RETURN(t, x) return x
146#else
147#define NTL_OPT_RETURN(t, x) return t(x, INIT_TRANS)
148#endif
149
150
151#ifndef NTL_NO_MIN_MAX
152
153inline int min(int a, int b) { return (a < b) ?  a : b; } 
154inline int max(int a, int b) { return (a < b) ? b : a; }
155
156inline long min(long a, long b) { return (a < b) ?  a : b; } 
157inline long max(long a, long b) { return (a < b) ? b : a; }
158
159inline long min(int a, long b) { return (a < b) ?  long(a) : b; } 
160inline long max(int a, long b) { return (a < b) ? b : long(a); }
161
162inline long min(long a, int b) { return (a < b) ?  a : long(b); } 
163inline long max(long a, int b) { return (a < b) ? long(b) : a; }
164
165#endif
166
167
168inline void swap(long& a, long& b)  {  long t;  t = a; a = b; b = t; }
169inline void swap(int& a, int& b)  {  int t;  t = a; a = b; b = t; }
170
171
172
173inline void conv(int& x, int a) { x = a; }
174inline void conv(int& x, long a) 
175   { unsigned y = (unsigned) a;  x = NTL_UINT_TO_INT(y); }
176inline void conv(int& x, float a) { x = int(NTL_SNS floor(double(a))); }
177inline void conv(int& x, double a) { x = int(NTL_SNS floor(a)); }
178
179inline void conv(int& x, unsigned a) 
180   { x = NTL_UINT_TO_INT(a); }
181
182inline void conv(int& x, unsigned long a)
183   { unsigned y = (unsigned) a;  x = NTL_UINT_TO_INT(y); }
184
185inline int to_int(int a) { return a; }
186inline int to_int(long a) 
187   { unsigned y = (unsigned) a;  return NTL_UINT_TO_INT(y); }
188inline int to_int(float a) { return int(NTL_SNS floor(double(a))); }
189inline int to_int(double a) { return int(NTL_SNS floor(a)); }
190
191inline int to_int(unsigned a) 
192   { return NTL_UINT_TO_INT(a); }
193
194inline int to_int(unsigned long a) 
195   { unsigned y = (unsigned) a;  return NTL_UINT_TO_INT(y); }
196
197
198inline void conv(long& x, int a) { x = a; }
199inline void conv(long& x, long a) { x = a; }
200inline void conv(long& x, float a) { x = long(NTL_SNS floor(double(a))); }
201inline void conv(long& x, double a) { x = long(NTL_SNS floor(a)); }
202
203inline void conv(long& x, unsigned a)
204   { unsigned long y = a;  x = NTL_ULONG_TO_LONG(y); }
205
206inline void conv(long& x, unsigned long a)
207   { x = NTL_ULONG_TO_LONG(a); }
208
209inline long to_long(int a) { return a; }
210inline long to_long(long a) { return a; }
211inline long to_long(float a) { return long(NTL_SNS floor(double(a))); }
212inline long to_long(double a) { return long(NTL_SNS floor(a)); }
213
214inline long to_long(unsigned a)
215   { unsigned long y = a;  return NTL_ULONG_TO_LONG(y); }
216
217inline long to_long(unsigned long a)
218   { return NTL_ULONG_TO_LONG(a); }
219
220inline void conv(float& x, int a) { x = float(a); }
221inline void conv(float& x, long a) { x = float(a); }
222inline void conv(float& x, unsigned a) { x = float(a); }
223inline void conv(float& x, unsigned long a) { x = float(a); }
224inline void conv(float& x, float a) { x = a; }
225inline void conv(float& x, double a) { x = float(a); }
226
227inline float to_float(int a) { return float(a); }
228inline float to_float(long a) { return float(a); }
229inline float to_float(unsigned a) { return float(a); }
230inline float to_float(unsigned long a) { return float(a); }
231inline float to_float(float a) { return a; }
232inline float to_float(double a) { return float(a); }
233
234inline void conv(double& x, int a) { x = double(a); }
235inline void conv(double& x, long a) { x = double(a); }
236inline void conv(double& x, unsigned a) { x = double(a); }
237inline void conv(double& x, unsigned long a) { x = double(a); }
238inline void conv(double& x, float a) { x = double(a); }
239inline void conv(double& x, double a) { x = a; }
240
241inline double to_double(int a) { return double(a); }
242inline double to_double(long a) { return double(a); }
243inline double to_double(unsigned a) { return double(a); }
244inline double to_double(unsigned long a) { return double(a); }
245inline double to_double(float a) { return double(a); }
246inline double to_double(double a) { return a; }
247
248#ifndef NOSTREAMIO
249long SkipWhiteSpace(NTL_SNS istream& s);
250#endif
251long IsWhiteSpace(long c);
252
253long CharToIntVal(long c);
254char IntValToChar(long a);
255
256
257
258void Error(const char *s);
259
260
261inline double GetTime() { return _ntl_GetTime(); }
262
263inline long IsFinite(double *p) { return _ntl_IsFinite(p); }
264inline void ForceToMem(double *p) { _ntl_ForceToMem(p); }
265
266
267
268void PrintTime(double t);
269
270NTL_CLOSE_NNS
271
272
273#endif
274
Note: See TracBrowser for help on using the repository browser.