pspline 5.0.5 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +5 -5
- data/README.md +44 -43
- data/Rakefile +6 -6
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/ext/pspline/basis.cpp +394 -351
- data/ext/pspline/example/exbspline.rb +57 -57
- data/ext/pspline/example/excspline.rb +57 -57
- data/ext/pspline/example/exdspline.rb +55 -55
- data/ext/pspline/example/exfspline.rb +44 -44
- data/ext/pspline/example/exfspline1.rb +40 -40
- data/ext/pspline/example/exfspline2.rb +68 -68
- data/ext/pspline/example/exfspline3.rb +64 -64
- data/ext/pspline/example/exmspline.rb +68 -68
- data/ext/pspline/example/expspline.rb +29 -29
- data/ext/pspline/example/expspline1.rb +29 -29
- data/ext/pspline/example/expspline2.rb +47 -47
- data/ext/pspline/example/exqspline.rb +31 -31
- data/ext/pspline/example/exqspline1.rb +31 -31
- data/ext/pspline/example/exqspline2.rb +50 -50
- data/ext/pspline/example/exqspline3.rb +51 -51
- data/ext/pspline/example/exqspline4.rb +35 -35
- data/ext/pspline/example/exrspline.rb +34 -34
- data/ext/pspline/example/exrspline1.rb +34 -34
- data/ext/pspline/example/exrspline2.rb +44 -44
- data/ext/pspline/example/exsspline.rb +35 -35
- data/ext/pspline/example/exsspline1.rb +35 -35
- data/ext/pspline/example/extspline.rb +54 -54
- data/ext/pspline/extconf.rb +7 -7
- data/ext/pspline/fft.cpp +27 -552
- data/ext/pspline/include/basis/basis.h +145 -137
- data/ext/pspline/include/basis/fft.h +188 -152
- data/ext/pspline/include/basis/fft_complex.h +215 -0
- data/ext/pspline/include/basis/fft_real.h +625 -0
- data/ext/pspline/include/basis/gabs.h +35 -0
- data/ext/pspline/include/basis/marray_class_ext.h +568 -0
- data/ext/pspline/include/basis/marray_ext.h +100 -0
- data/ext/pspline/include/basis/matrix_luc_ext.h +300 -0
- data/ext/pspline/include/basis/matrix_lud_ext.h +298 -0
- data/ext/pspline/include/basis/poly.h +454 -0
- data/ext/pspline/include/basis/poly_array.h +1030 -1568
- data/ext/pspline/include/basis/pspline.h +806 -642
- data/ext/pspline/include/basis/real.h +526 -0
- data/ext/pspline/include/basis/real_inline.h +442 -0
- data/ext/pspline/include/basis/spline.h +83 -0
- data/ext/pspline/include/basis/uspline.h +251 -210
- data/ext/pspline/include/basis/util.h +122 -656
- data/ext/pspline/include/bspline.h +71 -377
- data/ext/pspline/include/bspline_Config.h +8 -2
- data/ext/pspline/include/real_config.h +3 -0
- data/ext/pspline/pspline.cpp +1236 -1038
- data/ext/pspline/real.cpp +1607 -0
- data/ext/pspline/real_const.cpp +585 -0
- data/lib/pspline.rb +71 -71
- data/lib/pspline/version.rb +1 -1
- data/pspline.gemspec +25 -25
- metadata +17 -5
- data/ext/pspline/plotsub.cpp +0 -139
- data/ext/pspline/util.cpp +0 -483
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
#ifndef _REAL_H_
|
|
2
|
+
#define _REAL_H_
|
|
3
|
+
|
|
4
|
+
#include <math.h>
|
|
5
|
+
#include "basis/gabs.h"
|
|
6
|
+
#include "basis/util.h"
|
|
7
|
+
#include "basis/marray_ext.h"
|
|
8
|
+
#include "basis/real_inline.h"
|
|
9
|
+
#include "basis/marray_class_ext.h"
|
|
10
|
+
|
|
11
|
+
namespace rios {
|
|
12
|
+
typedef unsigned int fmtflags;
|
|
13
|
+
extern unsigned int fixed;
|
|
14
|
+
extern unsigned int scientific;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
#define MAXN 1
|
|
18
|
+
#define LMTN 4
|
|
19
|
+
|
|
20
|
+
template <typename T> class real : public varray<T>
|
|
21
|
+
{
|
|
22
|
+
public:
|
|
23
|
+
// default construtor
|
|
24
|
+
real() : varray<T>(1) { this->w[0] = 0.0; }
|
|
25
|
+
// general constructor
|
|
26
|
+
explicit real(size_t n) : varray<T>(size_t(1), n)
|
|
27
|
+
{
|
|
28
|
+
for (size_t i = 0; i <= n; ++i) this->w[i] = 0.0;
|
|
29
|
+
}
|
|
30
|
+
real(size_t n, const T *a, int f = 1) : varray<T>(const_cast<T*>(a), 1, n, 1, f) {}
|
|
31
|
+
|
|
32
|
+
real(const T *a, size_t s, size_t n, int t = 1, int f = 1) : varray<T>(const_cast<T*>(a), s, n, t, f) {}
|
|
33
|
+
|
|
34
|
+
real(T a, size_t n = 0) : varray<T>(size_t(1), n)
|
|
35
|
+
{
|
|
36
|
+
this->w[0] = a; for (size_t i = 1; i <= this->N; ++i) this->w[i] = 0.0;
|
|
37
|
+
}
|
|
38
|
+
explicit real(const char *s, size_t n = MAXN) : varray<T>(size_t(1), n)
|
|
39
|
+
{
|
|
40
|
+
if (read(s, *this)) throw "(real::qd_real): INPUT ERROR.";
|
|
41
|
+
}
|
|
42
|
+
real(const varray<T>& v) : varray<T>((T*)v, v.size(), v.atom(), v.stride()) {}
|
|
43
|
+
// copy constructor
|
|
44
|
+
real(const real& p) : varray<T>(size_t(1), p.N)
|
|
45
|
+
{
|
|
46
|
+
for (size_t i = 0; i <= this->N; ++i) this->w[i] = p.w[i];
|
|
47
|
+
}
|
|
48
|
+
// destructor
|
|
49
|
+
~real() = default;
|
|
50
|
+
// assignment operator
|
|
51
|
+
real& operator = (const real&);
|
|
52
|
+
real& operator = (const varray<T>&);
|
|
53
|
+
real& operator = (const char*);
|
|
54
|
+
real& operator = (T);
|
|
55
|
+
// Renormalization
|
|
56
|
+
void normalize() { renorm(this->N, this->w); }
|
|
57
|
+
void normalize(T e) { renorm(this->N, this->w, e); }
|
|
58
|
+
|
|
59
|
+
/************ Additions *************/
|
|
60
|
+
/* real<T,N> = T + T */
|
|
61
|
+
static real add(T a, T b)
|
|
62
|
+
{
|
|
63
|
+
T s[2];
|
|
64
|
+
s[0] = two_sum(a, b, s[1]);
|
|
65
|
+
return real(size_t(1), s);
|
|
66
|
+
}
|
|
67
|
+
/* real<T,N> + T */
|
|
68
|
+
friend real operator + (const real& a, T b)
|
|
69
|
+
{
|
|
70
|
+
size_t N = a.N; double s[N+1];
|
|
71
|
+
qd_add(N, s, a.w, b);
|
|
72
|
+
return real(N, s);
|
|
73
|
+
}
|
|
74
|
+
/* T + real<T,N> */
|
|
75
|
+
friend real operator + (T a, const real& b)
|
|
76
|
+
{
|
|
77
|
+
return (b + a);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/* real<T,N> + real<T,M> */
|
|
81
|
+
friend real operator + <> (const real& a, const real& b);
|
|
82
|
+
|
|
83
|
+
/*********** Self-Additions ************/
|
|
84
|
+
/* real<T,N> += T */
|
|
85
|
+
real& operator += (T a)
|
|
86
|
+
{
|
|
87
|
+
qd_add(this->N, this->w, this->w, a);
|
|
88
|
+
return *this;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/* real<T,N> += real<T,M> */
|
|
92
|
+
real& operator += (const real& a)
|
|
93
|
+
{
|
|
94
|
+
size_t M = a.N;
|
|
95
|
+
if (this->N <= M) { qd_add(this->N, this->w, this->w, a.w); } else
|
|
96
|
+
{
|
|
97
|
+
T u[this->N+1];
|
|
98
|
+
for (size_t i = 0; i <= this->N; ++i) u[i] = (i <= M) ? a.w[i] : 0.0;
|
|
99
|
+
qd_add(this->N, this->w, this->w, u);
|
|
100
|
+
}
|
|
101
|
+
return *this;
|
|
102
|
+
}
|
|
103
|
+
/********** Unary Minus **********/
|
|
104
|
+
real operator - () const
|
|
105
|
+
{
|
|
106
|
+
T s[this->N+1];
|
|
107
|
+
qd_minus(this->N, s, this->w);
|
|
108
|
+
return real(this->N, s);
|
|
109
|
+
}
|
|
110
|
+
/********** Subtractions ***********/
|
|
111
|
+
/* real<T,N> = T - T */
|
|
112
|
+
static real sub(T a, T b)
|
|
113
|
+
{
|
|
114
|
+
T s[2];
|
|
115
|
+
s[0] = two_diff(a, b, s[1]);
|
|
116
|
+
return real(size_t(1), s);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
friend real operator - (const real& a, T b)
|
|
120
|
+
{
|
|
121
|
+
return (a + (-b));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
friend real operator - (T a, const real& b)
|
|
125
|
+
{
|
|
126
|
+
return (a + (-b));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
friend real operator - (const real& a, const real& b)
|
|
130
|
+
{
|
|
131
|
+
return (a + (-b));
|
|
132
|
+
}
|
|
133
|
+
/********** Self-Subtractions **********/
|
|
134
|
+
real& operator -= (T a)
|
|
135
|
+
{
|
|
136
|
+
qd_sub(this->N, this->w, this->w, a);
|
|
137
|
+
return *this;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
real& operator -= (const real<T>& a)
|
|
141
|
+
{
|
|
142
|
+
size_t M = a.N;
|
|
143
|
+
if (this->N <= M) { qd_sub(this->N, this->w, this->w, a.w); } else
|
|
144
|
+
{
|
|
145
|
+
T u[this->N+1];
|
|
146
|
+
for (size_t i = 0; i <= this->N; ++i) u[i] = (i <= M) ? a.w[i] : 0.0;
|
|
147
|
+
qd_sub(this->N, this->w, this->w, u);
|
|
148
|
+
}
|
|
149
|
+
return *this;
|
|
150
|
+
}
|
|
151
|
+
/********** Multiplications ***********/
|
|
152
|
+
friend real mul_pwr2(const real& a, T b)
|
|
153
|
+
{
|
|
154
|
+
const size_t N = a.N;
|
|
155
|
+
real s(N);
|
|
156
|
+
for (size_t i = 0; i <= N; ++i) s.w[i] = a.w[i] * b;
|
|
157
|
+
return s;
|
|
158
|
+
}
|
|
159
|
+
/* T-T * (2.0 ^ exp) */
|
|
160
|
+
friend real ldexp(const real& a, int n)
|
|
161
|
+
{
|
|
162
|
+
const size_t N = a.N;
|
|
163
|
+
real s(N);
|
|
164
|
+
for (size_t i = 0; i <= N; ++i) s.w[i] = _ldexp(a.w[i], n);
|
|
165
|
+
return s;
|
|
166
|
+
}
|
|
167
|
+
/* real<T,N> = T * T */
|
|
168
|
+
static real mul(T a, T b)
|
|
169
|
+
{
|
|
170
|
+
T p[2];
|
|
171
|
+
p[0] = two_prod(a, b, p[1]);
|
|
172
|
+
return real(size_t(1), p);
|
|
173
|
+
}
|
|
174
|
+
/* real<T,N> * T */
|
|
175
|
+
friend real operator * (const real& a, T b)
|
|
176
|
+
{
|
|
177
|
+
size_t N = a.N; double s[N+1];
|
|
178
|
+
qd_mul(N, s, a.w, b);
|
|
179
|
+
return real(N, s);
|
|
180
|
+
}
|
|
181
|
+
/* T * real<T,N> */
|
|
182
|
+
friend real operator * (T a, const real& b)
|
|
183
|
+
{
|
|
184
|
+
return (b * a);
|
|
185
|
+
}
|
|
186
|
+
/* real<T,N> * real<T,N> */
|
|
187
|
+
friend real operator * <> (const real& a, const real& b);
|
|
188
|
+
/********** Self-Multiplication **********/
|
|
189
|
+
/* real<T,N> *= T */
|
|
190
|
+
real& operator *= (T a)
|
|
191
|
+
{
|
|
192
|
+
qd_mul(this->N, this->w, this->w, a);
|
|
193
|
+
return *this;
|
|
194
|
+
}
|
|
195
|
+
/* real<T,N> *= real<T,N> */
|
|
196
|
+
real& operator *= (const real& a)
|
|
197
|
+
{
|
|
198
|
+
size_t M = a.N;
|
|
199
|
+
if (this->N <= M) { qd_mul(this->N, this->w, this->w, a.w); } else
|
|
200
|
+
{
|
|
201
|
+
T u[this->N+1];
|
|
202
|
+
for (size_t i = 0; i <= this->N; ++i) u[i] = (i <= M) ? a.w[i] : 0.0;
|
|
203
|
+
qd_mul(this->N, this->w, this->w, u);
|
|
204
|
+
}
|
|
205
|
+
return *this;
|
|
206
|
+
}
|
|
207
|
+
/********** Divisions ***********/
|
|
208
|
+
static real div(T a, T b)
|
|
209
|
+
{
|
|
210
|
+
T q1, q2, p1, p2, s[2];
|
|
211
|
+
|
|
212
|
+
q1 = a / b;
|
|
213
|
+
/* Compute a - q1 * b */
|
|
214
|
+
p1 = two_prod(q1, b, p2);
|
|
215
|
+
s[0] = two_diff(a, p1, s[1]);
|
|
216
|
+
s[1] -= p2;
|
|
217
|
+
/* get next approximation */
|
|
218
|
+
q2 = (s[0] + s[1]) / b;
|
|
219
|
+
s[0] = quick_two_sum(q1, q2, s[1]);
|
|
220
|
+
return real(size_t(1), s);
|
|
221
|
+
}
|
|
222
|
+
/* real<T,N> / T */
|
|
223
|
+
friend real operator / (const real& a, T b)
|
|
224
|
+
{
|
|
225
|
+
const size_t N = a.N; double q[N+1];
|
|
226
|
+
qd_div(N, q, a.w, b);
|
|
227
|
+
return real(N, q);
|
|
228
|
+
}
|
|
229
|
+
/* real<T,N> / real<T,M> */
|
|
230
|
+
friend real operator / <> (const real& a, const real& b);
|
|
231
|
+
/* T / real<T,N> */
|
|
232
|
+
friend real operator / (T a, const real& b)
|
|
233
|
+
{
|
|
234
|
+
real s(b.N); s.w[0] = a;
|
|
235
|
+
return s / b;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
friend real inv(const real& b)
|
|
239
|
+
{
|
|
240
|
+
real s(b.N); s.w[0] = 1.0;
|
|
241
|
+
return s / b;
|
|
242
|
+
}
|
|
243
|
+
/********** Self-Divisions **********/
|
|
244
|
+
/* real<T,N> /= T */
|
|
245
|
+
real& operator /= (T a)
|
|
246
|
+
{
|
|
247
|
+
qd_div(this->N, this->w, this->w, a);
|
|
248
|
+
return *this;
|
|
249
|
+
}
|
|
250
|
+
/* real<T,N> /= real<T,N> */
|
|
251
|
+
real& operator /= (const real& a)
|
|
252
|
+
{
|
|
253
|
+
size_t M = a.N;
|
|
254
|
+
if (this->N <= M) { qd_div(this->N, this->w, this->w, a.w); } else
|
|
255
|
+
{
|
|
256
|
+
T u[this->N+1];
|
|
257
|
+
for (size_t i = 0; i <= this->N; ++i) u[i] = (i <= M) ? a.w[i] : 0.0;
|
|
258
|
+
qd_div(this->N, this->w, this->w, u);
|
|
259
|
+
}
|
|
260
|
+
return *this;
|
|
261
|
+
}
|
|
262
|
+
/*********** Squaring **********/
|
|
263
|
+
friend real sqr <> (const real& a);
|
|
264
|
+
|
|
265
|
+
static real sqr(T a)
|
|
266
|
+
{
|
|
267
|
+
T p[2];
|
|
268
|
+
p[0] = two_sqr(a, p[1]);
|
|
269
|
+
return real(size_t(1), p);
|
|
270
|
+
}
|
|
271
|
+
/********** Exponentiation **********/
|
|
272
|
+
friend real pow(const real& a, int n)
|
|
273
|
+
{
|
|
274
|
+
return npwr(a, n);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
real operator ^ (int n) const
|
|
278
|
+
{
|
|
279
|
+
return pow(*this, n);
|
|
280
|
+
}
|
|
281
|
+
/********** Miscellaneous **********/
|
|
282
|
+
friend real abs(const real& a)
|
|
283
|
+
{
|
|
284
|
+
return (a.w[0] < 0.0) ? -a : a;
|
|
285
|
+
}
|
|
286
|
+
/********** Equality Comparison **********/
|
|
287
|
+
friend bool operator == (const real& a, T b)
|
|
288
|
+
{
|
|
289
|
+
return qd_eq(a.N, a.w, b);
|
|
290
|
+
}
|
|
291
|
+
friend bool operator == (T a, const real& b)
|
|
292
|
+
{
|
|
293
|
+
return (b == a);
|
|
294
|
+
}
|
|
295
|
+
friend bool operator == <> (const real& a, const real& b);
|
|
296
|
+
|
|
297
|
+
/********** Less-Than Comparison ***********/
|
|
298
|
+
friend bool operator < (const real& a, T b)
|
|
299
|
+
{
|
|
300
|
+
return qd_lt(a.N, a.w, b);
|
|
301
|
+
}
|
|
302
|
+
friend bool operator < (T a, const real& b)
|
|
303
|
+
{
|
|
304
|
+
return (b > a);
|
|
305
|
+
}
|
|
306
|
+
friend bool operator < <> (const real& a, const real& b);
|
|
307
|
+
|
|
308
|
+
/********** Greater-Than Comparison ***********/
|
|
309
|
+
friend bool operator > (const real& a, T b)
|
|
310
|
+
{
|
|
311
|
+
return qd_gt(a.N, a.w, b);
|
|
312
|
+
}
|
|
313
|
+
friend bool operator > (T a, const real& b)
|
|
314
|
+
{
|
|
315
|
+
return (b < a);
|
|
316
|
+
}
|
|
317
|
+
friend bool operator > <> (const real& a, const real& b);
|
|
318
|
+
|
|
319
|
+
/********** Less-Than-Or-Equal-To Comparison **********/
|
|
320
|
+
friend bool operator <= (const real& a, T b)
|
|
321
|
+
{
|
|
322
|
+
return qd_le(a.N, a.w, b);
|
|
323
|
+
}
|
|
324
|
+
friend bool operator <= (T a, const real& b)
|
|
325
|
+
{
|
|
326
|
+
return (b >= a);
|
|
327
|
+
}
|
|
328
|
+
friend bool operator <= <> (const real& a, const real& b);
|
|
329
|
+
|
|
330
|
+
/********** Greater-Than-Or-Equal-To Comparison **********/
|
|
331
|
+
friend bool operator >= (const real& a, T b)
|
|
332
|
+
{
|
|
333
|
+
return qd_ge(a.N, a.w, b);
|
|
334
|
+
}
|
|
335
|
+
friend bool operator >= (T a, const real& b)
|
|
336
|
+
{
|
|
337
|
+
return (b <= a);
|
|
338
|
+
}
|
|
339
|
+
friend bool operator >= <> (const real& a, const real& b);
|
|
340
|
+
|
|
341
|
+
/********** Not-Equal-To Comparison **********/
|
|
342
|
+
friend bool operator != (const real& a, T b)
|
|
343
|
+
{
|
|
344
|
+
return !(a == b);
|
|
345
|
+
}
|
|
346
|
+
friend bool operator != (T a, const real& b)
|
|
347
|
+
{
|
|
348
|
+
return !(a == b);
|
|
349
|
+
}
|
|
350
|
+
friend bool operator != (const real& a, const real& b)
|
|
351
|
+
{
|
|
352
|
+
return !(a == b);
|
|
353
|
+
}
|
|
354
|
+
/********** Multiplications **********/
|
|
355
|
+
friend real nint(const real& a)
|
|
356
|
+
{
|
|
357
|
+
const size_t N = a.N;
|
|
358
|
+
real x(N);
|
|
359
|
+
x.w[0] = _nint(a.w[0]);
|
|
360
|
+
for (size_t i = 0; i < N; ++i) {
|
|
361
|
+
if (x.w[i] != a.w[i]) {
|
|
362
|
+
if (fabs(x.w[i] - a.w[i]) == 0.5 && a.w[i+1] < 0.0)
|
|
363
|
+
x.w[i] -= 1.0;
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
x.w[i+1] = _nint(a.w[i+1]);
|
|
367
|
+
}
|
|
368
|
+
renorm(N, x.w);
|
|
369
|
+
return x;
|
|
370
|
+
}
|
|
371
|
+
friend real floor(const real& a)
|
|
372
|
+
{
|
|
373
|
+
const size_t N = a.N;
|
|
374
|
+
real x(N);
|
|
375
|
+
for (size_t i = 0; i <= N; ++i) {
|
|
376
|
+
x.w[i] = _floor(a.w[i]);
|
|
377
|
+
if (x.w[i] != a.w[i]) break;
|
|
378
|
+
}
|
|
379
|
+
renorm(N, x.w);
|
|
380
|
+
return x;
|
|
381
|
+
}
|
|
382
|
+
friend real ceil(const real& a)
|
|
383
|
+
{
|
|
384
|
+
const size_t N = a.N;
|
|
385
|
+
real x(N);
|
|
386
|
+
for (size_t i = 0; i <= N; ++i) {
|
|
387
|
+
x.w[i] = _ceil(a.w[i]);
|
|
388
|
+
if (x.w[i] != a.w[i]) break;
|
|
389
|
+
}
|
|
390
|
+
renorm(N, x.w);
|
|
391
|
+
return x;
|
|
392
|
+
}
|
|
393
|
+
friend real max(const real& a, const real& b) { return (a > b) ? a : b; }
|
|
394
|
+
friend real max(const real& a, const real& b, const real& c)
|
|
395
|
+
{
|
|
396
|
+
return (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);
|
|
397
|
+
}
|
|
398
|
+
friend real min(const real& a, const real& b) { return (a < b) ? a : b; }
|
|
399
|
+
friend real min(const real& a, const real& b, const real& c)
|
|
400
|
+
{
|
|
401
|
+
return (a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c);
|
|
402
|
+
}
|
|
403
|
+
friend int sgn(const real& a) { return (a > 0.0) ? 1 : (a < 0.0) ? -1 : 0; }
|
|
404
|
+
|
|
405
|
+
bool is_zero() const { return (this->w[0] == 0.0); }
|
|
406
|
+
bool is_one() const
|
|
407
|
+
{
|
|
408
|
+
size_t i; bool f = (this->w[0] == 1.0);
|
|
409
|
+
if (f) for (i = 0; i <= this->N; ++i) if (this->w[i] == 0.0) break;
|
|
410
|
+
return (f && i > this->N);
|
|
411
|
+
}
|
|
412
|
+
bool is_positive() const { return (this->w[0] > 0.0); }
|
|
413
|
+
bool is_negative() const { return (this->w[0] < 0.0); }
|
|
414
|
+
bool is_inf() const
|
|
415
|
+
{
|
|
416
|
+
size_t i = 0;
|
|
417
|
+
if (this->w) for (; i <= this->N; ++i) if (isinf(this->w[i])) break;
|
|
418
|
+
return (!(this->w == NULL) && i <= this->N);
|
|
419
|
+
}
|
|
420
|
+
bool is_nan() const
|
|
421
|
+
{
|
|
422
|
+
size_t i = 0;
|
|
423
|
+
if (this->w) for (; i <= this->N; ++i) if (isnan(this->w[i])) break;
|
|
424
|
+
return (i <= this->N);
|
|
425
|
+
}
|
|
426
|
+
#ifdef USE_RANDOM
|
|
427
|
+
/* Random number generator */
|
|
428
|
+
static real rand(size_t N) { return qdrand(N); }
|
|
429
|
+
static real qdrand(size_t);
|
|
430
|
+
static real debug_rand(size_t);
|
|
431
|
+
static real uniform_rand(size_t, T, T);
|
|
432
|
+
static real normal_rand(size_t, T, T);
|
|
433
|
+
#endif
|
|
434
|
+
operator T* () const {return this->w;}
|
|
435
|
+
varray<T>* operator & () { return (varray<T>*)this; }
|
|
436
|
+
real operator[](int n) const { const varray<T>& v = *this; assert(this->_size > size_t(n)); return v[n]; }
|
|
437
|
+
T operator()(int n) const {return (this->w == NULL) ? 0.0 : this->w[n];}
|
|
438
|
+
T& operator()(int i) {assert(this->w != NULL); return this->w[i];}
|
|
439
|
+
|
|
440
|
+
size_t atom() const {return this->N;}
|
|
441
|
+
T to_d() const {return this->w[0];}
|
|
442
|
+
int to_i() const {return static_cast<int>(this->w[0]);}
|
|
443
|
+
char *to_a(const char *f = "%g") const;
|
|
444
|
+
char *to_s(const char *f = "%g", char fill = ' ') const;
|
|
445
|
+
void fprint(FILE *f, const char *fmt = "%g\n") const { gprint(*this, f, fmt); }
|
|
446
|
+
void print(const char *fmt = "%g\n") const { this->fprint(stdout, fmt); }
|
|
447
|
+
int read(const char *s, real& qd);
|
|
448
|
+
int write(char *s, int len, int precision,
|
|
449
|
+
rios::fmtflags fmt, bool showpos = false, bool uppercase = false, char fill = '0') const;
|
|
450
|
+
char *to_string(int precision, int width,
|
|
451
|
+
rios::fmtflags fmt, bool showpos = false, bool uppercase = false, char fill = '0') const;
|
|
452
|
+
|
|
453
|
+
}; // end of real<T>;
|
|
454
|
+
|
|
455
|
+
using Real = real<double>;
|
|
456
|
+
|
|
457
|
+
typedef enum { md, dd, hd, qd, pd, de, he, qe, pe } real_precision;
|
|
458
|
+
|
|
459
|
+
template <typename T> class real_const
|
|
460
|
+
{
|
|
461
|
+
const T *data;
|
|
462
|
+
public:
|
|
463
|
+
real_const(const T* d) : data(d) {}
|
|
464
|
+
const real<T> operator[](size_t n) const { return real<T>(n, data); }
|
|
465
|
+
const real<T> operator[](real_precision n) const { return real<T>(static_cast<size_t>(n), data); }
|
|
466
|
+
T operator()(size_t n) const { return data[n]; }
|
|
467
|
+
T operator()(real_precision n) const { return data[static_cast<size_t>(n)]; }
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
/* Some useful constants. */
|
|
471
|
+
extern real_const<double> _2pi ;
|
|
472
|
+
extern real_const<double> _pi ;
|
|
473
|
+
extern real_const<double> _pi2 ;
|
|
474
|
+
extern real_const<double> _pi4 ;
|
|
475
|
+
extern real_const<double> _3pi4 ;
|
|
476
|
+
extern real_const<double> _e ;
|
|
477
|
+
extern real_const<double> _log2 ;
|
|
478
|
+
extern real_const<double> _log10 ;
|
|
479
|
+
extern real_const<double> _nan ;
|
|
480
|
+
extern real_const<double> _inf ;
|
|
481
|
+
extern real_const<double> _eps ; // = 2^-209
|
|
482
|
+
extern real_const<double> _min_normalized; // = 2^(-1022 + 3*53)
|
|
483
|
+
extern real_const<double> _max ;
|
|
484
|
+
extern real_const<double> _safe_max ;
|
|
485
|
+
extern real_const<int> _ndigits ;
|
|
486
|
+
extern real_const<double> _pi1024 ;
|
|
487
|
+
extern const double real_const_table[15][5];
|
|
488
|
+
extern const int real_const_ndigits[5];
|
|
489
|
+
#define n_inv_fact 15
|
|
490
|
+
extern const double real_inv_data[n_inv_fact][5];
|
|
491
|
+
extern const double real_sin_data[256][5]; /* Table of sin(k * pi/1024)*/
|
|
492
|
+
extern const double real_cos_data[256][5]; /* Table of cos(k * pi/1024). */
|
|
493
|
+
|
|
494
|
+
template <> inline Real gabs(Real p) { return abs(p); }
|
|
495
|
+
|
|
496
|
+
Real sqrt(const Real&);
|
|
497
|
+
Real nroot(const Real&, int);
|
|
498
|
+
Real exp(const Real&);
|
|
499
|
+
Real log(const Real&);
|
|
500
|
+
Real log10(const Real&);
|
|
501
|
+
Real sin(const Real&);
|
|
502
|
+
Real cos(const Real&);
|
|
503
|
+
void sincos(const Real&, Real&, Real&);
|
|
504
|
+
Real atan(const Real&);
|
|
505
|
+
Real atan2(const Real&, const Real&);
|
|
506
|
+
Real drem(const Real&, const Real&);
|
|
507
|
+
Real divrem(const Real&, const Real&, Real&);
|
|
508
|
+
Real tan(const Real&);
|
|
509
|
+
Real asin(const Real&);
|
|
510
|
+
Real acos(const Real&);
|
|
511
|
+
Real sinh(const Real&);
|
|
512
|
+
Real cosh(const Real&);
|
|
513
|
+
Real tanh(const Real&);
|
|
514
|
+
void sincosh(const Real&, Real&, Real&);
|
|
515
|
+
Real asinh(const Real&);
|
|
516
|
+
Real acosh(const Real&);
|
|
517
|
+
Real atanh(const Real&);
|
|
518
|
+
Real fmod(const Real&, const Real&);
|
|
519
|
+
Real polyeval(const Real*, int, const Real &);
|
|
520
|
+
Real polyroot(const Real*, int, const Real &, int = 64, double = 0.0);
|
|
521
|
+
|
|
522
|
+
void debug_sin_table(real_precision);
|
|
523
|
+
void debug_cos_table(real_precision);
|
|
524
|
+
void debug_inv_fact(real_precision);
|
|
525
|
+
|
|
526
|
+
#endif
|