epoc32/include/tools/stlport/stl/_complex.c
branchSymbian3
changeset 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/tools/stlport/stl/_complex.c	Wed Mar 31 12:33:34 2010 +0100
     1.3 @@ -0,0 +1,148 @@
     1.4 +/*
     1.5 + * Copyright (c) 1999
     1.6 + * Silicon Graphics Computer Systems, Inc.
     1.7 + *
     1.8 + * Copyright (c) 1999
     1.9 + * Boris Fomitchev
    1.10 + *
    1.11 + * This material is provided "as is", with absolutely no warranty expressed
    1.12 + * or implied. Any use is at your own risk.
    1.13 + *
    1.14 + * Permission to use or copy this software for any purpose is hereby granted
    1.15 + * without fee, provided the above notices are retained on all copies.
    1.16 + * Permission to modify the code and to distribute modified code is granted,
    1.17 + * provided the above notices are retained, and a notice that the code was
    1.18 + * modified is included with the above copyright notice.
    1.19 + *
    1.20 + */
    1.21 +#ifndef _STLP_COMPLEX_C
    1.22 +#define _STLP_COMPLEX_C
    1.23 +
    1.24 +#ifndef _STLP_INTERNAL_COMPLEX
    1.25 +#  include <stl/_complex.h>
    1.26 +#endif
    1.27 +
    1.28 +#if !defined (_STLP_USE_NO_IOSTREAMS)
    1.29 +#  ifndef _STLP_INTERNAL_ISTREAM
    1.30 +#    include <stl/_istream.h>
    1.31 +#  endif
    1.32 +
    1.33 +#  ifndef _STLP_INTERNAL_SSTREAM
    1.34 +#    include <stl/_sstream.h>
    1.35 +#  endif
    1.36 +
    1.37 +#  ifndef _STLP_STRING_IO_H
    1.38 +#    include <stl/_string_io.h>
    1.39 +#  endif
    1.40 +#endif
    1.41 +
    1.42 +_STLP_BEGIN_NAMESPACE
    1.43 +
    1.44 +// Non-inline member functions.
    1.45 +
    1.46 +template <class _Tp>
    1.47 +void complex<_Tp>::_div(const _Tp& __z1_r, const _Tp& __z1_i,
    1.48 +                        const _Tp& __z2_r, const _Tp& __z2_i,
    1.49 +                        _Tp& __res_r, _Tp& __res_i) {
    1.50 +  _Tp __ar = __z2_r >= 0 ? __z2_r : -__z2_r;
    1.51 +  _Tp __ai = __z2_i >= 0 ? __z2_i : -__z2_i;
    1.52 +
    1.53 +  if (__ar <= __ai) {
    1.54 +    _Tp __ratio = __z2_r / __z2_i;
    1.55 +    _Tp __denom = __z2_i * (1 + __ratio * __ratio);
    1.56 +    __res_r = (__z1_r * __ratio + __z1_i) / __denom;
    1.57 +    __res_i = (__z1_i * __ratio - __z1_r) / __denom;
    1.58 +  }
    1.59 +  else {
    1.60 +    _Tp __ratio = __z2_i / __z2_r;
    1.61 +    _Tp __denom = __z2_r * (1 + __ratio * __ratio);
    1.62 +    __res_r = (__z1_r + __z1_i * __ratio) / __denom;
    1.63 +    __res_i = (__z1_i - __z1_r * __ratio) / __denom;
    1.64 +  }
    1.65 +}
    1.66 +
    1.67 +template <class _Tp>
    1.68 +void complex<_Tp>::_div(const _Tp& __z1_r,
    1.69 +                        const _Tp& __z2_r, const _Tp& __z2_i,
    1.70 +                        _Tp& __res_r, _Tp& __res_i) {
    1.71 +  _Tp __ar = __z2_r >= 0 ? __z2_r : -__z2_r;
    1.72 +  _Tp __ai = __z2_i >= 0 ? __z2_i : -__z2_i;
    1.73 +
    1.74 +  if (__ar <= __ai) {
    1.75 +    _Tp __ratio = __z2_r / __z2_i;
    1.76 +    _Tp __denom = __z2_i * (1 + __ratio * __ratio);
    1.77 +    __res_r = (__z1_r * __ratio) / __denom;
    1.78 +    __res_i = - __z1_r / __denom;
    1.79 +  }
    1.80 +  else {
    1.81 +    _Tp __ratio = __z2_i / __z2_r;
    1.82 +    _Tp __denom = __z2_r * (1 + __ratio * __ratio);
    1.83 +    __res_r = __z1_r / __denom;
    1.84 +    __res_i = - (__z1_r * __ratio) / __denom;
    1.85 +  }
    1.86 +}
    1.87 +
    1.88 +// I/O.
    1.89 +#if !defined (_STLP_USE_NO_IOSTREAMS)
    1.90 +
    1.91 +// Complex output, in the form (re,im).  We use a two-step process
    1.92 +// involving stringstream so that we get the padding right.
    1.93 +template <class _Tp, class _CharT, class _Traits>
    1.94 +basic_ostream<_CharT, _Traits>& _STLP_CALL
    1.95 +operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __z) {
    1.96 +  basic_ostringstream<_CharT, _Traits, allocator<_CharT> > __tmp;
    1.97 +  __tmp.flags(__os.flags());
    1.98 +  __tmp.imbue(__os.getloc());
    1.99 +  __tmp.precision(__os.precision());
   1.100 +  __tmp << '(' << __z.real() << ',' << __z.imag() << ')';
   1.101 +  return __os << __tmp.str();
   1.102 +}
   1.103 +
   1.104 +// Complex input from arbitrary streams.  Note that results in some
   1.105 +// locales may be confusing, since the decimal character varies with
   1.106 +// locale and the separator between real and imaginary parts does not.
   1.107 +
   1.108 +template <class _Tp, class _CharT, class _Traits>
   1.109 +basic_istream<_CharT, _Traits>& _STLP_CALL
   1.110 +operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __z) {
   1.111 +  _Tp  __re = 0;
   1.112 +  _Tp  __im = 0;
   1.113 +
   1.114 +  // typedef ctype<_CharT> _Ctype;
   1.115 +  //  locale __loc = __is.getloc();
   1.116 +  //const _Ctype&  __c_type  = use_facet<_Ctype>(__loc);
   1.117 +  const ctype<_CharT>& __c_type = *__STATIC_CAST(const ctype<_CharT>*, __is._M_ctype_facet());
   1.118 +
   1.119 +  const char __punct[4] = "(,)";
   1.120 +  _CharT __wpunct[3];
   1.121 +  __c_type.widen(__punct, __punct + 3, __wpunct);
   1.122 +
   1.123 +  _CharT __c;
   1.124 +
   1.125 +  __is >> __c;
   1.126 +  if (_Traits::eq(__c, __wpunct[0])) {  // Left paren
   1.127 +    __is >> __re >> __c;
   1.128 +    if (_Traits::eq(__c, __wpunct[1]))  // Comma
   1.129 +      __is >> __im >> __c;
   1.130 +    if (!_Traits::eq(__c, __wpunct[2])) // Right paren
   1.131 +      __is.setstate(ios_base::failbit);
   1.132 +  }
   1.133 +  else {
   1.134 +    __is.putback(__c);
   1.135 +    __is >> __re;
   1.136 +  }
   1.137 +
   1.138 +  if (__is)
   1.139 +    __z = complex<_Tp>(__re, __im);
   1.140 +  return __is;
   1.141 +}
   1.142 +
   1.143 +#endif /* _STLP_USE_NO_IOSTREAMS */
   1.144 +
   1.145 +_STLP_END_NAMESPACE
   1.146 +
   1.147 +#endif /* _STLP_COMPLEX_C */
   1.148 +
   1.149 +// Local Variables:
   1.150 +// mode:C++
   1.151 +// End: