home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / complex.cc < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  3.5 KB  |  123 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.  * Copyright (c) 1994-1999 Rogue Wave Software, Inc.  All Rights Reserved.
  12.  *
  13.  * This computer software is owned by Rogue Wave Software, Inc. and is
  14.  * protected by U.S. copyright laws and other laws and by international
  15.  * treaties.  This computer software is furnished by Rogue Wave Software,
  16.  * Inc. pursuant to a written license agreement and may be used, copied,
  17.  * transmitted, and stored only in accordance with the terms of such
  18.  * license and with the inclusion of the above copyright notice.  This
  19.  * computer software or any other copies thereof may not be provided or
  20.  * otherwise made available to any other person.
  21.  *
  22.  * U.S. Government Restricted Rights.  This computer software is provided
  23.  * with Restricted Rights.  Use, duplication, or disclosure by the
  24.  * Government is subject to restrictions as set forth in subparagraph (c)
  25.  * (1) (ii) of The Rights in Technical Data and Computer Software clause
  26.  * at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the
  27.  * Commercial Computer Software รป Restricted Rights at 48 CFR 52.227-19,
  28.  * as applicable.  Manufacturer is Rogue Wave Software, Inc., 5500
  29.  * Flatiron Parkway, Boulder, Colorado 80301 USA.
  30.  *
  31.  **************************************************************************/
  32.  
  33. #include <stdcomp.h>
  34.  
  35. #ifdef _RW_STD_IOSTREAM
  36.   #include <sstream>
  37. #endif
  38.  
  39. #ifndef _RWSTD_NO_NAMESPACE 
  40. namespace std {
  41. #endif
  42.  
  43.   template <class T>
  44.   complex<T> log10 (const complex<T>& a)
  45.   {
  46. #ifndef _RWSTD_MULTI_THREAD
  47.     static 
  48. #endif
  49.     const T log10e = _RWSTD_C_SCOPE_LOG10(_RWSTD_C_SCOPE_EXP(T(1)));
  50.     return log10e * log(a);
  51.   }
  52.  
  53. #ifdef _RW_STD_IOSTREAM
  54.   template <class T,class charT, class traits>
  55.   basic_istream<charT, traits >&  
  56.   _RWSTDExportTemplate operator>> (basic_istream<charT, traits >& is,complex<T>& x)
  57. #else
  58.   template <class T>
  59.   istream& _RWSTDExportTemplate operator>> (istream& is, complex<T>& x)
  60. #endif
  61.   {
  62.     //
  63.     // operator >> reads a complex number x in the form
  64.     // u
  65.     // (u)
  66.     // (u, v)
  67.     //
  68.     T u = 0, v = 0;
  69.     char c;
  70.  
  71.     is >> c;
  72.     if (c == '(')
  73.     {
  74.       is >> u >> c;
  75.       if (c == ',') { is >> v  >> c;}
  76.       if (c != ')' )
  77.       {
  78. #ifdef _RW_STD_IOSTREAM
  79.         is.setstate(ios::failbit);
  80. #else
  81.         is.clear(ios::failbit);
  82. #endif
  83.       }
  84.     } 
  85.     else
  86.     {
  87.       is.putback(c);
  88.       is >> u;
  89.     }
  90.  
  91.     if (is)
  92.       x = complex<T>(u,v);
  93.  
  94.     return is;
  95.   }
  96.  
  97. #ifdef _RW_STD_IOSTREAM
  98.   #include <sstream>
  99.   template <class T,class charT,class traits>
  100.   basic_ostream<charT,traits >& _RWSTDExportTemplate operator<< (basic_ostream<charT, traits >& os,const complex<T>& x)
  101.   {
  102.     basic_ostringstream<charT, traits, allocator<charT> > s;
  103.     s.flags(os.flags());
  104.     s.imbue(os.getloc());
  105.     s.precision(os.precision());
  106.     s << '(' << x.real() << "," << x.imag() << ')';
  107.     return os << s.str();
  108.   }
  109. #else
  110.   template <class T>
  111.   ostream& _RWSTDExportTemplate operator<< (ostream& os, const complex<T>& x)
  112.   {
  113.     os << '(' << x.real() << "," << x.imag() << ')';
  114.     return os;
  115.   }
  116. #endif
  117. #ifndef _RWSTD_NO_NAMESPACE
  118. }
  119. #endif
  120.  
  121. #pragma option pop
  122. #endif /* __COMPLEX_CC */
  123.