ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

_complex.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1999
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Copyright (c) 1999
00006  * Boris Fomitchev
00007  *
00008  * This material is provided "as is", with absolutely no warranty expressed
00009  * or implied. Any use is at your own risk.
00010  *
00011  * Permission to use or copy this software for any purpose is hereby granted
00012  * without fee, provided the above notices are retained on all copies.
00013  * Permission to modify the code and to distribute modified code is granted,
00014  * provided the above notices are retained, and a notice that the code was
00015  * modified is included with the above copyright notice.
00016  *
00017  */
00018 #ifndef _STLP_COMPLEX_C
00019 #define _STLP_COMPLEX_C
00020 
00021 #ifndef _STLP_INTERNAL_COMPLEX
00022 #  include <stl/_complex.h>
00023 #endif
00024 
00025 #if !defined (_STLP_USE_NO_IOSTREAMS)
00026 #  ifndef _STLP_INTERNAL_ISTREAM
00027 #    include <stl/_istream.h>
00028 #  endif
00029 
00030 #  ifndef _STLP_INTERNAL_SSTREAM
00031 #    include <stl/_sstream.h>
00032 #  endif
00033 
00034 #  ifndef _STLP_STRING_IO_H
00035 #    include <stl/_string_io.h>
00036 #  endif
00037 #endif
00038 
00039 _STLP_BEGIN_NAMESPACE
00040 
00041 // Non-inline member functions.
00042 
00043 template <class _Tp>
00044 void complex<_Tp>::_div(const _Tp& __z1_r, const _Tp& __z1_i,
00045                         const _Tp& __z2_r, const _Tp& __z2_i,
00046                         _Tp& __res_r, _Tp& __res_i) {
00047   _Tp __ar = __z2_r >= 0 ? __z2_r : -__z2_r;
00048   _Tp __ai = __z2_i >= 0 ? __z2_i : -__z2_i;
00049 
00050   if (__ar <= __ai) {
00051     _Tp __ratio = __z2_r / __z2_i;
00052     _Tp __denom = __z2_i * (1 + __ratio * __ratio);
00053     __res_r = (__z1_r * __ratio + __z1_i) / __denom;
00054     __res_i = (__z1_i * __ratio - __z1_r) / __denom;
00055   }
00056   else {
00057     _Tp __ratio = __z2_i / __z2_r;
00058     _Tp __denom = __z2_r * (1 + __ratio * __ratio);
00059     __res_r = (__z1_r + __z1_i * __ratio) / __denom;
00060     __res_i = (__z1_i - __z1_r * __ratio) / __denom;
00061   }
00062 }
00063 
00064 template <class _Tp>
00065 void complex<_Tp>::_div(const _Tp& __z1_r,
00066                         const _Tp& __z2_r, const _Tp& __z2_i,
00067                         _Tp& __res_r, _Tp& __res_i) {
00068   _Tp __ar = __z2_r >= 0 ? __z2_r : -__z2_r;
00069   _Tp __ai = __z2_i >= 0 ? __z2_i : -__z2_i;
00070 
00071   if (__ar <= __ai) {
00072     _Tp __ratio = __z2_r / __z2_i;
00073     _Tp __denom = __z2_i * (1 + __ratio * __ratio);
00074     __res_r = (__z1_r * __ratio) / __denom;
00075     __res_i = - __z1_r / __denom;
00076   }
00077   else {
00078     _Tp __ratio = __z2_i / __z2_r;
00079     _Tp __denom = __z2_r * (1 + __ratio * __ratio);
00080     __res_r = __z1_r / __denom;
00081     __res_i = - (__z1_r * __ratio) / __denom;
00082   }
00083 }
00084 
00085 // I/O.
00086 #if !defined (_STLP_USE_NO_IOSTREAMS)
00087 
00088 // Complex output, in the form (re,im).  We use a two-step process
00089 // involving stringstream so that we get the padding right.
00090 template <class _Tp, class _CharT, class _Traits>
00091 basic_ostream<_CharT, _Traits>& _STLP_CALL
00092 operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __z) {
00093   basic_ostringstream<_CharT, _Traits, allocator<_CharT> > __tmp;
00094   __tmp.flags(__os.flags());
00095   __tmp.imbue(__os.getloc());
00096   __tmp.precision(__os.precision());
00097   __tmp << '(' << __z.real() << ',' << __z.imag() << ')';
00098   return __os << __tmp.str();
00099 }
00100 
00101 // Complex input from arbitrary streams.  Note that results in some
00102 // locales may be confusing, since the decimal character varies with
00103 // locale and the separator between real and imaginary parts does not.
00104 
00105 template <class _Tp, class _CharT, class _Traits>
00106 basic_istream<_CharT, _Traits>& _STLP_CALL
00107 operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __z) {
00108   _Tp  __re = 0;
00109   _Tp  __im = 0;
00110 
00111   const ctype<_CharT>& __c_type = *__is._M_ctype_facet();
00112 
00113   const char __punct[4] = "(,)";
00114   _CharT __wpunct[3];
00115   __c_type.widen(__punct, __punct + 3, __wpunct);
00116 
00117   _CharT __c;
00118 
00119   __is >> __c;
00120   if (_Traits::eq(__c, __wpunct[0])) {  // Left paren
00121     __is >> __re >> __c;
00122     if (_Traits::eq(__c, __wpunct[1]))  // Comma
00123       __is >> __im >> __c;
00124     if (!_Traits::eq(__c, __wpunct[2])) // Right paren
00125       __is.setstate(ios_base::failbit);
00126   }
00127   else {
00128     __is.putback(__c);
00129     __is >> __re;
00130   }
00131 
00132   if (__is)
00133     __z = complex<_Tp>(__re, __im);
00134   return __is;
00135 }
00136 
00137 #endif /* _STLP_USE_NO_IOSTREAMS */
00138 
00139 _STLP_END_NAMESPACE
00140 
00141 #endif /* _STLP_COMPLEX_C */
00142 
00143 // Local Variables:
00144 // mode:C++
00145 // End:

Generated on Sat May 26 2012 04:27:31 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.