| 1 |
/* |
| 2 |
* include/qd_inline.h |
| 3 |
* |
| 4 |
* This work was supported by the Director, Office of Science, Division |
| 5 |
* of Mathematical, Information, and Computational Sciences of the |
| 6 |
* U.S. Department of Energy under contract number DE-AC03-76SF00098. |
| 7 |
* |
| 8 |
* Copyright (c) 2000-2001 |
| 9 |
* |
| 10 |
* Contains small functions (suitable for inlining) in the quad-double |
| 11 |
* arithmetic package. |
| 12 |
*/ |
| 13 |
#ifndef _QD_QD_INLINE_H |
| 14 |
#define _QD_QD_INLINE_H |
| 15 |
|
| 16 |
#include <cmath> |
| 17 |
#include <qd/inline.h> |
| 18 |
|
| 19 |
#ifndef QD_INLINE |
| 20 |
#define inline |
| 21 |
#endif |
| 22 |
|
| 23 |
/********** Constructors **********/ |
| 24 |
inline qd_real::qd_real(double x0, double x1, double x2, double x3) { |
| 25 |
x[0] = x0; |
| 26 |
x[1] = x1; |
| 27 |
x[2] = x2; |
| 28 |
x[3] = x3; |
| 29 |
} |
| 30 |
|
| 31 |
inline qd_real::qd_real(const double *xx) { |
| 32 |
x[0] = xx[0]; |
| 33 |
x[1] = xx[1]; |
| 34 |
x[2] = xx[2]; |
| 35 |
x[3] = xx[3]; |
| 36 |
} |
| 37 |
|
| 38 |
inline qd_real::qd_real(double x0) { |
| 39 |
x[0] = x0; |
| 40 |
x[1] = x[2] = x[3] = 0.0; |
| 41 |
} |
| 42 |
|
| 43 |
inline qd_real::qd_real() { |
| 44 |
x[0] = 0.0; |
| 45 |
x[1] = 0.0; |
| 46 |
x[2] = 0.0; |
| 47 |
x[3] = 0.0; |
| 48 |
} |
| 49 |
|
| 50 |
inline qd_real::qd_real(const dd_real &a) { |
| 51 |
x[0] = a._hi(); |
| 52 |
x[1] = a._lo(); |
| 53 |
x[2] = x[3] = 0.0; |
| 54 |
} |
| 55 |
|
| 56 |
inline qd_real::qd_real(int i) { |
| 57 |
x[0] = static_cast<double>(i); |
| 58 |
x[1] = x[2] = x[3] = 0.0; |
| 59 |
} |
| 60 |
|
| 61 |
/********** Accessors **********/ |
| 62 |
inline double qd_real::operator[](int i) const { |
| 63 |
return x[i]; |
| 64 |
} |
| 65 |
|
| 66 |
inline double &qd_real::operator[](int i) { |
| 67 |
return x[i]; |
| 68 |
} |
| 69 |
|
| 70 |
inline bool qd_real::isnan() const { |
| 71 |
return QD_ISNAN(x[0]) || QD_ISNAN(x[1]) || QD_ISNAN(x[2]) || QD_ISNAN(x[3]); |
| 72 |
} |
| 73 |
|
| 74 |
/********** Renormalization **********/ |
| 75 |
namespace qd { |
| 76 |
inline void quick_renorm(double &c0, double &c1, |
| 77 |
double &c2, double &c3, double &c4) { |
| 78 |
double t0, t1, t2, t3; |
| 79 |
double s; |
| 80 |
s = qd::quick_two_sum(c3, c4, t3); |
| 81 |
s = qd::quick_two_sum(c2, s , t2); |
| 82 |
s = qd::quick_two_sum(c1, s , t1); |
| 83 |
c0 = qd::quick_two_sum(c0, s , t0); |
| 84 |
|
| 85 |
s = qd::quick_two_sum(t2, t3, t2); |
| 86 |
s = qd::quick_two_sum(t1, s , t1); |
| 87 |
c1 = qd::quick_two_sum(t0, s , t0); |
| 88 |
|
| 89 |
s = qd::quick_two_sum(t1, t2, t1); |
| 90 |
c2 = qd::quick_two_sum(t0, s , t0); |
| 91 |
|
| 92 |
c3 = t0 + t1; |
| 93 |
} |
| 94 |
|
| 95 |
inline void renorm(double &c0, double &c1, |
| 96 |
double &c2, double &c3) { |
| 97 |
double s0, s1, s2 = 0.0, s3 = 0.0; |
| 98 |
|
| 99 |
if (QD_ISINF(c0)) return; |
| 100 |
|
| 101 |
s0 = qd::quick_two_sum(c2, c3, c3); |
| 102 |
s0 = qd::quick_two_sum(c1, s0, c2); |
| 103 |
c0 = qd::quick_two_sum(c0, s0, c1); |
| 104 |
|
| 105 |
s0 = c0; |
| 106 |
s1 = c1; |
| 107 |
if (s1 != 0.0) { |
| 108 |
s1 = qd::quick_two_sum(s1, c2, s2); |
| 109 |
if (s2 != 0.0) |
| 110 |
s2 = qd::quick_two_sum(s2, c3, s3); |
| 111 |
else |
| 112 |
s1 = qd::quick_two_sum(s1, c3, s2); |
| 113 |
} else { |
| 114 |
s0 = qd::quick_two_sum(s0, c2, s1); |
| 115 |
if (s1 != 0.0) |
| 116 |
s1 = qd::quick_two_sum(s1, c3, s2); |
| 117 |
else |
| 118 |
s0 = qd::quick_two_sum(s0, c3, s1); |
| 119 |
} |
| 120 |
|
| 121 |
c0 = s0; |
| 122 |
c1 = s1; |
| 123 |
c2 = s2; |
| 124 |
c3 = s3; |
| 125 |
} |
| 126 |
|
| 127 |
inline void renorm(double &c0, double &c1, |
| 128 |
double &c2, double &c3, double &c4) { |
| 129 |
double s0, s1, s2 = 0.0, s3 = 0.0; |
| 130 |
|
| 131 |
if (QD_ISINF(c0)) return; |
| 132 |
|
| 133 |
s0 = qd::quick_two_sum(c3, c4, c4); |
| 134 |
s0 = qd::quick_two_sum(c2, s0, c3); |
| 135 |
s0 = qd::quick_two_sum(c1, s0, c2); |
| 136 |
c0 = qd::quick_two_sum(c0, s0, c1); |
| 137 |
|
| 138 |
s0 = c0; |
| 139 |
s1 = c1; |
| 140 |
|
| 141 |
s0 = qd::quick_two_sum(c0, c1, s1); |
| 142 |
if (s1 != 0.0) { |
| 143 |
s1 = qd::quick_two_sum(s1, c2, s2); |
| 144 |
if (s2 != 0.0) { |
| 145 |
s2 = qd::quick_two_sum(s2, c3, s3); |
| 146 |
if (s3 != 0.0) |
| 147 |
s3 += c4; |
| 148 |
else |
| 149 |
s2 += c4; |
| 150 |
} else { |
| 151 |
s1 = qd::quick_two_sum(s1, c3, s2); |
| 152 |
if (s2 != 0.0) |
| 153 |
s2 = qd::quick_two_sum(s2, c4, s3); |
| 154 |
else |
| 155 |
s1 = qd::quick_two_sum(s1, c4, s2); |
| 156 |
} |
| 157 |
} else { |
| 158 |
s0 = qd::quick_two_sum(s0, c2, s1); |
| 159 |
if (s1 != 0.0) { |
| 160 |
s1 = qd::quick_two_sum(s1, c3, s2); |
| 161 |
if (s2 != 0.0) |
| 162 |
s2 = qd::quick_two_sum(s2, c4, s3); |
| 163 |
else |
| 164 |
s1 = qd::quick_two_sum(s1, c4, s2); |
| 165 |
} else { |
| 166 |
s0 = qd::quick_two_sum(s0, c3, s1); |
| 167 |
if (s1 != 0.0) |
| 168 |
s1 = qd::quick_two_sum(s1, c4, s2); |
| 169 |
else |
| 170 |
s0 = qd::quick_two_sum(s0, c4, s1); |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
c0 = s0; |
| 175 |
c1 = s1; |
| 176 |
c2 = s2; |
| 177 |
c3 = s3; |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
inline void qd_real::renorm() { |
| 182 |
qd::renorm(x[0], x[1], x[2], x[3]); |
| 183 |
} |
| 184 |
|
| 185 |
inline void qd_real::renorm(double &e) { |
| 186 |
qd::renorm(x[0], x[1], x[2], x[3], e); |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
/********** Additions ************/ |
| 191 |
namespace qd { |
| 192 |
|
| 193 |
inline void three_sum(double &a, double &b, double &c) { |
| 194 |
double t1, t2, t3; |
| 195 |
t1 = qd::two_sum(a, b, t2); |
| 196 |
a = qd::two_sum(c, t1, t3); |
| 197 |
b = qd::two_sum(t2, t3, c); |
| 198 |
} |
| 199 |
|
| 200 |
inline void three_sum2(double &a, double &b, double &c) { |
| 201 |
double t1, t2, t3; |
| 202 |
t1 = qd::two_sum(a, b, t2); |
| 203 |
a = qd::two_sum(c, t1, t3); |
| 204 |
b = t2 + t3; |
| 205 |
} |
| 206 |
|
| 207 |
} |
| 208 |
|
| 209 |
/* quad-double + double */ |
| 210 |
inline qd_real operator+(const qd_real &a, double b) { |
| 211 |
double c0, c1, c2, c3; |
| 212 |
double e; |
| 213 |
|
| 214 |
c0 = qd::two_sum(a[0], b, e); |
| 215 |
c1 = qd::two_sum(a[1], e, e); |
| 216 |
c2 = qd::two_sum(a[2], e, e); |
| 217 |
c3 = qd::two_sum(a[3], e, e); |
| 218 |
|
| 219 |
qd::renorm(c0, c1, c2, c3, e); |
| 220 |
|
| 221 |
return qd_real(c0, c1, c2, c3); |
| 222 |
} |
| 223 |
|
| 224 |
/* quad-double + double-double */ |
| 225 |
inline qd_real operator+(const qd_real &a, const dd_real &b) { |
| 226 |
|
| 227 |
double s0, s1, s2, s3; |
| 228 |
double t0, t1; |
| 229 |
|
| 230 |
s0 = qd::two_sum(a[0], b._hi(), t0); |
| 231 |
s1 = qd::two_sum(a[1], b._lo(), t1); |
| 232 |
|
| 233 |
s1 = qd::two_sum(s1, t0, t0); |
| 234 |
|
| 235 |
s2 = a[2]; |
| 236 |
qd::three_sum(s2, t0, t1); |
| 237 |
|
| 238 |
s3 = qd::two_sum(t0, a[3], t0); |
| 239 |
t0 += t1; |
| 240 |
|
| 241 |
qd::renorm(s0, s1, s2, s3, t0); |
| 242 |
return qd_real(s0, s1, s2, s3); |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
/* double + quad-double */ |
| 247 |
inline qd_real operator+(double a, const qd_real &b) { |
| 248 |
return (b + a); |
| 249 |
} |
| 250 |
|
| 251 |
/* double-double + quad-double */ |
| 252 |
inline qd_real operator+(const dd_real &a, const qd_real &b) { |
| 253 |
return (b + a); |
| 254 |
} |
| 255 |
|
| 256 |
namespace qd { |
| 257 |
|
| 258 |
/* s = quick_three_accum(a, b, c) adds c to the dd-pair (a, b). |
| 259 |
* If the result does not fit in two doubles, then the sum is |
| 260 |
* output into s and (a,b) contains the remainder. Otherwise |
| 261 |
* s is zero and (a,b) contains the sum. */ |
| 262 |
inline double quick_three_accum(double &a, double &b, double c) { |
| 263 |
double s; |
| 264 |
bool za, zb; |
| 265 |
|
| 266 |
s = qd::two_sum(b, c, b); |
| 267 |
s = qd::two_sum(a, s, a); |
| 268 |
|
| 269 |
za = (a != 0.0); |
| 270 |
zb = (b != 0.0); |
| 271 |
|
| 272 |
if (za && zb) |
| 273 |
return s; |
| 274 |
|
| 275 |
if (!zb) { |
| 276 |
b = a; |
| 277 |
a = s; |
| 278 |
} else { |
| 279 |
a = s; |
| 280 |
} |
| 281 |
|
| 282 |
return 0.0; |
| 283 |
} |
| 284 |
|
| 285 |
} |
| 286 |
|
| 287 |
inline qd_real qd_real::ieee_add(const qd_real &a, const qd_real &b) { |
| 288 |
int i, j, k; |
| 289 |
double s, t; |
| 290 |
double u, v; /* double-length accumulator */ |
| 291 |
double x[4] = {0.0, 0.0, 0.0, 0.0}; |
| 292 |
|
| 293 |
i = j = k = 0; |
| 294 |
if (std::abs(a[i]) > std::abs(b[j])) |
| 295 |
u = a[i++]; |
| 296 |
else |
| 297 |
u = b[j++]; |
| 298 |
if (std::abs(a[i]) > std::abs(b[j])) |
| 299 |
v = a[i++]; |
| 300 |
else |
| 301 |
v = b[j++]; |
| 302 |
|
| 303 |
u = qd::quick_two_sum(u, v, v); |
| 304 |
|
| 305 |
while (k < 4) { |
| 306 |
if (i >= 4 && j >= 4) { |
| 307 |
x[k] = u; |
| 308 |
if (k < 3) |
| 309 |
x[++k] = v; |
| 310 |
break; |
| 311 |
} |
| 312 |
|
| 313 |
if (i >= 4) |
| 314 |
t = b[j++]; |
| 315 |
else if (j >= 4) |
| 316 |
t = a[i++]; |
| 317 |
else if (std::abs(a[i]) > std::abs(b[j])) { |
| 318 |
t = a[i++]; |
| 319 |
} else |
| 320 |
t = b[j++]; |
| 321 |
|
| 322 |
s = qd::quick_three_accum(u, v, t); |
| 323 |
|
| 324 |
if (s != 0.0) { |
| 325 |
x[k++] = s; |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
/* add the rest. */ |
| 330 |
for (k = i; k < 4; k++) |
| 331 |
x[3] += a[k]; |
| 332 |
for (k = j; k < 4; k++) |
| 333 |
x[3] += b[k]; |
| 334 |
|
| 335 |
qd::renorm(x[0], x[1], x[2], x[3]); |
| 336 |
return qd_real(x[0], x[1], x[2], x[3]); |
| 337 |
} |
| 338 |
|
| 339 |
inline qd_real qd_real::sloppy_add(const qd_real &a, const qd_real &b) { |
| 340 |
/* |
| 341 |
double s0, s1, s2, s3; |
| 342 |
double t0, t1, t2, t3; |
| 343 |
|
| 344 |
s0 = qd::two_sum(a[0], b[0], t0); |
| 345 |
s1 = qd::two_sum(a[1], b[1], t1); |
| 346 |
s2 = qd::two_sum(a[2], b[2], t2); |
| 347 |
s3 = qd::two_sum(a[3], b[3], t3); |
| 348 |
|
| 349 |
s1 = qd::two_sum(s1, t0, t0); |
| 350 |
qd::three_sum(s2, t0, t1); |
| 351 |
qd::three_sum2(s3, t0, t2); |
| 352 |
t0 = t0 + t1 + t3; |
| 353 |
|
| 354 |
qd::renorm(s0, s1, s2, s3, t0); |
| 355 |
return qd_real(s0, s1, s2, s3, t0); |
| 356 |
*/ |
| 357 |
|
| 358 |
/* Same as above, but addition re-organized to minimize |
| 359 |
data dependency ... unfortunately some compilers are |
| 360 |
not very smart to do this automatically */ |
| 361 |
double s0, s1, s2, s3; |
| 362 |
double t0, t1, t2, t3; |
| 363 |
|
| 364 |
volatile double v0, v1, v2, v3; |
| 365 |
volatile double u0, u1, u2, u3; |
| 366 |
volatile double w0, w1, w2, w3; |
| 367 |
|
| 368 |
s0 = a[0] + b[0]; |
| 369 |
s1 = a[1] + b[1]; |
| 370 |
s2 = a[2] + b[2]; |
| 371 |
s3 = a[3] + b[3]; |
| 372 |
|
| 373 |
v0 = s0 - a[0]; |
| 374 |
v1 = s1 - a[1]; |
| 375 |
v2 = s2 - a[2]; |
| 376 |
v3 = s3 - a[3]; |
| 377 |
|
| 378 |
u0 = s0 - v0; |
| 379 |
u1 = s1 - v1; |
| 380 |
u2 = s2 - v2; |
| 381 |
u3 = s3 - v3; |
| 382 |
|
| 383 |
w0 = a[0] - u0; |
| 384 |
w1 = a[1] - u1; |
| 385 |
w2 = a[2] - u2; |
| 386 |
w3 = a[3] - u3; |
| 387 |
|
| 388 |
u0 = b[0] - v0; |
| 389 |
u1 = b[1] - v1; |
| 390 |
u2 = b[2] - v2; |
| 391 |
u3 = b[3] - v3; |
| 392 |
|
| 393 |
t0 = w0 + u0; |
| 394 |
t1 = w1 + u1; |
| 395 |
t2 = w2 + u2; |
| 396 |
t3 = w3 + u3; |
| 397 |
|
| 398 |
s1 = qd::two_sum(s1, t0, t0); |
| 399 |
qd::three_sum(s2, t0, t1); |
| 400 |
qd::three_sum2(s3, t0, t2); |
| 401 |
t0 = t0 + t1 + t3; |
| 402 |
|
| 403 |
/* renormalize */ |
| 404 |
qd::renorm(s0, s1, s2, s3, t0); |
| 405 |
return qd_real(s0, s1, s2, s3); |
| 406 |
} |
| 407 |
|
| 408 |
/* quad-double + quad-double */ |
| 409 |
inline qd_real operator+(const qd_real &a, const qd_real &b) { |
| 410 |
#ifndef QD_IEEE_ADD |
| 411 |
return qd_real::sloppy_add(a, b); |
| 412 |
#else |
| 413 |
return qd_real::ieee_add(a, b); |
| 414 |
#endif |
| 415 |
} |
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
/********** Self-Additions ************/ |
| 420 |
/* quad-double += double */ |
| 421 |
inline qd_real &qd_real::operator+=(double a) { |
| 422 |
*this = *this + a; |
| 423 |
return *this; |
| 424 |
} |
| 425 |
|
| 426 |
/* quad-double += double-double */ |
| 427 |
inline qd_real &qd_real::operator+=(const dd_real &a) { |
| 428 |
*this = *this + a; |
| 429 |
return *this; |
| 430 |
} |
| 431 |
|
| 432 |
/* quad-double += quad-double */ |
| 433 |
inline qd_real &qd_real::operator+=(const qd_real &a) { |
| 434 |
*this = *this + a; |
| 435 |
return *this; |
| 436 |
} |
| 437 |
|
| 438 |
/********** Unary Minus **********/ |
| 439 |
inline qd_real qd_real::operator-() const { |
| 440 |
return qd_real(-x[0], -x[1], -x[2], -x[3]); |
| 441 |
} |
| 442 |
|
| 443 |
/********** Unary Minus **********/ |
| 444 |
inline qd_real qd_real::operator+() const { |
| 445 |
return *this; |
| 446 |
} |
| 447 |
/********** Subtractions **********/ |
| 448 |
inline qd_real operator-(const qd_real &a, double b) { |
| 449 |
return (a + (-b)); |
| 450 |
} |
| 451 |
|
| 452 |
inline qd_real operator-(double a, const qd_real &b) { |
| 453 |
return (a + (-b)); |
| 454 |
} |
| 455 |
|
| 456 |
inline qd_real operator-(const qd_real &a, const dd_real &b) { |
| 457 |
return (a + (-b)); |
| 458 |
} |
| 459 |
|
| 460 |
inline qd_real operator-(const dd_real &a, const qd_real &b) { |
| 461 |
return (a + (-b)); |
| 462 |
} |
| 463 |
|
| 464 |
inline qd_real operator-(const qd_real &a, const qd_real &b) { |
| 465 |
return (a + (-b)); |
| 466 |
} |
| 467 |
|
| 468 |
/********** Self-Subtractions **********/ |
| 469 |
inline qd_real &qd_real::operator-=(double a) { |
| 470 |
return ((*this) += (-a)); |
| 471 |
} |
| 472 |
|
| 473 |
inline qd_real &qd_real::operator-=(const dd_real &a) { |
| 474 |
return ((*this) += (-a)); |
| 475 |
} |
| 476 |
|
| 477 |
inline qd_real &qd_real::operator-=(const qd_real &a) { |
| 478 |
return ((*this) += (-a)); |
| 479 |
} |
| 480 |
|
| 481 |
|
| 482 |
inline qd_real operator*(double a, const qd_real &b) { |
| 483 |
return (b * a); |
| 484 |
} |
| 485 |
|
| 486 |
inline qd_real operator*(const dd_real &a, const qd_real &b) { |
| 487 |
return (b * a); |
| 488 |
} |
| 489 |
|
| 490 |
inline qd_real mul_pwr2(const qd_real &a, double b) { |
| 491 |
return qd_real(a[0] * b, a[1] * b, a[2] * b, a[3] * b); |
| 492 |
} |
| 493 |
|
| 494 |
/********** Multiplications **********/ |
| 495 |
inline qd_real operator*(const qd_real &a, double b) { |
| 496 |
double p0, p1, p2, p3; |
| 497 |
double q0, q1, q2; |
| 498 |
double s0, s1, s2, s3, s4; |
| 499 |
|
| 500 |
p0 = qd::two_prod(a[0], b, q0); |
| 501 |
p1 = qd::two_prod(a[1], b, q1); |
| 502 |
p2 = qd::two_prod(a[2], b, q2); |
| 503 |
p3 = a[3] * b; |
| 504 |
|
| 505 |
s0 = p0; |
| 506 |
|
| 507 |
s1 = qd::two_sum(q0, p1, s2); |
| 508 |
|
| 509 |
qd::three_sum(s2, q1, p2); |
| 510 |
|
| 511 |
qd::three_sum2(q1, q2, p3); |
| 512 |
s3 = q1; |
| 513 |
|
| 514 |
s4 = q2 + p2; |
| 515 |
|
| 516 |
qd::renorm(s0, s1, s2, s3, s4); |
| 517 |
return qd_real(s0, s1, s2, s3); |
| 518 |
|
| 519 |
} |
| 520 |
|
| 521 |
/* quad-double * double-double */ |
| 522 |
/* a0 * b0 0 |
| 523 |
a0 * b1 1 |
| 524 |
a1 * b0 2 |
| 525 |
a1 * b1 3 |
| 526 |
a2 * b0 4 |
| 527 |
a2 * b1 5 |
| 528 |
a3 * b0 6 |
| 529 |
a3 * b1 7 */ |
| 530 |
inline qd_real operator*(const qd_real &a, const dd_real &b) { |
| 531 |
double p0, p1, p2, p3, p4; |
| 532 |
double q0, q1, q2, q3, q4; |
| 533 |
double s0, s1, s2; |
| 534 |
double t0, t1; |
| 535 |
|
| 536 |
p0 = qd::two_prod(a[0], b._hi(), q0); |
| 537 |
p1 = qd::two_prod(a[0], b._lo(), q1); |
| 538 |
p2 = qd::two_prod(a[1], b._hi(), q2); |
| 539 |
p3 = qd::two_prod(a[1], b._lo(), q3); |
| 540 |
p4 = qd::two_prod(a[2], b._hi(), q4); |
| 541 |
|
| 542 |
qd::three_sum(p1, p2, q0); |
| 543 |
|
| 544 |
/* Five-Three-Sum */ |
| 545 |
qd::three_sum(p2, p3, p4); |
| 546 |
q1 = qd::two_sum(q1, q2, q2); |
| 547 |
s0 = qd::two_sum(p2, q1, t0); |
| 548 |
s1 = qd::two_sum(p3, q2, t1); |
| 549 |
s1 = qd::two_sum(s1, t0, t0); |
| 550 |
s2 = t0 + t1 + p4; |
| 551 |
p2 = s0; |
| 552 |
|
| 553 |
p3 = a[2] * b._hi() + a[3] * b._lo() + q3 + q4; |
| 554 |
qd::three_sum2(p3, q0, s1); |
| 555 |
p4 = q0 + s2; |
| 556 |
|
| 557 |
qd::renorm(p0, p1, p2, p3, p4); |
| 558 |
return qd_real(p0, p1, p2, p3); |
| 559 |
} |
| 560 |
|
| 561 |
/* quad-double * quad-double */ |
| 562 |
/* a0 * b0 0 |
| 563 |
a0 * b1 1 |
| 564 |
a1 * b0 2 |
| 565 |
a0 * b2 3 |
| 566 |
a1 * b1 4 |
| 567 |
a2 * b0 5 |
| 568 |
a0 * b3 6 |
| 569 |
a1 * b2 7 |
| 570 |
a2 * b1 8 |
| 571 |
a3 * b0 9 */ |
| 572 |
inline qd_real qd_real::sloppy_mul(const qd_real &a, const qd_real &b) { |
| 573 |
double p0, p1, p2, p3, p4, p5; |
| 574 |
double q0, q1, q2, q3, q4, q5; |
| 575 |
double t0, t1; |
| 576 |
double s0, s1, s2; |
| 577 |
|
| 578 |
p0 = qd::two_prod(a[0], b[0], q0); |
| 579 |
|
| 580 |
p1 = qd::two_prod(a[0], b[1], q1); |
| 581 |
p2 = qd::two_prod(a[1], b[0], q2); |
| 582 |
|
| 583 |
p3 = qd::two_prod(a[0], b[2], q3); |
| 584 |
p4 = qd::two_prod(a[1], b[1], q4); |
| 585 |
p5 = qd::two_prod(a[2], b[0], q5); |
| 586 |
|
| 587 |
/* Start Accumulation */ |
| 588 |
qd::three_sum(p1, p2, q0); |
| 589 |
|
| 590 |
/* Six-Three Sum of p2, q1, q2, p3, p4, p5. */ |
| 591 |
qd::three_sum(p2, q1, q2); |
| 592 |
qd::three_sum(p3, p4, p5); |
| 593 |
/* compute (s0, s1, s2) = (p2, q1, q2) + (p3, p4, p5). */ |
| 594 |
s0 = qd::two_sum(p2, p3, t0); |
| 595 |
s1 = qd::two_sum(q1, p4, t1); |
| 596 |
s2 = q2 + p5; |
| 597 |
s1 = qd::two_sum(s1, t0, t0); |
| 598 |
s2 += (t0 + t1); |
| 599 |
|
| 600 |
/* O(eps^3) order terms */ |
| 601 |
s1 += a[0]*b[3] + a[1]*b[2] + a[2]*b[1] + a[3]*b[0] + q0 + q3 + q4 + q5; |
| 602 |
qd::renorm(p0, p1, s0, s1, s2); |
| 603 |
return qd_real(p0, p1, s0, s1); |
| 604 |
} |
| 605 |
|
| 606 |
inline qd_real qd_real::accurate_mul(const qd_real &a, const qd_real &b) { |
| 607 |
double p0, p1, p2, p3, p4, p5; |
| 608 |
double q0, q1, q2, q3, q4, q5; |
| 609 |
double p6, p7, p8, p9; |
| 610 |
double q6, q7, q8, q9; |
| 611 |
double r0, r1; |
| 612 |
double t0, t1; |
| 613 |
double s0, s1, s2; |
| 614 |
|
| 615 |
p0 = qd::two_prod(a[0], b[0], q0); |
| 616 |
|
| 617 |
p1 = qd::two_prod(a[0], b[1], q1); |
| 618 |
p2 = qd::two_prod(a[1], b[0], q2); |
| 619 |
|
| 620 |
p3 = qd::two_prod(a[0], b[2], q3); |
| 621 |
p4 = qd::two_prod(a[1], b[1], q4); |
| 622 |
p5 = qd::two_prod(a[2], b[0], q5); |
| 623 |
|
| 624 |
/* Start Accumulation */ |
| 625 |
qd::three_sum(p1, p2, q0); |
| 626 |
|
| 627 |
/* Six-Three Sum of p2, q1, q2, p3, p4, p5. */ |
| 628 |
qd::three_sum(p2, q1, q2); |
| 629 |
qd::three_sum(p3, p4, p5); |
| 630 |
/* compute (s0, s1, s2) = (p2, q1, q2) + (p3, p4, p5). */ |
| 631 |
s0 = qd::two_sum(p2, p3, t0); |
| 632 |
s1 = qd::two_sum(q1, p4, t1); |
| 633 |
s2 = q2 + p5; |
| 634 |
s1 = qd::two_sum(s1, t0, t0); |
| 635 |
s2 += (t0 + t1); |
| 636 |
|
| 637 |
/* O(eps^3) order terms */ |
| 638 |
p6 = qd::two_prod(a[0], b[3], q6); |
| 639 |
p7 = qd::two_prod(a[1], b[2], q7); |
| 640 |
p8 = qd::two_prod(a[2], b[1], q8); |
| 641 |
p9 = qd::two_prod(a[3], b[0], q9); |
| 642 |
|
| 643 |
/* Nine-Two-Sum of q0, s1, q3, q4, q5, p6, p7, p8, p9. */ |
| 644 |
q0 = qd::two_sum(q0, q3, q3); |
| 645 |
q4 = qd::two_sum(q4, q5, q5); |
| 646 |
p6 = qd::two_sum(p6, p7, p7); |
| 647 |
p8 = qd::two_sum(p8, p9, p9); |
| 648 |
/* Compute (t0, t1) = (q0, q3) + (q4, q5). */ |
| 649 |
t0 = qd::two_sum(q0, q4, t1); |
| 650 |
t1 += (q3 + q5); |
| 651 |
/* Compute (r0, r1) = (p6, p7) + (p8, p9). */ |
| 652 |
r0 = qd::two_sum(p6, p8, r1); |
| 653 |
r1 += (p7 + p9); |
| 654 |
/* Compute (q3, q4) = (t0, t1) + (r0, r1). */ |
| 655 |
q3 = qd::two_sum(t0, r0, q4); |
| 656 |
q4 += (t1 + r1); |
| 657 |
/* Compute (t0, t1) = (q3, q4) + s1. */ |
| 658 |
t0 = qd::two_sum(q3, s1, t1); |
| 659 |
t1 += q4; |
| 660 |
|
| 661 |
/* O(eps^4) terms -- Nine-One-Sum */ |
| 662 |
t1 += a[1] * b[3] + a[2] * b[2] + a[3] * b[1] + q6 + q7 + q8 + q9 + s2; |
| 663 |
|
| 664 |
qd::renorm(p0, p1, s0, t0, t1); |
| 665 |
return qd_real(p0, p1, s0, t0); |
| 666 |
} |
| 667 |
|
| 668 |
inline qd_real operator*(const qd_real &a, const qd_real &b) { |
| 669 |
#ifdef QD_SLOPPY_MUL |
| 670 |
return qd_real::sloppy_mul(a, b); |
| 671 |
#else |
| 672 |
return qd_real::accurate_mul(a, b); |
| 673 |
#endif |
| 674 |
} |
| 675 |
|
| 676 |
/* quad-double ^ 2 = (x0 + x1 + x2 + x3) ^ 2 |
| 677 |
= x0 ^ 2 + 2 x0 * x1 + (2 x0 * x2 + x1 ^ 2) |
| 678 |
+ (2 x0 * x3 + 2 x1 * x2) */ |
| 679 |
inline qd_real sqr(const qd_real &a) { |
| 680 |
double p0, p1, p2, p3, p4, p5; |
| 681 |
double q0, q1, q2, q3; |
| 682 |
double s0, s1; |
| 683 |
double t0, t1; |
| 684 |
|
| 685 |
p0 = qd::two_sqr(a[0], q0); |
| 686 |
p1 = qd::two_prod(2.0 * a[0], a[1], q1); |
| 687 |
p2 = qd::two_prod(2.0 * a[0], a[2], q2); |
| 688 |
p3 = qd::two_sqr(a[1], q3); |
| 689 |
|
| 690 |
p1 = qd::two_sum(q0, p1, q0); |
| 691 |
|
| 692 |
q0 = qd::two_sum(q0, q1, q1); |
| 693 |
p2 = qd::two_sum(p2, p3, p3); |
| 694 |
|
| 695 |
s0 = qd::two_sum(q0, p2, t0); |
| 696 |
s1 = qd::two_sum(q1, p3, t1); |
| 697 |
|
| 698 |
s1 = qd::two_sum(s1, t0, t0); |
| 699 |
t0 += t1; |
| 700 |
|
| 701 |
s1 = qd::quick_two_sum(s1, t0, t0); |
| 702 |
p2 = qd::quick_two_sum(s0, s1, t1); |
| 703 |
p3 = qd::quick_two_sum(t1, t0, q0); |
| 704 |
|
| 705 |
p4 = 2.0 * a[0] * a[3]; |
| 706 |
p5 = 2.0 * a[1] * a[2]; |
| 707 |
|
| 708 |
p4 = qd::two_sum(p4, p5, p5); |
| 709 |
q2 = qd::two_sum(q2, q3, q3); |
| 710 |
|
| 711 |
t0 = qd::two_sum(p4, q2, t1); |
| 712 |
t1 = t1 + p5 + q3; |
| 713 |
|
| 714 |
p3 = qd::two_sum(p3, t0, p4); |
| 715 |
p4 = p4 + q0 + t1; |
| 716 |
|
| 717 |
qd::renorm(p0, p1, p2, p3, p4); |
| 718 |
return qd_real(p0, p1, p2, p3); |
| 719 |
|
| 720 |
} |
| 721 |
|
| 722 |
/********** Self-Multiplication **********/ |
| 723 |
/* quad-double *= double */ |
| 724 |
inline qd_real &qd_real::operator*=(double a) { |
| 725 |
*this = (*this * a); |
| 726 |
return *this; |
| 727 |
} |
| 728 |
|
| 729 |
/* quad-double *= double-double */ |
| 730 |
inline qd_real &qd_real::operator*=(const dd_real &a) { |
| 731 |
*this = (*this * a); |
| 732 |
return *this; |
| 733 |
} |
| 734 |
|
| 735 |
/* quad-double *= quad-double */ |
| 736 |
inline qd_real &qd_real::operator*=(const qd_real &a) { |
| 737 |
*this = *this * a; |
| 738 |
return *this; |
| 739 |
} |
| 740 |
|
| 741 |
inline qd_real operator/ (const qd_real &a, const dd_real &b) { |
| 742 |
#ifdef QD_SLOPPY_DIV |
| 743 |
return qd_real::sloppy_div(a, b); |
| 744 |
#else |
| 745 |
return qd_real::accurate_div(a, b); |
| 746 |
#endif |
| 747 |
} |
| 748 |
|
| 749 |
inline qd_real operator/(const qd_real &a, const qd_real &b) { |
| 750 |
#ifdef QD_SLOPPY_DIV |
| 751 |
return qd_real::sloppy_div(a, b); |
| 752 |
#else |
| 753 |
return qd_real::accurate_div(a, b); |
| 754 |
#endif |
| 755 |
} |
| 756 |
|
| 757 |
/* double / quad-double */ |
| 758 |
inline qd_real operator/(double a, const qd_real &b) { |
| 759 |
return qd_real(a) / b; |
| 760 |
} |
| 761 |
|
| 762 |
/* double-double / quad-double */ |
| 763 |
inline qd_real operator/(const dd_real &a, const qd_real &b) { |
| 764 |
return qd_real(a) / b; |
| 765 |
} |
| 766 |
|
| 767 |
/********** Self-Divisions **********/ |
| 768 |
/* quad-double /= double */ |
| 769 |
inline qd_real &qd_real::operator/=(double a) { |
| 770 |
*this = (*this / a); |
| 771 |
return *this; |
| 772 |
} |
| 773 |
|
| 774 |
/* quad-double /= double-double */ |
| 775 |
inline qd_real &qd_real::operator/=(const dd_real &a) { |
| 776 |
*this = (*this / a); |
| 777 |
return *this; |
| 778 |
} |
| 779 |
|
| 780 |
/* quad-double /= quad-double */ |
| 781 |
inline qd_real &qd_real::operator/=(const qd_real &a) { |
| 782 |
*this = (*this / a); |
| 783 |
return *this; |
| 784 |
} |
| 785 |
|
| 786 |
|
| 787 |
/********** Exponentiation **********/ |
| 788 |
inline qd_real qd_real::operator^(int n) const { |
| 789 |
return pow(*this, n); |
| 790 |
} |
| 791 |
|
| 792 |
/********** Miscellaneous **********/ |
| 793 |
inline qd_real abs(const qd_real &a) { |
| 794 |
return (a[0] < 0.0) ? -a : a; |
| 795 |
} |
| 796 |
|
| 797 |
inline qd_real fabs(const qd_real &a) { |
| 798 |
return abs(a); |
| 799 |
} |
| 800 |
|
| 801 |
/* Quick version. May be off by one when qd is very close |
| 802 |
to the middle of two integers. */ |
| 803 |
inline qd_real quick_nint(const qd_real &a) { |
| 804 |
qd_real r = qd_real(qd::nint(a[0]), qd::nint(a[1]), |
| 805 |
qd::nint(a[2]), qd::nint(a[3])); |
| 806 |
r.renorm(); |
| 807 |
return r; |
| 808 |
} |
| 809 |
|
| 810 |
/*********** Assignments ************/ |
| 811 |
/* quad-double = double */ |
| 812 |
inline qd_real &qd_real::operator=(double a) { |
| 813 |
x[0] = a; |
| 814 |
x[1] = x[2] = x[3] = 0.0; |
| 815 |
return *this; |
| 816 |
} |
| 817 |
|
| 818 |
/* quad-double = double-double */ |
| 819 |
inline qd_real &qd_real::operator=(const dd_real &a) { |
| 820 |
x[0] = a._hi(); |
| 821 |
x[1] = a._lo(); |
| 822 |
x[2] = x[3] = 0.0; |
| 823 |
return *this; |
| 824 |
} |
| 825 |
|
| 826 |
/********** Equality Comparison **********/ |
| 827 |
inline bool operator==(const qd_real &a, int b) { |
| 828 |
return (a[0] == double(b) && a[1] == 0.0 && a[2] == 0.0 && a[3] == 0.0); |
| 829 |
} |
| 830 |
|
| 831 |
inline bool operator==(int a, const qd_real &b) { |
| 832 |
return (b == a); |
| 833 |
} |
| 834 |
|
| 835 |
inline bool operator==(const qd_real &a, double b) { |
| 836 |
return (a[0] == b && a[1] == 0.0 && a[2] == 0.0 && a[3] == 0.0); |
| 837 |
} |
| 838 |
|
| 839 |
inline bool operator==(double a, const qd_real &b) { |
| 840 |
return (b == a); |
| 841 |
} |
| 842 |
|
| 843 |
inline bool operator==(const qd_real &a, const dd_real &b) { |
| 844 |
return (a[0] == b._hi() && a[1] == b._lo() && |
| 845 |
a[2] == 0.0 && a[3] == 0.0); |
| 846 |
} |
| 847 |
|
| 848 |
inline bool operator==(const dd_real &a, const qd_real &b) { |
| 849 |
return (b == a); |
| 850 |
} |
| 851 |
|
| 852 |
inline bool operator==(const qd_real &a, const qd_real &b) { |
| 853 |
return (a[0] == b[0] && a[1] == b[1] && |
| 854 |
a[2] == b[2] && a[3] == b[3]); |
| 855 |
} |
| 856 |
|
| 857 |
|
| 858 |
/********** Less-Than Comparison ***********/ |
| 859 |
inline bool operator<(const qd_real &a, int b) { |
| 860 |
return (a[0] < double(b) || (a[0] == double(b) && a[1] < 0.0)); |
| 861 |
} |
| 862 |
|
| 863 |
inline bool operator<(int a, const qd_real &b) { |
| 864 |
return (b > a); |
| 865 |
} |
| 866 |
|
| 867 |
inline bool operator<(const qd_real &a, double b) { |
| 868 |
return (a[0] < b || (a[0] == b && a[1] < 0.0)); |
| 869 |
} |
| 870 |
|
| 871 |
inline bool operator<(double a, const qd_real &b) { |
| 872 |
return (b > a); |
| 873 |
} |
| 874 |
|
| 875 |
inline bool operator<(const qd_real &a, const dd_real &b) { |
| 876 |
return (a[0] < b._hi() || |
| 877 |
(a[0] == b._hi() && (a[1] < b._lo() || |
| 878 |
(a[1] == b._lo() && a[2] < 0.0)))); |
| 879 |
} |
| 880 |
|
| 881 |
inline bool operator<(const dd_real &a, const qd_real &b) { |
| 882 |
return (b > a); |
| 883 |
} |
| 884 |
|
| 885 |
inline bool operator<(const qd_real &a, const qd_real &b) { |
| 886 |
return (a[0] < b[0] || |
| 887 |
(a[0] == b[0] && (a[1] < b[1] || |
| 888 |
(a[1] == b[1] && (a[2] < b[2] || |
| 889 |
(a[2] == b[2] && a[3] < b[3])))))); |
| 890 |
} |
| 891 |
|
| 892 |
/********** Greater-Than Comparison ***********/ |
| 893 |
inline bool operator>(const qd_real &a, int b) { |
| 894 |
return (a[0] > double(b) || (a[0] == double(b) && a[1] > 0.0)); |
| 895 |
} |
| 896 |
|
| 897 |
inline bool operator>(int a, const qd_real &b) { |
| 898 |
return (b < a); |
| 899 |
} |
| 900 |
|
| 901 |
inline bool operator>(const qd_real &a, double b) { |
| 902 |
return (a[0] > b || (a[0] == b && a[1] > 0.0)); |
| 903 |
} |
| 904 |
|
| 905 |
inline bool operator>(double a, const qd_real &b) { |
| 906 |
return (b < a); |
| 907 |
} |
| 908 |
|
| 909 |
inline bool operator>(const qd_real &a, const dd_real &b) { |
| 910 |
return (a[0] > b._hi() || |
| 911 |
(a[0] == b._hi() && (a[1] > b._lo() || |
| 912 |
(a[1] == b._lo() && a[2] > 0.0)))); |
| 913 |
} |
| 914 |
|
| 915 |
inline bool operator>(const dd_real &a, const qd_real &b) { |
| 916 |
return (b < a); |
| 917 |
} |
| 918 |
|
| 919 |
inline bool operator>(const qd_real &a, const qd_real &b) { |
| 920 |
return (a[0] > b[0] || |
| 921 |
(a[0] == b[0] && (a[1] > b[1] || |
| 922 |
(a[1] == b[1] && (a[2] > b[2] || |
| 923 |
(a[2] == b[2] && a[3] > b[3])))))); |
| 924 |
} |
| 925 |
|
| 926 |
|
| 927 |
/********** Less-Than-Or-Equal-To Comparison **********/ |
| 928 |
inline bool operator<=(const qd_real &a, int b) { |
| 929 |
return (a[0] < double(b) || (a[0] == double(b) && a[1] <= 0.0)); |
| 930 |
} |
| 931 |
|
| 932 |
inline bool operator<=(int a, const qd_real &b) { |
| 933 |
return (b >= a); |
| 934 |
} |
| 935 |
|
| 936 |
inline bool operator<=(const qd_real &a, double b) { |
| 937 |
return (a[0] < b || (a[0] == b && a[1] <= 0.0)); |
| 938 |
} |
| 939 |
|
| 940 |
inline bool operator<=(double a, const qd_real &b) { |
| 941 |
return (b >= a); |
| 942 |
} |
| 943 |
|
| 944 |
inline bool operator<=(const qd_real &a, const dd_real &b) { |
| 945 |
return (a[0] < b._hi() || |
| 946 |
(a[0] == b._hi() && (a[1] < b._lo() || |
| 947 |
(a[1] == b._lo() && a[2] <= 0.0)))); |
| 948 |
} |
| 949 |
|
| 950 |
inline bool operator<=(const dd_real &a, const qd_real &b) { |
| 951 |
return (b >= a); |
| 952 |
} |
| 953 |
|
| 954 |
inline bool operator<=(const qd_real &a, const qd_real &b) { |
| 955 |
return (a[0] < b[0] || |
| 956 |
(a[0] == b[0] && (a[1] < b[1] || |
| 957 |
(a[1] == b[1] && (a[2] < b[2] || |
| 958 |
(a[2] == b[2] && a[3] <= b[3])))))); |
| 959 |
} |
| 960 |
|
| 961 |
/********** Greater-Than-Or-Equal-To Comparison **********/ |
| 962 |
inline bool operator>=(const qd_real &a, int b) { |
| 963 |
return (a[0] > double(b) || (a[0] == double(b) && a[1] >= 0.0)); |
| 964 |
} |
| 965 |
|
| 966 |
inline bool operator>=(int a, const qd_real &b) { |
| 967 |
return (b <= a); |
| 968 |
} |
| 969 |
|
| 970 |
inline bool operator>=(const qd_real &a, double b) { |
| 971 |
return (a[0] > b || (a[0] == b && a[1] >= 0.0)); |
| 972 |
} |
| 973 |
|
| 974 |
inline bool operator>=(double a, const qd_real &b) { |
| 975 |
return (b <= a); |
| 976 |
} |
| 977 |
|
| 978 |
inline bool operator>=(const qd_real &a, const dd_real &b) { |
| 979 |
return (a[0] > b._hi() || |
| 980 |
(a[0] == b._hi() && (a[1] > b._lo() || |
| 981 |
(a[1] == b._lo() && a[2] >= 0.0)))); |
| 982 |
} |
| 983 |
|
| 984 |
inline bool operator>=(const dd_real &a, const qd_real &b) { |
| 985 |
return (b <= a); |
| 986 |
} |
| 987 |
|
| 988 |
inline bool operator>=(const qd_real &a, const qd_real &b) { |
| 989 |
return (a[0] > b[0] || |
| 990 |
(a[0] == b[0] && (a[1] > b[1] || |
| 991 |
(a[1] == b[1] && (a[2] > b[2] || |
| 992 |
(a[2] == b[2] && a[3] >= b[3])))))); |
| 993 |
} |
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
/********** Not-Equal-To Comparison **********/ |
| 998 |
inline bool operator!=(const qd_real &a, int b) { |
| 999 |
return !(a == b); |
| 1000 |
} |
| 1001 |
|
| 1002 |
inline bool operator!=(int a, const qd_real &b) { |
| 1003 |
return !(a == b); |
| 1004 |
} |
| 1005 |
|
| 1006 |
inline bool operator!=(const qd_real &a, double b) { |
| 1007 |
return !(a == b); |
| 1008 |
} |
| 1009 |
|
| 1010 |
inline bool operator!=(double a, const qd_real &b) { |
| 1011 |
return !(a == b); |
| 1012 |
} |
| 1013 |
|
| 1014 |
inline bool operator!=(const qd_real &a, const dd_real &b) { |
| 1015 |
return !(a == b); |
| 1016 |
} |
| 1017 |
|
| 1018 |
inline bool operator!=(const dd_real &a, const qd_real &b) { |
| 1019 |
return !(a == b); |
| 1020 |
} |
| 1021 |
|
| 1022 |
inline bool operator!=(const qd_real &a, const qd_real &b) { |
| 1023 |
return !(a == b); |
| 1024 |
} |
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
inline qd_real aint(const qd_real &a) { |
| 1029 |
return (a[0] >= 0) ? floor(a) : ceil(a); |
| 1030 |
} |
| 1031 |
|
| 1032 |
inline bool qd_real::is_zero() const { |
| 1033 |
return (x[0] == 0.0); |
| 1034 |
} |
| 1035 |
|
| 1036 |
inline bool qd_real::is_one() const { |
| 1037 |
return (x[0] == 1.0 && x[1] == 0.0 && x[2] == 0.0 && x[3] == 0.0); |
| 1038 |
} |
| 1039 |
|
| 1040 |
inline bool qd_real::is_positive() const { |
| 1041 |
return (x[0] > 0.0); |
| 1042 |
} |
| 1043 |
|
| 1044 |
inline bool qd_real::is_negative() const { |
| 1045 |
return (x[0] < 0.0); |
| 1046 |
} |
| 1047 |
|
| 1048 |
inline dd_real to_dd_real(const qd_real &a) { |
| 1049 |
return dd_real(a[0], a[1]); |
| 1050 |
} |
| 1051 |
|
| 1052 |
inline double to_double(const qd_real &a) { |
| 1053 |
return a[0]; |
| 1054 |
} |
| 1055 |
|
| 1056 |
inline int to_int(const qd_real &a) { |
| 1057 |
return static_cast<int>(a[0]); |
| 1058 |
} |
| 1059 |
|
| 1060 |
inline qd_real inv(const qd_real &qd) { |
| 1061 |
return 1.0 / qd; |
| 1062 |
} |
| 1063 |
|
| 1064 |
inline qd_real max(const qd_real &a, const qd_real &b) { |
| 1065 |
return (a > b) ? a : b; |
| 1066 |
} |
| 1067 |
|
| 1068 |
inline qd_real max(const qd_real &a, const qd_real &b, |
| 1069 |
const qd_real &c) { |
| 1070 |
return (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c); |
| 1071 |
} |
| 1072 |
|
| 1073 |
inline qd_real min(const qd_real &a, const qd_real &b) { |
| 1074 |
return (a < b) ? a : b; |
| 1075 |
} |
| 1076 |
|
| 1077 |
inline qd_real min(const qd_real &a, const qd_real &b, |
| 1078 |
const qd_real &c) { |
| 1079 |
return (a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c); |
| 1080 |
} |
| 1081 |
|
| 1082 |
/* Random number generator */ |
| 1083 |
inline qd_real qd_real::rand() { |
| 1084 |
return qdrand(); |
| 1085 |
} |
| 1086 |
|
| 1087 |
inline qd_real ldexp(const qd_real &a, int n) { |
| 1088 |
return qd_real(std::ldexp(a[0], n), std::ldexp(a[1], n), |
| 1089 |
std::ldexp(a[2], n), std::ldexp(a[3], n)); |
| 1090 |
} |
| 1091 |
|
| 1092 |
#endif /* _QD_QD_INLINE_H */ |