|
|
|
1 |
|
// complex standard header |
2 |
|
#pragma once |
3 |
|
#ifndef _COMPLEX_ |
4 |
|
#define _COMPLEX_ |
5 |
|
#ifndef RC_INVOKED |
6 |
|
#include <ymath.h> |
7 |
|
#include <ccomplex> /* dummy if not C99 library */ |
8 |
|
#include <cmath> |
9 |
|
#include <sstream> |
10 |
|
|
11 |
|
#ifdef _MSC_VER |
12 |
|
#pragma pack(push,_CRT_PACKING) |
13 |
|
#pragma warning(push,3) |
14 |
|
#pragma warning(disable: 4244) |
15 |
|
#endif /* _MSC_VER */ |
16 |
|
|
17 |
|
_C_STD_BEGIN |
18 |
|
#ifndef _C_COMPLEX_T |
19 |
|
#define _C_COMPLEX_T |
20 |
|
|
21 |
|
typedef struct _C_double_complex |
22 |
|
{ /* double complex */ |
23 |
|
double _Val[2]; |
24 |
|
} _C_double_complex; |
25 |
|
|
26 |
|
typedef struct _C_float_complex |
27 |
|
{ /* float complex */ |
28 |
|
float _Val[2]; |
29 |
|
} _C_float_complex; |
30 |
|
|
31 |
|
typedef struct _C_ldouble_complex |
32 |
|
{ /* long double complex */ |
33 |
|
long double _Val[2]; |
34 |
|
} _C_ldouble_complex; |
35 |
|
|
36 |
|
#endif /* _C_COMPLEX_T */ |
37 |
|
|
38 |
|
_C_STD_END |
39 |
|
|
40 |
|
// COMPLEX _Val OFFSETS |
41 |
|
#define _RE 0 |
42 |
|
#define _IM 1 |
43 |
|
|
44 |
|
_STD_BEGIN |
45 |
|
typedef ::_C_double_complex _Dcomplex_value; |
46 |
|
typedef ::_C_float_complex _Fcomplex_value; |
47 |
|
typedef ::_C_ldouble_complex _Lcomplex_value; |
48 |
|
|
49 |
|
#define __STD_COMPLEX /* signal presence of complex classes */ |
50 |
|
|
51 |
|
template<class _Ty> |
52 |
|
class complex; |
53 |
|
template<> class _CRTIMP2_PURE complex<float>; |
54 |
|
template<> class _CRTIMP2_PURE complex<double>; |
55 |
|
template<> class _CRTIMP2_PURE complex<long double>; |
56 |
|
|
57 |
|
// TEMPLATE CLASS _Ctraits |
58 |
|
template<class _Ty> |
59 |
|
class _Ctraits |
60 |
|
{ // complex traits for _Ty |
61 |
|
public: |
62 |
|
static _Ty __CLRCALL_OR_CDECL _Cosh(_Ty _Left, _Ty _Right) |
63 |
|
{ // return cosh(_Left) * _Right |
64 |
|
return (::_Cosh((double)_Left, (double)_Right)); |
65 |
|
} |
66 |
|
|
67 |
|
static short __CLRCALL_OR_CDECL _Exp(_Ty *_Pleft, _Ty _Right, short _Exponent) |
68 |
|
{ // compute exp(*_Pleft) * _Right * 2 ^ _Exponent |
69 |
|
double _Tmp = (double)*_Pleft; |
1085 |
|
if (_Istr >> _Ch && _Ch != _Ctype_fac.widen('(')) |
1086 |
|
{ // no leading '(', treat as real only |
1087 |
|
_Istr.putback(_Ch); |
1088 |
|
_Istr >> _Real; |
1089 |
|
_Imag = 0; |
1090 |
|
} |
1091 |
|
else if (_Istr >> _Real >> _Ch && _Ch != _Ctype_fac.widen(',')) |
1092 |
|
if (_Ch == _Ctype_fac.widen(')')) |
1093 |
|
_Imag = 0; // (real) |
1094 |
|
else |
1095 |
|
{ // no trailing ')' after real, treat as bad field |
1096 |
|
_Istr.putback(_Ch); |
1097 |
|
_Istr.setstate(ios_base::failbit); |
1098 |
|
} |
1099 |
|
else if (_Istr >> _Imag >> _Ch && _Ch != _Ctype_fac.widen(')')) |
1100 |
|
{ // no imag or trailing ')', treat as bad field |
1101 |
|
_Istr.putback(_Ch); |
1102 |
|
_Istr.setstate(ios_base::failbit); |
1103 |
|
} |
1104 |
|
|
1105 |
|
if (!_Istr.fail()) |
1106 |
|
{ // store valid result |
1107 |
|
_Ty _Tyreal((_Ty)_Real), _Tyimag((_Ty)_Imag); |
1108 |
|
_Right = _Myt(_Tyreal, _Tyimag); |
1109 |
|
} |
1110 |
|
return (_Istr); |
1111 |
|
} |
1112 |
|
|
1113 |
|
// TEMPLATE FUNCTION operator<< |
1114 |
|
template<class _Ty, |
1115 |
|
class _Elem, |
1116 |
|
class _Tr> inline |
1117 |
|
basic_ostream<_Elem, _Tr>& __CLRCALL_OR_CDECL operator<<( |
1118 |
|
basic_ostream<_Elem, _Tr>& _Ostr, const complex<_Ty>& _Right) |
1119 |
|
{ // insert a complex<_Ty> |
1120 |
|
const ctype<_Elem>& _Ctype_fac = _USE(_Ostr.getloc(), ctype<_Elem>); |
1121 |
|
basic_ostringstream<_Elem, _Tr, allocator<_Elem> > _Sstr; |
1122 |
|
|
1123 |
|
_Sstr.flags(_Ostr.flags()); |
1124 |
|
_Sstr.imbue(_Ostr.getloc()); |
1125 |
|
_Sstr.precision(_Ostr.precision()); |
1126 |
|
_Sstr << _Ctype_fac.widen('(') << real(_Right) |
1127 |
|
<< _Ctype_fac.widen(',') << imag(_Right) |
1128 |
|
<< _Ctype_fac.widen(')'); |
1129 |
|
|
1130 |
|
basic_string<_Elem, _Tr, allocator<_Elem> > _Str = _Sstr.str(); |
1131 |
|
return (_Ostr << _Str.c_str()); |
1132 |
|
} |
1133 |
|
|
1134 |
|
#if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE) |
1135 |
|
template _CRTIMP2_PURE basic_istream<char, char_traits<char> >& |
1136 |
|
__CLRCALL_OR_CDECL operator>>(basic_istream<char, char_traits<char> >&, |
1137 |
|
complex<float>&); |
1138 |
|
template _CRTIMP2_PURE basic_ostream<char, char_traits<char> >& |
1139 |
|
__CLRCALL_OR_CDECL operator<<(basic_ostream<char, char_traits<char> >&, |
1140 |
|
const complex<float>&); |
1141 |
|
template _CRTIMP2_PURE basic_istream<wchar_t, char_traits<wchar_t> >& |
1142 |
|
__CLRCALL_OR_CDECL operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, |
1143 |
|
complex<float>&); |
1144 |
|
template _CRTIMP2_PURE basic_ostream<wchar_t, char_traits<wchar_t> >& |
1145 |
|
__CLRCALL_OR_CDECL operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, |
1146 |
|
const complex<float>&); |
1147 |
|
|
1148 |
|
|
1149 |
|
template _CRTIMP2_PURE basic_istream<char, char_traits<char> >& |
1150 |
|
__CLRCALL_OR_CDECL operator>>(basic_istream<char, char_traits<char> >&, |
1151 |
|
complex<double>&); |
1152 |
|
template _CRTIMP2_PURE basic_ostream<char, char_traits<char> >& |
1153 |
|
__CLRCALL_OR_CDECL operator<<(basic_ostream<char, char_traits<char> >&, |
1154 |
|
const complex<double>&); |
1155 |
|
template _CRTIMP2_PURE basic_istream<wchar_t, char_traits<wchar_t> >& |
1156 |
|
__CLRCALL_OR_CDECL operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, |
1157 |
|
complex<double>&); |
1158 |
|
template _CRTIMP2_PURE basic_ostream<wchar_t, char_traits<wchar_t> >& |
1159 |
|
__CLRCALL_OR_CDECL operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, |
1160 |
|
const complex<double>&); |
1161 |
|
|
1162 |
|
|
1163 |
|
template _CRTIMP2_PURE basic_istream<char, char_traits<char> >& |
1164 |
|
__CLRCALL_OR_CDECL operator>>(basic_istream<char, char_traits<char> >&, |
1165 |
|
complex<long double>&); |
1166 |
|
template _CRTIMP2_PURE basic_ostream<char, char_traits<char> >& |
1167 |
|
__CLRCALL_OR_CDECL operator<<(basic_ostream<char, char_traits<char> >&, |
1168 |
|
const complex<long double>&); |
1169 |
|
template _CRTIMP2_PURE basic_istream<wchar_t, char_traits<wchar_t> >& |
1170 |
|
__CLRCALL_OR_CDECL operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, |
1171 |
|
complex<long double>&); |
1172 |
|
template _CRTIMP2_PURE basic_ostream<wchar_t, char_traits<wchar_t> >& |
1173 |
|
__CLRCALL_OR_CDECL operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, |
1174 |
|
const complex<long double>&); |
1175 |
|
|
1176 |
|
|
1177 |
|
|
1178 |
|
#endif /* _DLL_CPPLIB */ |
1179 |
|
_STD_END |
1180 |
|
|
1181 |
|
_C_STD_BEGIN |
1182 |
|
// TEMPLATE CLASS _Rc_type (ADDITIONS TO <math.h>) |
1183 |
|
template<class _Ty> |
1184 |
|
struct _Rc_type; |
1185 |
|
|
1186 |
|
template<> struct _Rc_type<std::complex<float> > |
1187 |
|
{ // determine if type is real or complex |
1188 |
|
typedef char _Type; |
1189 |
|
}; |
1190 |
|
|
1191 |
|
template<> struct _Rc_type<std::complex<double> > |
1192 |
|
{ // determine if type is real or complex |
1193 |
|
typedef char _Type; |
1194 |
|
}; |
1195 |
|
|
1196 |
|
template<> struct _Rc_type<std::complex<long double> > |
1197 |
|
{ // determine if type is real or complex |
1198 |
|
typedef char _Type; |
1199 |
|
}; |
1200 |
|
|
1201 |
|
// TEMPLATE CLASS _Real_type (ADDITIONS TO <math.h>) |
1202 |
|
template<class _Ty> |
1203 |
|
struct _Real_type; |
1204 |
|
|
1205 |
|
template<> struct _Real_type<std::complex<float> > |
1206 |
|
{ // determine equivalent real type |
1207 |
|
typedef float _Type; |
1208 |
|
}; |
1209 |
|
|
1210 |
|
template<> struct _Real_type<std::complex<double> > |
1211 |
|
{ // determine equivalent real type |
1212 |
|
typedef double _Type; |
1213 |
|
}; |
1214 |
|
|
1215 |
|
template<> struct _Real_type<std::complex<long double> > |
1216 |
|
{ // determine equivalent real type |
1217 |
|
typedef long double _Type; |
1218 |
|
}; |
1219 |
|
_C_STD_END |
1220 |
|
|
1221 |
|
#pragma warning(default: 4244) |
1222 |
|
|
1223 |
|
#ifdef _MSC_VER |
1224 |
|
#pragma warning(pop) |
1225 |
|
#pragma pack(pop) |
1226 |
|
#endif /* _MSC_VER */ |
1227 |
|
|
1228 |
|
#endif /* RC_INVOKED */ |
1229 |
|
#endif /* _COMPLEX_ */ |
1230 |
|
|
1231 |
|
/* |
1232 |
|
* Copyright (c) 1992-2007 by P.J. Plauger. ALL RIGHTS RESERVED. |
1233 |
|
* Consult your license regarding permissions and restrictions. |
1234 |
|
V5.03:0009 */ |
1235 |
|
|
1236 |
|
|
1237 |
|
|
|
|
|