source: git/ntl/include/NTL/tools.h @ 92c0ac

spielwiese
Last change on this file since 92c0ac was 92c0ac, checked in by Hans Schönemann <hannes@…>, 21 years ago
NTL-5.2 git-svn-id: file:///usr/local/Singular/svn/trunk@6320 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 5.4 KB
Line 
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
85namespace foo_bar {
86
87class ostream;
88class istream;
89
90typedef unsigned int size_t;
91
92double floor(double);
93float floor(float);
94
95}
96#endif
97
98
99#include <NTL/IsFinite.h>
100
101#if (!defined(NTL_CXX_ONLY))
102extern "C"
103#endif
104double _ntl_GetTime();
105
106typedef unsigned long _ntl_ulong;
107typedef _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
115NTL_OPEN_NNS
116
117struct INIT_SIZE_STRUCT { };
118const INIT_SIZE_STRUCT INIT_SIZE = INIT_SIZE_STRUCT();
119typedef const INIT_SIZE_STRUCT& INIT_SIZE_TYPE;
120
121struct INIT_VAL_STRUCT { };
122const INIT_VAL_STRUCT INIT_VAL = INIT_VAL_STRUCT();
123typedef const INIT_VAL_STRUCT& INIT_VAL_TYPE;
124
125struct INIT_TRANS_STRUCT { };
126const INIT_TRANS_STRUCT INIT_TRANS = INIT_TRANS_STRUCT();
127typedef const INIT_TRANS_STRUCT& INIT_TRANS_TYPE;
128
129
130struct INIT_LOOP_HOLE_STRUCT { };
131const INIT_LOOP_HOLE_STRUCT INIT_LOOP_HOLE = INIT_LOOP_HOLE_STRUCT();
132typedef const INIT_LOOP_HOLE_STRUCT& INIT_LOOP_HOLE_TYPE;
133
134struct INIT_FFT_STRUCT { };
135const INIT_FFT_STRUCT INIT_FFT = INIT_FFT_STRUCT();
136typedef 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
148inline int min(int a, int b) { return (a < b) ?  a : b; } 
149inline int max(int a, int b) { return (a < b) ? b : a; }
150
151inline long min(long a, long b) { return (a < b) ?  a : b; } 
152inline long max(long a, long b) { return (a < b) ? b : a; }
153
154inline long min(int a, long b) { return (a < b) ?  long(a) : b; } 
155inline long max(int a, long b) { return (a < b) ? b : long(a); }
156
157inline long min(long a, int b) { return (a < b) ?  a : long(b); } 
158inline long max(long a, int b) { return (a < b) ? long(b) : a; }
159
160#endif
161
162
163inline void swap(long& a, long& b)  {  long t;  t = a; a = b; b = t; }
164inline void swap(int& a, int& b)  {  int t;  t = a; a = b; b = t; }
165
166inline void conv(int& x, int a) { x = a; }
167inline void conv(int& x, long a) { x = int(a); }
168inline void conv(int& x, float a) { x = int(NTL_SNS floor(double(a))); }
169inline void conv(int& x, double a) { x = int(NTL_SNS floor(a)); }
170
171inline int to_int(int a) { return a; }
172inline int to_int(long a) { return int(a); }
173inline int to_int(float a) { return int(NTL_SNS floor(double(a))); }
174inline int to_int(double a) { return int(NTL_SNS floor(a)); }
175
176
177inline void conv(long& x, int a) { x = a; }
178inline void conv(long& x, long a) { x = a; }
179inline void conv(long& x, float a) { x = long(NTL_SNS floor(double(a))); }
180inline void conv(long& x, double a) { x = long(NTL_SNS floor(a)); }
181
182inline long to_long(int a) { return a; }
183inline long to_long(long a) { return a; }
184inline long to_long(float a) { return long(NTL_SNS floor(double(a))); }
185inline long to_long(double a) { return long(NTL_SNS floor(a)); }
186
187inline void conv(float& x, int a) { x = float(a); }
188inline void conv(float& x, long a) { x = float(a); }
189inline void conv(float& x, float a) { x = a; }
190inline void conv(float& x, double a) { x = float(a); }
191
192inline float to_float(int a) { return float(a); }
193inline float to_float(long a) { return float(a); }
194inline float to_float(float a) { return a; }
195inline float to_float(double a) { return float(a); }
196
197inline void conv(double& x, int a) { x = double(a); }
198inline void conv(double& x, long a) { x = double(a); }
199inline void conv(double& x, float a) { x = double(a); }
200inline void conv(double& x, double a) { x = a; }
201
202inline double to_double(int a) { return double(a); }
203inline double to_double(long a) { return double(a); }
204inline double to_double(float a) { return double(a); }
205inline double to_double(double a) { return a; }
206
207
208long SkipWhiteSpace(NTL_SNS istream& s);
209
210
211
212void Error(const char *s);
213
214
215inline double GetTime() { return _ntl_GetTime(); }
216
217inline long IsFinite(double *p) { return _ntl_IsFinite(p); }
218inline void ForceToMem(double *p) { _ntl_ForceToMem(p); }
219
220
221
222void PrintTime(NTL_SNS ostream& s, double t);
223
224NTL_CLOSE_NNS
225
226
227#endif
228
Note: See TracBrowser for help on using the repository browser.