home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 May / PCP163A.iso / Runimage / Cbuilder4 / Include / COMPLEX.CC < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-26  |  4.0 KB  |  132 lines

  1. #ifndef __COMPLEX_CC
  2. #define __COMPLEX_CC
  3. #pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
  4.  
  5. /***************************************************************************
  6.  *
  7.  * complex - Declaration for the Standard Library complex class
  8.  *
  9.  ***************************************************************************
  10.  *
  11.  * (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
  12.  * ALL RIGHTS RESERVED
  13.  *
  14.  * The software and information contained herein are proprietary to, and
  15.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  16.  * intends to preserve as trade secrets such software and information.
  17.  * This software is furnished pursuant to a written license agreement and
  18.  * may be used, copied, transmitted, and stored only in accordance with
  19.  * the terms of such license and with the inclusion of the above copyright
  20.  * notice.  This software and information or any other copies thereof may
  21.  * not be provided or otherwise made available to any other person.
  22.  *
  23.  * Notwithstanding any other lease or license that may pertain to, or
  24.  * accompany the delivery of, this computer software and information, the
  25.  * rights of the Government regarding its use, reproduction and disclosure
  26.  * are as set forth in Section 52.227-19 of the FARS Computer
  27.  * Software-Restricted Rights clause.
  28.  * 
  29.  * Use, duplication, or disclosure by the Government is subject to
  30.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  31.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  32.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  33.  * P.O. Box 2328, Corvallis, Oregon 97339.
  34.  *
  35.  * This computer software and information is distributed with "restricted
  36.  * rights."  Use, duplication or disclosure is subject to restrictions as
  37.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  38.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  39.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  40.  * then the "Alternate III" clause applies.
  41.  *
  42.  **************************************************************************/
  43.  
  44. #include <stdcomp.h>
  45.  
  46. #ifdef _RW_STD_IOSTREAM
  47.   #include <sstream>
  48. #endif
  49.  
  50. #ifndef _RWSTD_NO_NAMESPACE 
  51. namespace std {
  52. #endif
  53.  
  54.   template <class T>
  55.   complex<T> log10 (const complex<T>& a)
  56.   {
  57. #ifndef _RWSTD_MULTI_THREAD
  58.     static 
  59. #endif
  60.     const T log10e = _RWSTD_C_SCOPE_LOG10(_RWSTD_C_SCOPE_EXP(T(1)));
  61.     return log10e * log(a);
  62.   }
  63.  
  64. #ifdef _RW_STD_IOSTREAM
  65.   template <class T,class charT, class traits>
  66.   basic_istream<charT, traits >&  
  67.   _RWSTDExportTemplate operator>> (basic_istream<charT, traits >& is,complex<T>& x)
  68. #else
  69.   template <class T>
  70.   istream& _RWSTDExportTemplate operator>> (istream& is, complex<T>& x)
  71. #endif
  72.   {
  73.     //
  74.     // operator >> reads a complex number x in the form
  75.     // u
  76.     // (u)
  77.     // (u, v)
  78.     //
  79.     T u = 0, v = 0;
  80.     char c;
  81.  
  82.     is >> c;
  83.     if (c == '(')
  84.     {
  85.       is >> u >> c;
  86.       if (c == ',') { is >> v  >> c;}
  87.       if (c != ')' )
  88.       {
  89. #ifdef _RW_STD_IOSTREAM
  90.         is.setstate(ios::failbit);
  91. #else
  92.         is.clear(ios::failbit);
  93. #endif
  94.       }
  95.     } 
  96.     else
  97.     {
  98.       is.putback(c);
  99.       is >> u;
  100.     }
  101.  
  102.     if (is)
  103.       x = complex<T>(u,v);
  104.  
  105.     return is;
  106.   }
  107.  
  108. #ifdef _RW_STD_IOSTREAM
  109.   #include <sstream>
  110.   template <class T,class charT,class traits>
  111.   basic_ostream<charT,traits >& _RWSTDExportTemplate operator<< (basic_ostream<charT, traits >& os,const complex<T>& x)
  112.   {
  113.     basic_ostringstream<charT, traits, allocator<charT> > s;
  114.     s.flags(os.flags());
  115.     s.imbue(os.getloc());
  116.     s.precision(os.precision());
  117.     s << '(' << x.real() << "," << x.imag() << ')';
  118.     return os << s.str();
  119.   }
  120. #else
  121.   template <class T>
  122.   ostream& _RWSTDExportTemplate operator<< (ostream& os, const complex<T>& x)
  123.   {
  124.     os << '(' << x.real() << "," << x.imag() << ')';
  125.   }
  126. #endif
  127. #ifndef _RWSTD_NO_NAMESPACE
  128. }
  129. #endif
  130. #pragma option pop
  131. #endif /* __COMPLEX_CC */
  132.