1/* 2 * Copyright (c) 1999 3 * Silicon Graphics Computer Systems, Inc. 4 * 5 * Copyright (c) 1999 6 * Boris Fomitchev 7 * 8 * This material is provided "as is", with absolutely no warranty expressed 9 * or implied. Any use is at your own risk. 10 * 11 * Permission to use or copy this software for any purpose is hereby granted 12 * without fee, provided the above notices are retained on all copies. 13 * Permission to modify the code and to distribute modified code is granted, 14 * provided the above notices are retained, and a notice that the code was 15 * modified is included with the above copyright notice. 16 * 17 */ 18#ifndef _STLP_INTERNAL_COMPLEX 19#define _STLP_INTERNAL_COMPLEX 20 21// This header declares the template class complex, as described in 22// in the draft C++ standard. Single-precision complex numbers 23// are complex<float>, double-precision are complex<double>, and 24// quad precision are complex<long double>. 25 26// Note that the template class complex is declared within namespace 27// std, as called for by the draft C++ standard. 28 29#ifndef _STLP_INTERNAL_CMATH 30# include <stl/_cmath.h> 31#endif 32 33_STLP_BEGIN_NAMESPACE 34 35template <class _Tp> 36struct complex { 37 typedef _Tp value_type; 38 typedef complex<_Tp> _Self; 39 40 // Constructors, destructor, assignment operator. 41 complex() : _M_re(0), _M_im(0) {} 42 complex(const value_type& __x) 43 : _M_re(__x), _M_im(0) {} 44 complex(const value_type& __x, const value_type& __y) 45 : _M_re(__x), _M_im(__y) {} 46 complex(const _Self& __z) 47 : _M_re(__z._M_re), _M_im(__z._M_im) {} 48 49 _Self& operator=(const _Self& __z) { 50 _M_re = __z._M_re; 51 _M_im = __z._M_im; 52 return *this; 53 } 54 55#if defined (_STLP_MEMBER_TEMPLATES) && defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) 56 template <class _Tp2> 57 explicit complex(const complex<_Tp2>& __z) 58 : _M_re(__z._M_re), _M_im(__z._M_im) {} 59 60 template <class _Tp2> 61 _Self& operator=(const complex<_Tp2>& __z) { 62 _M_re = __z._M_re; 63 _M_im = __z._M_im; 64 return *this; 65 } 66#endif /* _STLP_MEMBER_TEMPLATES */ 67 68 // Element access. 69 value_type real() const { return _M_re; } 70 value_type imag() const { return _M_im; } 71 72 // Arithmetic op= operations involving one real argument. 73 74 _Self& operator= (const value_type& __x) { 75 _M_re = __x; 76 _M_im = 0; 77 return *this; 78 } 79 _Self& operator+= (const value_type& __x) { 80 _M_re += __x; 81 return *this; 82 } 83 _Self& operator-= (const value_type& __x) { 84 _M_re -= __x; 85 return *this; 86 } 87 _Self& operator*= (const value_type& __x) { 88 _M_re *= __x; 89 _M_im *= __x; 90 return *this; 91 } 92 _Self& operator/= (const value_type& __x) { 93 _M_re /= __x; 94 _M_im /= __x; 95 return *this; 96 } 97 98 // Arithmetic op= operations involving two complex arguments. 99 100 static void _STLP_CALL _div(const value_type& __z1_r, const value_type& __z1_i, 101 const value_type& __z2_r, const value_type& __z2_i, 102 value_type& __res_r, value_type& __res_i); 103 104 static void _STLP_CALL _div(const value_type& __z1_r, 105 const value_type& __z2_r, const value_type& __z2_i, 106 value_type& __res_r, value_type& __res_i); 107 108#if defined (_STLP_MEMBER_TEMPLATES) // && defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) 109 110 template <class _Tp2> _Self& operator+= (const complex<_Tp2>& __z) { 111 _M_re += __z._M_re; 112 _M_im += __z._M_im; 113 return *this; 114 } 115 116 template <class _Tp2> _Self& operator-= (const complex<_Tp2>& __z) { 117 _M_re -= __z._M_re; 118 _M_im -= __z._M_im; 119 return *this; 120 } 121 122 template <class _Tp2> _Self& operator*= (const complex<_Tp2>& __z) { 123 value_type __r = _M_re * __z._M_re - _M_im * __z._M_im; 124 value_type __i = _M_re * __z._M_im + _M_im * __z._M_re; 125 _M_re = __r; 126 _M_im = __i; 127 return *this; 128 } 129 130 template <class _Tp2> _Self& operator/= (const complex<_Tp2>& __z) { 131 value_type __r; 132 value_type __i; 133 _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i); 134 _M_re = __r; 135 _M_im = __i; 136 return *this; 137 } 138#endif /* _STLP_MEMBER_TEMPLATES */ 139 140 _Self& operator+= (const _Self& __z) { 141 _M_re += __z._M_re; 142 _M_im += __z._M_im; 143 return *this; 144 } 145 146 _Self& operator-= (const _Self& __z) { 147 _M_re -= __z._M_re; 148 _M_im -= __z._M_im; 149 return *this; 150 } 151 152 _Self& operator*= (const _Self& __z) { 153 value_type __r = _M_re * __z._M_re - _M_im * __z._M_im; 154 value_type __i = _M_re * __z._M_im + _M_im * __z._M_re; 155 _M_re = __r; 156 _M_im = __i; 157 return *this; 158 } 159 160 _Self& operator/= (const _Self& __z) { 161 value_type __r; 162 value_type __i; 163 _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i); 164 _M_re = __r; 165 _M_im = __i; 166 return *this; 167 } 168 169 // Data members. 170 value_type _M_re; 171 value_type _M_im; 172}; 173 174// Explicit specializations for float, double, long double. The only 175// reason for these specializations is to enable automatic conversions 176// from complex<float> to complex<double>, and complex<double> to 177// complex<long double>. 178 179_STLP_TEMPLATE_NULL 180struct _STLP_CLASS_DECLSPEC complex<float> { 181 typedef float value_type; 182 typedef complex<float> _Self; 183 // Constructors, destructor, assignment operator. 184 185 complex(value_type __x = 0.0f, value_type __y = 0.0f) 186 : _M_re(__x), _M_im(__y) {} 187 188 complex(const complex<float>& __z) : _M_re(__z._M_re), _M_im(__z._M_im) {} 189 190 inline explicit complex(const complex<double>& __z); 191#ifndef _STLP_NO_LONG_DOUBLE 192 inline explicit complex(const complex<long double>& __z); 193#endif 194 // Element access. 195 value_type real() const { return _M_re; } 196 value_type imag() const { return _M_im; } 197 198 // Arithmetic op= operations involving one real argument. 199 200 _Self& operator= (value_type __x) { 201 _M_re = __x; 202 _M_im = 0.0f; 203 return *this; 204 } 205 _Self& operator+= (value_type __x) { 206 _M_re += __x; 207 return *this; 208 } 209 _Self& operator-= (value_type __x) { 210 _M_re -= __x; 211 return *this; 212 } 213 _Self& operator*= (value_type __x) { 214 _M_re *= __x; 215 _M_im *= __x; 216 return *this; 217 } 218 _Self& operator/= (value_type __x) { 219 _M_re /= __x; 220 _M_im /= __x; 221 return *this; 222 } 223 224 // Arithmetic op= operations involving two complex arguments. 225 226 static void _STLP_CALL _div(const float& __z1_r, const float& __z1_i, 227 const float& __z2_r, const float& __z2_i, 228 float& __res_r, float& __res_i); 229 230 static void _STLP_CALL _div(const float& __z1_r, 231 const float& __z2_r, const float& __z2_i, 232 float& __res_r, float& __res_i); 233 234#if defined (_STLP_MEMBER_TEMPLATES) 235 template <class _Tp2> 236 complex<float>& operator=(const complex<_Tp2>& __z) { 237 _M_re = __z._M_re; 238 _M_im = __z._M_im; 239 return *this; 240 } 241 242 template <class _Tp2> 243 complex<float>& operator+= (const complex<_Tp2>& __z) { 244 _M_re += __z._M_re; 245 _M_im += __z._M_im; 246 return *this; 247 } 248 249 template <class _Tp2> 250 complex<float>& operator-= (const complex<_Tp2>& __z) { 251 _M_re -= __z._M_re; 252 _M_im -= __z._M_im; 253 return *this; 254 } 255 256 template <class _Tp2> 257 complex<float>& operator*= (const complex<_Tp2>& __z) { 258 float __r = _M_re * __z._M_re - _M_im * __z._M_im; 259 float __i = _M_re * __z._M_im + _M_im * __z._M_re; 260 _M_re = __r; 261 _M_im = __i; 262 return *this; 263 } 264 265 template <class _Tp2> 266 complex<float>& operator/= (const complex<_Tp2>& __z) { 267 float __r; 268 float __i; 269 _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i); 270 _M_re = __r; 271 _M_im = __i; 272 return *this; 273 } 274 275#endif /* _STLP_MEMBER_TEMPLATES */ 276 277 _Self& operator=(const _Self& __z) { 278 _M_re = __z._M_re; 279 _M_im = __z._M_im; 280 return *this; 281 } 282 283 _Self& operator+= (const _Self& __z) { 284 _M_re += __z._M_re; 285 _M_im += __z._M_im; 286 return *this; 287 } 288 289 _Self& operator-= (const _Self& __z) { 290 _M_re -= __z._M_re; 291 _M_im -= __z._M_im; 292 return *this; 293 } 294 295 _Self& operator*= (const _Self& __z) { 296 value_type __r = _M_re * __z._M_re - _M_im * __z._M_im; 297 value_type __i = _M_re * __z._M_im + _M_im * __z._M_re; 298 _M_re = __r; 299 _M_im = __i; 300 return *this; 301 } 302 303 _Self& operator/= (const _Self& __z) { 304 value_type __r; 305 value_type __i; 306 _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i); 307 _M_re = __r; 308 _M_im = __i; 309 return *this; 310 } 311 312 // Data members. 313 value_type _M_re; 314 value_type _M_im; 315}; 316 317_STLP_TEMPLATE_NULL 318struct _STLP_CLASS_DECLSPEC complex<double> { 319 typedef double value_type; 320 typedef complex<double> _Self; 321 322 // Constructors, destructor, assignment operator. 323 324 complex(value_type __x = 0.0, value_type __y = 0.0) 325 : _M_re(__x), _M_im(__y) {} 326 327 complex(const complex<double>& __z) 328 : _M_re(__z._M_re), _M_im(__z._M_im) {} 329 inline complex(const complex<float>& __z); 330#if !defined (_STLP_NO_LONG_DOUBLE) 331 explicit inline complex(const complex<long double>& __z); 332#endif 333 // Element access. 334 value_type real() const { return _M_re; } 335 value_type imag() const { return _M_im; } 336 337 // Arithmetic op= operations involving one real argument. 338 339 _Self& operator= (value_type __x) { 340 _M_re = __x; 341 _M_im = 0.0; 342 return *this; 343 } 344 _Self& operator+= (value_type __x) { 345 _M_re += __x; 346 return *this; 347 } 348 _Self& operator-= (value_type __x) { 349 _M_re -= __x; 350 return *this; 351 } 352 _Self& operator*= (value_type __x) { 353 _M_re *= __x; 354 _M_im *= __x; 355 return *this; 356 } 357 _Self& operator/= (value_type __x) { 358 _M_re /= __x; 359 _M_im /= __x; 360 return *this; 361 } 362 363 // Arithmetic op= operations involving two complex arguments. 364 365 static void _STLP_CALL _div(const double& __z1_r, const double& __z1_i, 366 const double& __z2_r, const double& __z2_i, 367 double& __res_r, double& __res_i); 368 static void _STLP_CALL _div(const double& __z1_r, 369 const double& __z2_r, const double& __z2_i, 370 double& __res_r, double& __res_i); 371 372#if defined (_STLP_MEMBER_TEMPLATES) && defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) 373 template <class _Tp2> 374 complex<double>& operator=(const complex<_Tp2>& __z) { 375 _M_re = __z._M_re; 376 _M_im = __z._M_im; 377 return *this; 378 } 379 380 template <class _Tp2> 381 complex<double>& operator+= (const complex<_Tp2>& __z) { 382 _M_re += __z._M_re; 383 _M_im += __z._M_im; 384 return *this; 385 } 386 387 template <class _Tp2> 388 complex<double>& operator-= (const complex<_Tp2>& __z) { 389 _M_re -= __z._M_re; 390 _M_im -= __z._M_im; 391 return *this; 392 } 393 394 template <class _Tp2> 395 complex<double>& operator*= (const complex<_Tp2>& __z) { 396 double __r = _M_re * __z._M_re - _M_im * __z._M_im; 397 double __i = _M_re * __z._M_im + _M_im * __z._M_re; 398 _M_re = __r; 399 _M_im = __i; 400 return *this; 401 } 402 403 template <class _Tp2> 404 complex<double>& operator/= (const complex<_Tp2>& __z) { 405 double __r; 406 double __i; 407 _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i); 408 _M_re = __r; 409 _M_im = __i; 410 return *this; 411 } 412 413#endif /* _STLP_MEMBER_TEMPLATES */ 414 415 _Self& operator=(const _Self& __z) { 416 _M_re = __z._M_re; 417 _M_im = __z._M_im; 418 return *this; 419 } 420 421 _Self& operator+= (const _Self& __z) { 422 _M_re += __z._M_re; 423 _M_im += __z._M_im; 424 return *this; 425 } 426 427 _Self& operator-= (const _Self& __z) { 428 _M_re -= __z._M_re; 429 _M_im -= __z._M_im; 430 return *this; 431 } 432 433 _Self& operator*= (const _Self& __z) { 434 value_type __r = _M_re * __z._M_re - _M_im * __z._M_im; 435 value_type __i = _M_re * __z._M_im + _M_im * __z._M_re; 436 _M_re = __r; 437 _M_im = __i; 438 return *this; 439 } 440 441 _Self& operator/= (const _Self& __z) { 442 value_type __r; 443 value_type __i; 444 _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i); 445 _M_re = __r; 446 _M_im = __i; 447 return *this; 448 } 449 450 // Data members. 451 value_type _M_re; 452 value_type _M_im; 453}; 454 455#if !defined (_STLP_NO_LONG_DOUBLE) 456 457_STLP_TEMPLATE_NULL 458struct _STLP_CLASS_DECLSPEC complex<long double> { 459 typedef long double value_type; 460 typedef complex<long double> _Self; 461 462 // Constructors, destructor, assignment operator. 463 complex(value_type __x = 0.0l, value_type __y = 0.0l) 464 : _M_re(__x), _M_im(__y) {} 465 466 complex(const complex<long double>& __z) 467 : _M_re(__z._M_re), _M_im(__z._M_im) {} 468 inline complex(const complex<float>& __z); 469 inline complex(const complex<double>& __z); 470 471 // Element access. 472 value_type real() const { return _M_re; } 473 value_type imag() const { return _M_im; } 474 475 // Arithmetic op= operations involving one real argument. 476 477 _Self& operator= (value_type __x) { 478 _M_re = __x; 479 _M_im = 0.0l; 480 return *this; 481 } 482 _Self& operator+= (value_type __x) { 483 _M_re += __x; 484 return *this; 485 } 486 _Self& operator-= (value_type __x) { 487 _M_re -= __x; 488 return *this; 489 } 490 _Self& operator*= (value_type __x) { 491 _M_re *= __x; 492 _M_im *= __x; 493 return *this; 494 } 495 _Self& operator/= (value_type __x) { 496 _M_re /= __x; 497 _M_im /= __x; 498 return *this; 499 } 500 501 // Arithmetic op= operations involving two complex arguments. 502 503 static void _STLP_CALL _div(const long double& __z1_r, const long double& __z1_i, 504 const long double& __z2_r, const long double& __z2_i, 505 long double& __res_r, long double& __res_i); 506 507 static void _STLP_CALL _div(const long double& __z1_r, 508 const long double& __z2_r, const long double& __z2_i, 509 long double& __res_r, long double& __res_i); 510 511# if defined (_STLP_MEMBER_TEMPLATES) && defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) 512 513 template <class _Tp2> 514 complex<long double>& operator=(const complex<_Tp2>& __z) { 515 _M_re = __z._M_re; 516 _M_im = __z._M_im; 517 return *this; 518 } 519 520 template <class _Tp2> 521 complex<long double>& operator+= (const complex<_Tp2>& __z) { 522 _M_re += __z._M_re; 523 _M_im += __z._M_im; 524 return *this; 525 } 526 527 template <class _Tp2> 528 complex<long double>& operator-= (const complex<_Tp2>& __z) { 529 _M_re -= __z._M_re; 530 _M_im -= __z._M_im; 531 return *this; 532 } 533 534 template <class _Tp2> 535 complex<long double>& operator*= (const complex<_Tp2>& __z) { 536 long double __r = _M_re * __z._M_re - _M_im * __z._M_im; 537 long double __i = _M_re * __z._M_im + _M_im * __z._M_re; 538 _M_re = __r; 539 _M_im = __i; 540 return *this; 541 } 542 543 template <class _Tp2> 544 complex<long double>& operator/= (const complex<_Tp2>& __z) { 545 long double __r; 546 long double __i; 547 _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i); 548 _M_re = __r; 549 _M_im = __i; 550 return *this; 551 } 552 553# endif /* _STLP_MEMBER_TEMPLATES */ 554 555 _Self& operator=(const _Self& __z) { 556 _M_re = __z._M_re; 557 _M_im = __z._M_im; 558 return *this; 559 } 560 561 _Self& operator+= (const _Self& __z) { 562 _M_re += __z._M_re; 563 _M_im += __z._M_im; 564 return *this; 565 } 566 567 _Self& operator-= (const _Self& __z) { 568 _M_re -= __z._M_re; 569 _M_im -= __z._M_im; 570 return *this; 571 } 572 573 _Self& operator*= (const _Self& __z) { 574 value_type __r = _M_re * __z._M_re - _M_im * __z._M_im; 575 value_type __i = _M_re * __z._M_im + _M_im * __z._M_re; 576 _M_re = __r; 577 _M_im = __i; 578 return *this; 579 } 580 581 _Self& operator/= (const _Self& __z) { 582 value_type __r; 583 value_type __i; 584 _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i); 585 _M_re = __r; 586 _M_im = __i; 587 return *this; 588 } 589 590 // Data members. 591 value_type _M_re; 592 value_type _M_im; 593}; 594 595#endif /* _STLP_NO_LONG_DOUBLE */ 596 597// Converting constructors from one of these three specialized types 598// to another. 599 600inline complex<float>::complex(const complex<double>& __z) 601 : _M_re((float)__z._M_re), _M_im((float)__z._M_im) {} 602inline complex<double>::complex(const complex<float>& __z) 603 : _M_re(__z._M_re), _M_im(__z._M_im) {} 604#ifndef _STLP_NO_LONG_DOUBLE 605inline complex<float>::complex(const complex<long double>& __z) 606 : _M_re((float)__z._M_re), _M_im((float)__z._M_im) {} 607inline complex<double>::complex(const complex<long double>& __z) 608 : _M_re((double)__z._M_re), _M_im((double)__z._M_im) {} 609inline complex<long double>::complex(const complex<float>& __z) 610 : _M_re(__z._M_re), _M_im(__z._M_im) {} 611inline complex<long double>::complex(const complex<double>& __z) 612 : _M_re(__z._M_re), _M_im(__z._M_im) {} 613#endif 614 615// Unary non-member arithmetic operators. 616 617template <class _Tp> 618inline complex<_Tp> _STLP_CALL operator+(const complex<_Tp>& __z) 619{ return __z; } 620 621template <class _Tp> 622inline complex<_Tp> _STLP_CALL operator-(const complex<_Tp>& __z) 623{ return complex<_Tp>(-__z._M_re, -__z._M_im); } 624 625// Non-member arithmetic operations involving one real argument. 626 627template <class _Tp> 628inline complex<_Tp> _STLP_CALL operator+(const _Tp& __x, const complex<_Tp>& __z) 629{ return complex<_Tp>(__x + __z._M_re, __z._M_im); } 630 631template <class _Tp> 632inline complex<_Tp> _STLP_CALL operator+(const complex<_Tp>& __z, const _Tp& __x) 633{ return complex<_Tp>(__z._M_re + __x, __z._M_im); } 634 635template <class _Tp> 636inline complex<_Tp> _STLP_CALL operator-(const _Tp& __x, const complex<_Tp>& __z) 637{ return complex<_Tp>(__x - __z._M_re, -__z._M_im); } 638 639template <class _Tp> 640inline complex<_Tp> _STLP_CALL operator-(const complex<_Tp>& __z, const _Tp& __x) 641{ return complex<_Tp>(__z._M_re - __x, __z._M_im); } 642 643template <class _Tp> 644inline complex<_Tp> _STLP_CALL operator*(const _Tp& __x, const complex<_Tp>& __z) 645{ return complex<_Tp>(__x * __z._M_re, __x * __z._M_im); } 646 647template <class _Tp> 648inline complex<_Tp> _STLP_CALL operator*(const complex<_Tp>& __z, const _Tp& __x) 649{ return complex<_Tp>(__z._M_re * __x, __z._M_im * __x); } 650 651template <class _Tp> 652inline complex<_Tp> _STLP_CALL operator/(const _Tp& __x, const complex<_Tp>& __z) { 653 complex<_Tp> __result; 654 complex<_Tp>::_div(__x, 655 __z._M_re, __z._M_im, 656 __result._M_re, __result._M_im); 657 return __result; 658} 659 660template <class _Tp> 661inline complex<_Tp> _STLP_CALL operator/(const complex<_Tp>& __z, const _Tp& __x) 662{ return complex<_Tp>(__z._M_re / __x, __z._M_im / __x); } 663 664// Non-member arithmetic operations involving two complex arguments 665 666template <class _Tp> 667inline complex<_Tp> _STLP_CALL 668operator+(const complex<_Tp>& __z1, const complex<_Tp>& __z2) 669{ return complex<_Tp>(__z1._M_re + __z2._M_re, __z1._M_im + __z2._M_im); } 670 671template <class _Tp> 672inline complex<_Tp> _STLP_CALL 673operator-(const complex<_Tp>& __z1, const complex<_Tp>& __z2) 674{ return complex<_Tp>(__z1._M_re - __z2._M_re, __z1._M_im - __z2._M_im); } 675 676template <class _Tp> 677inline complex<_Tp> _STLP_CALL 678operator*(const complex<_Tp>& __z1, const complex<_Tp>& __z2) { 679 return complex<_Tp>(__z1._M_re * __z2._M_re - __z1._M_im * __z2._M_im, 680 __z1._M_re * __z2._M_im + __z1._M_im * __z2._M_re); 681} 682 683template <class _Tp> 684inline complex<_Tp> _STLP_CALL 685operator/(const complex<_Tp>& __z1, const complex<_Tp>& __z2) { 686 complex<_Tp> __result; 687 complex<_Tp>::_div(__z1._M_re, __z1._M_im, 688 __z2._M_re, __z2._M_im, 689 __result._M_re, __result._M_im); 690 return __result; 691} 692 693// Comparison operators. 694 695template <class _Tp> 696inline bool _STLP_CALL operator==(const complex<_Tp>& __z1, const complex<_Tp>& __z2) 697{ return __z1._M_re == __z2._M_re && __z1._M_im == __z2._M_im; } 698 699template <class _Tp> 700inline bool _STLP_CALL operator==(const complex<_Tp>& __z, const _Tp& __x) 701{ return __z._M_re == __x && __z._M_im == 0; } 702 703template <class _Tp> 704inline bool _STLP_CALL operator==(const _Tp& __x, const complex<_Tp>& __z) 705{ return __x == __z._M_re && 0 == __z._M_im; } 706 707//04/27/04 dums: removal of this check, if it is restablish 708//please explain why the other operators are not macro guarded 709//#ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER 710 711template <class _Tp> 712inline bool _STLP_CALL operator!=(const complex<_Tp>& __z1, const complex<_Tp>& __z2) 713{ return __z1._M_re != __z2._M_re || __z1._M_im != __z2._M_im; } 714 715//#endif /* _STLP_FUNCTION_TMPL_PARTIAL_ORDER */ 716 717template <class _Tp> 718inline bool _STLP_CALL operator!=(const complex<_Tp>& __z, const _Tp& __x) 719{ return __z._M_re != __x || __z._M_im != 0; } 720 721template <class _Tp> 722inline bool _STLP_CALL operator!=(const _Tp& __x, const complex<_Tp>& __z) 723{ return __x != __z._M_re || 0 != __z._M_im; } 724 725// Other basic arithmetic operations 726template <class _Tp> 727inline _Tp _STLP_CALL real(const complex<_Tp>& __z) 728{ return __z._M_re; } 729 730template <class _Tp> 731inline _Tp _STLP_CALL imag(const complex<_Tp>& __z) 732{ return __z._M_im; } 733 734template <class _Tp> 735_Tp _STLP_CALL abs(const complex<_Tp>& __z); 736 737template <class _Tp> 738_Tp _STLP_CALL arg(const complex<_Tp>& __z); 739 740template <class _Tp> 741inline _Tp _STLP_CALL norm(const complex<_Tp>& __z) 742{ return __z._M_re * __z._M_re + __z._M_im * __z._M_im; } 743 744template <class _Tp> 745inline complex<_Tp> _STLP_CALL conj(const complex<_Tp>& __z) 746{ return complex<_Tp>(__z._M_re, -__z._M_im); } 747 748template <class _Tp> 749complex<_Tp> _STLP_CALL polar(const _Tp& __rho) 750{ return complex<_Tp>(__rho, 0); } 751 752template <class _Tp> 753complex<_Tp> _STLP_CALL polar(const _Tp& __rho, const _Tp& __phi); 754 755_STLP_TEMPLATE_NULL 756_STLP_DECLSPEC float _STLP_CALL abs(const complex<float>&); 757_STLP_TEMPLATE_NULL 758_STLP_DECLSPEC double _STLP_CALL abs(const complex<double>&); 759_STLP_TEMPLATE_NULL 760_STLP_DECLSPEC float _STLP_CALL arg(const complex<float>&); 761_STLP_TEMPLATE_NULL 762_STLP_DECLSPEC double _STLP_CALL arg(const complex<double>&); 763_STLP_TEMPLATE_NULL 764_STLP_DECLSPEC complex<float> _STLP_CALL polar(const float& __rho, const float& __phi); 765_STLP_TEMPLATE_NULL 766_STLP_DECLSPEC complex<double> _STLP_CALL polar(const double& __rho, const double& __phi); 767 768template <class _Tp> 769_Tp _STLP_CALL abs(const complex<_Tp>& __z) 770{ return _Tp(abs(complex<double>(double(__z.real()), double(__z.imag())))); } 771 772template <class _Tp> 773_Tp _STLP_CALL arg(const complex<_Tp>& __z) 774{ return _Tp(arg(complex<double>(double(__z.real()), double(__z.imag())))); } 775 776template <class _Tp> 777complex<_Tp> _STLP_CALL polar(const _Tp& __rho, const _Tp& __phi) { 778 complex<double> __tmp = polar(double(__rho), double(__phi)); 779 return complex<_Tp>(_Tp(__tmp.real()), _Tp(__tmp.imag())); 780} 781 782#if !defined (_STLP_NO_LONG_DOUBLE) 783_STLP_TEMPLATE_NULL 784_STLP_DECLSPEC long double _STLP_CALL arg(const complex<long double>&); 785_STLP_TEMPLATE_NULL 786_STLP_DECLSPEC long double _STLP_CALL abs(const complex<long double>&); 787_STLP_TEMPLATE_NULL 788_STLP_DECLSPEC complex<long double> _STLP_CALL polar(const long double&, const long double&); 789#endif 790 791 792#if !defined (_STLP_USE_NO_IOSTREAMS) 793 794_STLP_END_NAMESPACE 795 796# ifndef _STLP_INTERNAL_IOSFWD 797# include <stl/_iosfwd.h> 798# endif 799 800_STLP_BEGIN_NAMESPACE 801 802// Complex output, in the form (re,im). We use a two-step process 803// involving stringstream so that we get the padding right. 804template <class _Tp, class _CharT, class _Traits> 805basic_ostream<_CharT, _Traits>& _STLP_CALL 806operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __z); 807 808template <class _Tp, class _CharT, class _Traits> 809basic_istream<_CharT, _Traits>& _STLP_CALL 810operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __z); 811 812// Specializations for narrow characters; lets us avoid widen. 813 814_STLP_OPERATOR_TEMPLATE 815_STLP_DECLSPEC basic_istream<char, char_traits<char> >& _STLP_CALL 816operator>>(basic_istream<char, char_traits<char> >& __is, complex<float>& __z); 817 818_STLP_OPERATOR_TEMPLATE 819_STLP_DECLSPEC basic_istream<char, char_traits<char> >& _STLP_CALL 820operator>>(basic_istream<char, char_traits<char> >& __is, complex<double>& __z); 821 822_STLP_OPERATOR_TEMPLATE 823_STLP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL 824operator<<(basic_ostream<char, char_traits<char> >& __is, const complex<float>& __z); 825 826_STLP_OPERATOR_TEMPLATE 827_STLP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL 828operator<<(basic_ostream<char, char_traits<char> >& __is, const complex<double>& __z); 829 830# if !defined (_STLP_NO_LONG_DOUBLE) 831_STLP_OPERATOR_TEMPLATE 832_STLP_DECLSPEC basic_istream<char, char_traits<char> >& _STLP_CALL 833operator>>(basic_istream<char, char_traits<char> >& __is, complex<long double>& __z); 834 835_STLP_OPERATOR_TEMPLATE 836_STLP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL 837operator<<(basic_ostream<char, char_traits<char> >& __is, const complex<long double>& __z); 838 839# endif 840 841# if defined (_STLP_USE_TEMPLATE_EXPORT) && ! defined (_STLP_NO_WCHAR_T) 842 843_STLP_EXPORT_TEMPLATE basic_istream<wchar_t, char_traits<wchar_t> >& _STLP_CALL 844operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, complex<double>&); 845_STLP_EXPORT_TEMPLATE basic_ostream<wchar_t, char_traits<wchar_t> >& _STLP_CALL 846operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<double>&); 847_STLP_EXPORT_TEMPLATE basic_istream<wchar_t, char_traits<wchar_t> >& _STLP_CALL 848operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, complex<float>&); 849_STLP_EXPORT_TEMPLATE basic_ostream<wchar_t, char_traits<wchar_t> >& _STLP_CALL 850operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<float>&); 851 852# if !defined (_STLP_NO_LONG_DOUBLE) 853_STLP_EXPORT_TEMPLATE basic_istream<wchar_t, char_traits<wchar_t> >& _STLP_CALL 854operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, complex<long double>&); 855_STLP_EXPORT_TEMPLATE basic_ostream<wchar_t, char_traits<wchar_t> >& _STLP_CALL 856operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<long double>&); 857# endif 858# endif 859#endif 860 861 862// Transcendental functions. These are defined only for float, 863// double, and long double. (Sqrt isn't transcendental, of course, 864// but it's included in this section anyway.) 865 866_STLP_DECLSPEC complex<float> _STLP_CALL sqrt(const complex<float>&); 867 868_STLP_DECLSPEC complex<float> _STLP_CALL exp(const complex<float>&); 869_STLP_DECLSPEC complex<float> _STLP_CALL log(const complex<float>&); 870_STLP_DECLSPEC complex<float> _STLP_CALL log10(const complex<float>&); 871 872_STLP_DECLSPEC complex<float> _STLP_CALL pow(const complex<float>&, int); 873_STLP_DECLSPEC complex<float> _STLP_CALL pow(const complex<float>&, const float&); 874_STLP_DECLSPEC complex<float> _STLP_CALL pow(const float&, const complex<float>&); 875_STLP_DECLSPEC complex<float> _STLP_CALL pow(const complex<float>&, const complex<float>&); 876 877_STLP_DECLSPEC complex<float> _STLP_CALL sin(const complex<float>&); 878_STLP_DECLSPEC complex<float> _STLP_CALL cos(const complex<float>&); 879_STLP_DECLSPEC complex<float> _STLP_CALL tan(const complex<float>&); 880 881_STLP_DECLSPEC complex<float> _STLP_CALL sinh(const complex<float>&); 882_STLP_DECLSPEC complex<float> _STLP_CALL cosh(const complex<float>&); 883_STLP_DECLSPEC complex<float> _STLP_CALL tanh(const complex<float>&); 884 885_STLP_DECLSPEC complex<double> _STLP_CALL sqrt(const complex<double>&); 886 887_STLP_DECLSPEC complex<double> _STLP_CALL exp(const complex<double>&); 888_STLP_DECLSPEC complex<double> _STLP_CALL log(const complex<double>&); 889_STLP_DECLSPEC complex<double> _STLP_CALL log10(const complex<double>&); 890 891_STLP_DECLSPEC complex<double> _STLP_CALL pow(const complex<double>&, int); 892_STLP_DECLSPEC complex<double> _STLP_CALL pow(const complex<double>&, const double&); 893_STLP_DECLSPEC complex<double> _STLP_CALL pow(const double&, const complex<double>&); 894_STLP_DECLSPEC complex<double> _STLP_CALL pow(const complex<double>&, const complex<double>&); 895 896_STLP_DECLSPEC complex<double> _STLP_CALL sin(const complex<double>&); 897_STLP_DECLSPEC complex<double> _STLP_CALL cos(const complex<double>&); 898_STLP_DECLSPEC complex<double> _STLP_CALL tan(const complex<double>&); 899 900_STLP_DECLSPEC complex<double> _STLP_CALL sinh(const complex<double>&); 901_STLP_DECLSPEC complex<double> _STLP_CALL cosh(const complex<double>&); 902_STLP_DECLSPEC complex<double> _STLP_CALL tanh(const complex<double>&); 903 904#if !defined (_STLP_NO_LONG_DOUBLE) 905_STLP_DECLSPEC complex<long double> _STLP_CALL sqrt(const complex<long double>&); 906_STLP_DECLSPEC complex<long double> _STLP_CALL exp(const complex<long double>&); 907_STLP_DECLSPEC complex<long double> _STLP_CALL log(const complex<long double>&); 908_STLP_DECLSPEC complex<long double> _STLP_CALL log10(const complex<long double>&); 909 910_STLP_DECLSPEC complex<long double> _STLP_CALL pow(const complex<long double>&, int); 911_STLP_DECLSPEC complex<long double> _STLP_CALL pow(const complex<long double>&, const long double&); 912_STLP_DECLSPEC complex<long double> _STLP_CALL pow(const long double&, const complex<long double>&); 913_STLP_DECLSPEC complex<long double> _STLP_CALL pow(const complex<long double>&, 914 const complex<long double>&); 915 916_STLP_DECLSPEC complex<long double> _STLP_CALL sin(const complex<long double>&); 917_STLP_DECLSPEC complex<long double> _STLP_CALL cos(const complex<long double>&); 918_STLP_DECLSPEC complex<long double> _STLP_CALL tan(const complex<long double>&); 919 920_STLP_DECLSPEC complex<long double> _STLP_CALL sinh(const complex<long double>&); 921_STLP_DECLSPEC complex<long double> _STLP_CALL cosh(const complex<long double>&); 922_STLP_DECLSPEC complex<long double> _STLP_CALL tanh(const complex<long double>&); 923#endif 924 925_STLP_END_NAMESPACE 926 927#ifndef _STLP_LINK_TIME_INSTANTIATION 928# include <stl/_complex.c> 929#endif 930 931#endif 932 933// Local Variables: 934// mode:C++ 935// End: 936