home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / optivc32 / newcplx.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-03-06  |  61.8 KB  |  1,286 lines

  1. /* newcmplx.h
  2.  
  3.     Include-File for the CMATH Complex Number Library
  4.     replaces <complex.h>.
  5.  
  6.     Copyright (C) 1996-1999 Martin Sander
  7.     Address of the author:
  8.            Dr. Martin Sander Software Dev.
  9.            Sertuernerstr. 11
  10.            D-37085 Goettingen
  11.            Germany
  12.            MartinSander@Bigfoot.com
  13.            http://www.optivec.com
  14.  
  15.     for C++, the following classes are defined:
  16.     a) if you choose the "classic" Borland C++ style:  class complex;
  17.     b) otherwise:
  18.        classes complex<float>, complex<double>, and complex<long double>.
  19.     fComplex, dComplex, and eComplex are defined as synonyms for these classes.
  20.  
  21.     Fo plain C, use <cmath.h> instead, which declares fComplex, dComplex,
  22.     and eComplex as structs, along with the same range of functions as
  23.     present in the complex C++ classes.
  24.  
  25.     The classes complex and complex<double> are binary compatible with
  26.     the C struct dComplex. Similarly, complex<float> and struct fComplex
  27.     as well as class complex<long double> and struct eComplex are mutually
  28.     compatible. This is important if one has programs with some modules
  29.     written in C, others in C++.
  30.  
  31.     All mathematical complex functions are implemented as a library
  32.     written in Assembler language. In comparison to C++ inline functions,
  33.     this leads to greater precision, greater speed and best security due
  34.     to complete error handling via the standard C error handling functions
  35.     _matherr() (for complex<float> and complex<double>)
  36.     and _matherrl() (for complex<long double>).
  37.  
  38.     The declarations for the Standard Library complex classes have
  39.     partly been adapted from the implementation by Rogue Wave Software, Inc.
  40.     The function bodies, however, are completely new.
  41.  
  42.     Note the following important differences between this implementation
  43.     and the one contained in <complex.h>:
  44.     -  The real and imaginary parts are declared as public and are referred
  45.        to as  Re and Im, so that you may always access them as z.Re and z.Im
  46.        in addition to the member functions real(z) and imag(z);
  47.     -  The argument of all mathematical functions is a value, not a reference.
  48.     -  The following functions and operators have been added:
  49.        friend complex  cubic(complex);  //   third power
  50.        friend complex  inv(complex);    //   1.0 / z
  51.        friend complex  ipow(complex __base, int __expo);  // integer power
  52.        friend complex  log2(complex);
  53.        friend complex  powReExpo(complex __base, double __expoRe);
  54.                                        // explicit power with real exponent
  55.        friend complex  powReBase(double __baseRe, complex __expo);
  56.                                        // explicit power of real base
  57.        friend complex  quartic(complex);  // fourth power
  58.        friend complex  square(complex);
  59.        friend int      operator==(complex &, double);
  60.        friend int      operator!=(complex &, double);
  61.        Also new are many of the mixed-accuracy level binary operators.
  62. */
  63.  
  64. #ifndef __cplusplus
  65. #error Must use C++ for complex classes. Include <cmath.h> for the plain-C version
  66. #endif
  67. #if !defined(__NEWCPLX_H)
  68. #define __NEWCPLX_H
  69.  
  70.  
  71.       /* define _VFAR to get around the buggy definition of _FAR : */
  72. #if defined __TINY || defined __SMALL__ || defined __MEDIUM__
  73.     #if defined(_RTLDLL) || defined(_CLASSDLL)
  74.         #error Must use static BC Runtime Library with OptiVec in models TINY, SMALL, MEDIUM
  75.     #endif
  76.     #define   _VFAR  near   /* even in case of DS!=SS  */
  77. #elif defined __FLAT__ || defined _WIN32
  78.     #define  _VFAR
  79. #else
  80.     #define   _VFAR  far
  81. #endif
  82. #ifdef __BORLANDC__
  83.      #pragma option -a-
  84.      #if (__BORLANDC__ >= 0x450)
  85.          #define __cmf _RTLENTRY _EXPFUNC
  86.          #define __cmo _RTLENTRY
  87.     #else
  88.          #define __cmf  _Cdecl _FARFUNC
  89.          #define __cmo  _Cdecl
  90.     #endif
  91.     #if __BORLANDC__ < 0x500
  92.         #define VBOOL int
  93.     #else
  94.         #define VBOOL bool
  95.     #endif
  96. #else /* Visual C++, Watcom */
  97.      #pragma pack( push,1 )
  98.      #define VBOOL int
  99.      #define __cmf _cdecl
  100.      #define __cmo _cdecl
  101. #endif /* avoid insertion of dummy bytes  */
  102. #define _VFARC const _VFAR
  103.  
  104. #if !defined(__IOSTREAM_H)
  105. #include <iostream.h>
  106. #endif
  107.  
  108. #if defined( CMATH_CLASSIC_COMPLEX )
  109.       // classic Borland C++ class complex only. This has double precision.
  110.       // complex numbers of float and of long double precision are
  111.       // implemented as structs. So there is no constructor! Moreover, there
  112.       // are no functions defined for the float and long double complex numbers.
  113. #if !defined(__IOSTREAM_H)
  114. #include <iostream.h>
  115. #endif
  116.  
  117. #if !defined(RC_INVOKED)
  118.  
  119. #if defined(__BCOPT__)
  120. #if !defined(__FLAT__) && ((__BORLANDC__ < 0x450) || !defined(_RTL_ALLOW_po))
  121. #pragma option -po-     // disable Object data calling convention
  122. #endif
  123. #endif
  124.  
  125. #pragma option -Vo-
  126.  
  127. #if defined(__STDC__)
  128. #pragma warn -nak
  129. #endif
  130.  
  131. #endif  /* !RC_INVOKED */
  132.  
  133. #if(__BORLANDC__ >= 0x450)
  134. class _EXPCLASS complex {
  135. #else
  136. _CLASSDEF(complex)
  137. class _CLASSTYPE complex {
  138. #endif
  139.   public:
  140.     // constructors
  141.     complex( double Re_part, double Im_part ) {Re=Re_part; Im=Im_part;}
  142.     complex( double Re_part )  {Re=Re_part; Im=0;}
  143.     complex() {}; // more efficient to have these three separate variants
  144.     // Cartesian complex from polar coordinates:
  145.     friend complex __cmf polar(double _mag, double _angle=0);
  146.     // basic operations:
  147.     double real() { return Re; }                     // real part
  148.     double real(complex _VFARC &_z) { return _z.Re; }
  149.     double imag() { return Im; }                     // imaginary part
  150.     double imag(complex _VFARC &_z) { return _z.Im; } // imaginary part
  151.     friend complex __cmf neg(complex _VFARC &);   // same as unary operator -
  152.     friend complex __cmf conj(complex _VFARC &);  // complex conjugate
  153.     friend double  __cmf norm(complex);          // square of the magnitude
  154.     friend double  __cmf arg(complex);           // angle in the plane
  155.  
  156.      // Unary operators
  157.     complex _VFAR & __cmo operator+();
  158.     friend complex _VFAR & __cmf operator-( complex _VFARC &);
  159.  
  160.     // Binary operators
  161.     friend complex __cmf operator+(complex _VFARC &, complex _VFARC &);
  162.     friend complex __cmf operator+(double, complex _VFARC &);
  163.     friend complex __cmf operator+(complex _VFARC &, double);
  164.     friend complex __cmf operator-(complex _VFARC &, complex _VFARC &);
  165.     friend complex __cmf operator-(double, complex _VFARC &);
  166.     friend complex __cmf operator-(complex _VFARC &, double);
  167.     friend complex __cmf operator*(complex _VFARC &, complex _VFARC &);
  168.     friend complex __cmf operator*(complex _VFARC &, double);
  169.     friend complex __cmf operator*(double, complex _VFARC &);
  170.     friend complex __cmf operator/(complex _VFARC &, complex _VFARC &);
  171.     friend complex __cmf operator/(complex _VFARC &, double);
  172.     friend complex __cmf operator/(double, complex _VFARC &);
  173.  
  174.     friend VBOOL __cmf operator==(complex _VFARC &, complex _VFARC &);
  175.     friend VBOOL __cmf operator==(complex _VFARC &, double);
  176.     friend VBOOL __cmf operator!=(complex _VFARC &, complex _VFARC &);
  177.     friend VBOOL __cmf operator!=(complex _VFARC &, double);
  178.  
  179.     complex _VFAR & __cmo operator+=(complex _VFARC &);
  180.     complex _VFAR & __cmo operator+=(double);
  181.     complex _VFAR & __cmo operator-=(complex _VFARC &);
  182.     complex _VFAR & __cmo operator-=(double);
  183.     complex _VFAR & __cmo operator*=(complex _VFARC &);
  184.     complex _VFAR & __cmo operator*=(double);
  185.     complex _VFAR & __cmo operator/=(complex _VFARC &);
  186.     complex _VFAR & __cmo operator/=(double);
  187.  
  188.     // Overloaded ANSI C math functions with error handling via matherr():
  189.     friend double  __cmf abs(complex);    // complex pointer magnitude
  190.     friend complex __cmf acos(complex);
  191.     friend complex __cmf asin(complex);
  192.     friend complex __cmf atan(complex);
  193.     friend complex __cmf cos(complex);
  194.     friend complex __cmf cosh(complex);
  195.     friend complex __cmf cubic(complex);  // raise to the third power
  196.     friend complex __cmf exp(complex);
  197.     friend complex __cmf inv(complex);    //   1.0 / z
  198.     friend complex __cmf ipow(complex _base, int _IntExpo);  // integer power
  199.     friend complex __cmf ln(complex);
  200.     friend complex __cmf log(complex); // same as ln
  201.     friend complex __cmf log2(complex);
  202.     friend complex __cmf log10(complex);
  203.     friend complex __cmf pow(complex _base, double _expoRe);
  204.     friend complex __cmf powReExpo(complex _base, double _expoRe);
  205.     friend complex __cmf pow(double _baseRe, complex _expo);
  206.     friend complex __cmf powReBase(double _baseRe, complex _expo);
  207.     friend complex __cmf pow(complex _base, complex _expo);
  208.     friend complex __cmf quartic(complex);  // raise to the fourth power
  209.     friend complex __cmf sin(complex);
  210.     friend complex __cmf sinh(complex);
  211.     friend complex __cmf sqrt(complex);
  212.     friend complex __cmf square(complex);
  213.     friend complex __cmf tan(complex);
  214.     friend complex __cmf tanh(complex);
  215.  
  216.     friend ostream _VFAR & __cmf operator<<(ostream _VFAR &, complex _VFAR &);
  217.     friend istream _VFAR & __cmf operator>>(istream _VFAR &, complex _VFARC &);
  218.  
  219. // Implementation
  220.     double Re, Im;   // still public!
  221. };
  222. #if !defined( _CMATH_DEFS )
  223.    #define _CMATH_DEFS
  224.    typedef struct {float  Re, Im;} fComplex;
  225.    typedef complex  dComplex;
  226.    #ifdef __BORLANDC__
  227.        typedef long double  extended;
  228.        typedef struct {extended Re, Im;} eComplex;
  229.    #else /* Visual C++ */
  230.        typedef  double extended; /* Visual C++ does not support
  231.                                  80-bit IEEE numbers. So make
  232.                                  extended equal to double    */
  233.        typedef dComplex  eComplex;
  234.    #endif    /* restore default data packing  */
  235. #endif
  236.  
  237. // Inline implementation of the simplest functions and operators
  238. // basic operations:
  239. inline complex __cmo conj(complex _VFARC & __z)
  240. {    return complex(__z.Re, -__z.Im); }
  241.  
  242. inline complex __cmo neg(complex _VFARC & __z)
  243. {    return complex(-__z.Re, -__z.Im); }
  244.  
  245. // unary operators:
  246. inline complex _VFAR & __cmo complex::operator+()
  247. {    return *this; }
  248.  
  249. inline complex _VFAR & __cmf operator-( complex _VFARC & __z)
  250. {    return complex(-__z.Re, -__z.Im); }
  251.  
  252.  
  253. // binary operators:
  254. inline complex __cmo operator+(complex _VFARC & __z1, complex _VFARC & __z2)
  255. {    return complex(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  256.  
  257. inline complex __cmo operator+(double __z1Re, complex _VFARC & __z2)
  258. {    return complex(__z1Re + __z2.Re, __z2.Im); }
  259.  
  260. inline complex __cmo operator+(complex _VFARC & __z1, double __z2Re)
  261. {    return complex(__z1.Re + __z2Re, __z1.Im); }
  262.  
  263. inline complex __cmo operator-(complex _VFARC & __z1, complex _VFARC & __z2)
  264. {    return complex(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  265.  
  266. inline complex __cmo operator-(double __z1Re, complex _VFARC & __z2)
  267. {    return complex(__z1Re - __z2.Re, -__z2.Im); }
  268.  
  269. inline complex __cmo operator-(complex _VFARC & __z1, double __z2Re)
  270. {    return complex(__z1.Re - __z2Re, __z1.Im); }
  271.  
  272. inline complex __cmo operator*(complex _VFARC & __z1, complex _VFARC & __z2)
  273. {   return complex( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  274.                     __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  275. }
  276.  
  277. inline complex __cmo operator*(complex _VFARC & __z1, double __z2Re)
  278. {    return complex(__z1.Re*__z2Re, __z1.Im*__z2Re); }
  279.  
  280. inline complex __cmo operator*(double __z1Re, complex _VFARC & __z2)
  281. {    return complex(__z2.Re*__z1Re, __z2.Im*__z1Re); }
  282.  
  283. inline complex __cmo operator /(complex _VFARC & __dividend,
  284.                                 complex _VFARC & __divisor )
  285. {     complex     Result;
  286.       long double denom;
  287.       Result.Re = (double)((__dividend.Re *__divisor.Re +
  288.                             __dividend.Im *__divisor.Im) /
  289.          (denom = (long double)(__divisor.Re) * __divisor.Re +
  290.                   (long double)(__divisor.Im) * __divisor.Im));
  291.       Result.Im = (double)((__dividend.Im * __divisor.Re -
  292.                             __dividend.Re * __divisor.Im ) / denom);
  293.       return Result;
  294. }
  295.  
  296. inline complex __cmo operator/(complex _VFARC & __dividend, double __divisorRe)
  297. {    return complex(__dividend.Re/__divisorRe, __dividend.Im/__divisorRe); }
  298.  
  299. inline complex __cmo operator /( double __dividendRe, complex _VFARC & __divisor )
  300. {     complex     Result;
  301.       long double denom;
  302.       Result.Re = (double)((__dividendRe * __divisor.Re) /
  303.          (denom = (long double)(__divisor.Re) * __divisor.Re +
  304.                   (long double)(__divisor.Im) * __divisor.Im));
  305.       Result.Im = -(double)((__dividendRe * __divisor.Im ) / denom);
  306.       return Result;
  307. }
  308.  
  309. inline complex _VFAR & __cmo complex::operator+=(complex _VFARC & __z2)
  310. {   Re += __z2.Re;
  311.     Im += __z2.Im;
  312.     return *this;
  313. }
  314.  
  315. inline complex _VFAR & __cmo complex::operator+=(double __z2Re)
  316. {   Re += __z2Re;
  317.     return *this;
  318. }
  319.  
  320. inline complex _VFAR & __cmo complex::operator-=(complex _VFARC & __z2)
  321. {   Re -= __z2.Re;
  322.     Im -= __z2.Im;
  323.     return *this;
  324. }
  325.  
  326. inline complex _VFAR & __cmo complex::operator-=(double __z2Re)
  327. {   Re -= __z2Re;
  328.     return *this;
  329. }
  330.  
  331. inline complex _VFAR & __cmo complex::operator*=(double __z2Re)
  332. {   Re *= __z2Re;
  333.     Im *= __z2Re;
  334.     return *this;
  335. }
  336.  
  337. inline complex _VFAR & __cmo complex::operator *=(complex _VFARC & __z2)
  338. {     double tmpRe = Re * __z2.Re - Im * __z2.Im;
  339.              Im    = Re * __z2.Im + Im * __z2.Re;
  340.       Re = tmpRe;
  341.       return *this;
  342. }
  343.  
  344. inline complex _VFAR & __cmo complex::operator /=( complex _VFARC & __divisor )
  345. {     long double denom;
  346.       double tmpRe = (double)((Re * __divisor.Re + Im * __divisor.Im) /
  347.         (denom = (long double)(__divisor.Re) * __divisor.Re +
  348.                  (long double)(__divisor.Im) * __divisor.Im));
  349.       Im = (Im * __divisor.Re - Re * __divisor.Im ) / denom;
  350.       Re = tmpRe;
  351.       return *this;
  352. }
  353.  
  354. inline complex _VFAR & __cmo complex::operator/=(double __z2Re)
  355. {   Re /= __z2Re;
  356.     Im /= __z2Re;
  357.     return *this;
  358. }
  359.  
  360. inline VBOOL __cmo operator==(complex _VFARC & __z1, complex _VFARC & __z2)
  361. {   return __z1.Re == __z2.Re && __z1.Im == __z2.Im; }
  362.  
  363. inline VBOOL __cmo operator==(complex _VFARC & __z1, double __z2Re)
  364. {   return __z1.Re == __z2Re && __z1.Im == 0.0; }
  365.  
  366. inline VBOOL __cmo operator!=(complex _VFARC & __z1, complex _VFARC & __z2)
  367. {   return __z1.Re != __z2.Re || __z1.Im != __z2.Im; }
  368.  
  369. inline VBOOL __cmo operator!=(complex _VFARC & __z1, double __z2Re)
  370. {   return __z1.Re != __z2Re || __z1.Im != 0.0; }
  371.  
  372.  
  373. #if !defined(RC_INVOKED)
  374.  
  375. #if defined(__STDC__)
  376. #pragma warn .nak
  377. #endif
  378.  
  379. #pragma option -Vo.
  380.  
  381. #if defined(__BCOPT__)
  382. #if !defined(__FLAT__) && ((__BORLANDC__ < 0x450) || !defined(_RTL_ALLOW_po))
  383. #pragma option -po.     // restore Object data calling convention
  384. #endif
  385. #endif
  386.  
  387. #endif  /* !RC_INVOKED */
  388. #if !defined( _CMATH_DEFS )
  389.    #define _CMATH_DEFS
  390.    typedef struct {float  Re, Im;} fComplex;
  391.    typedef complex  dComplex;
  392.    #ifdef __BORLANDC__
  393.        typedef long double  extended;
  394.        typedef struct {extended Re, Im;} eComplex;
  395.    #else /* Watcom, Visual C++ */
  396.        typedef  double extended; /* Visual C++ and Optima++ do 
  397.                             not support 80-bit IEEE numbers. So 
  398.                             make extended equal to double    */
  399.        typedef dComplex  eComplex;
  400.    #endif    /* restore default data packing  */
  401. #endif
  402.  
  403. #else   // declare the complex classes for all three levels of precision
  404.         // Although these classes are fully compatible to the complex
  405.         // classes of the Standard C++ Library, keep them out of the
  406.         // standard namespace.
  407.  
  408. template <class T>
  409. class complex;
  410. class complex<float>;
  411. class complex<double>;
  412. class complex<long double>;
  413.  
  414. class complex<float>
  415. {
  416.   public:
  417.          // constructors:
  418.     #if !defined __BORLANDC__ || __BORLANDC__ >= 0x450
  419.         complex( float Re_part, float Im_part ) {Re=Re_part; Im=Im_part;}
  420.         complex( float Re_part )  {Re=Re_part; Im=0;}
  421.         complex() {}; // most efficient to have these as three different constructors!
  422.             // interconversions between the three levels of accuracy:
  423.             // with OVERFLOW error handling for the down-conversions
  424.     #else // problems with the template definitions in older BC versions
  425.         complex<float>( float Re_part, float Im_part ) {Re=Re_part; Im=Im_part;}
  426.         complex<float>( float Re_part )  {Re=Re_part; Im=0;}
  427.         complex<float>() {}; 
  428.     #endif
  429.     #if !defined _MSC_VER && (!defined __BORLANDC__ || __BORLANDC__ > 0x500)
  430.         complex (complex<float> _VFARC &);
  431.     #endif
  432.     friend complex<float> __cmf cdtocf( complex<double> cd );
  433.     friend complex<float> __cmf cetocf( complex<long double> ce );
  434.     #if defined _MSC_VER || (defined __BORLANDC__ && __BORLANDC__ >= 0x500)
  435.         explicit complex (complex<double> _VFARC &);
  436.         explicit complex (complex<long double> _VFARC &);
  437.     #else
  438.         #ifdef __BORLANDC__   // prior to v5.0
  439.             complex<float> (complex<double> _VFARC & zd) {*this = cdtocf( zd );}
  440.             complex<float> (complex<long double> _VFARC & ze) {*this = cetocf( ze );}
  441.         #else // Optima++ doesn't like "explicit"
  442.             complex (complex<double> _VFARC & zd);
  443.             complex (complex<long double> _VFARC & ze);
  444.         #endif
  445.     #endif
  446.        // simple assignments: no OVERFLOW error handling
  447.     complex<float> _VFAR & __cmo  operator= (complex<float> _VFARC &);
  448.     complex<float> _VFAR & __cmo  operator= (complex<double> _VFARC &);
  449.     complex<float> _VFAR & __cmo  operator= (complex<long double> _VFARC &);
  450.  
  451.     // Cartesian complex from polar coordinates:
  452.     friend complex<float> __cmf polar(float _mag, float _angle=0);
  453.  
  454.     // basic operations:
  455.     float real() { return Re; }                              // real part
  456.     friend float __cmf real(complex<float> _VFARC &_z);
  457.     float imag() { return Im; }                              // imaginary part
  458.     friend float __cmf imag(complex<float> _VFARC &_z);
  459.     friend complex<float> __cmf neg(complex<float> _VFARC &); // same as unary operator -
  460.     friend complex<float> __cmf conj(complex<float> _VFARC &);// complex conjugate
  461.     friend float  __cmf norm(complex<float>);          // square of the magnitude
  462.     friend float  __cmf arg(complex<float>);           // angle in the plane
  463.  
  464.      // Unary operators
  465.     complex<float> _VFAR & __cmo operator+();
  466.     friend complex<float> __cmf operator-( complex<float> _VFARC &);
  467.  
  468.     // Binary operators:
  469.     friend complex<float> __cmf operator+(complex<float> _VFARC &, complex<float> _VFARC &);
  470.     friend complex<float> __cmf operator+(float, complex<float> _VFARC &);
  471.     friend complex<float> __cmf operator+(complex<float> _VFARC &, float);
  472.     friend complex<float> __cmf operator-(complex<float> _VFARC &, complex<float> _VFARC &);
  473.     friend complex<float> __cmf operator-(float, complex<float> _VFARC &);
  474.     friend complex<float> __cmf operator-(complex<float> _VFARC &, float);
  475.     friend complex<float> __cmf operator*(complex<float> _VFARC &, complex<float> _VFARC &);
  476.     friend complex<float> __cmf operator*(complex<float> _VFARC &, float);
  477.     friend complex<float> __cmf operator*(float, complex<float> _VFARC &);
  478.     friend complex<float> __cmf operator/(complex<float> _VFARC &, complex<float> _VFARC &);
  479.     friend complex<float> __cmf operator/(complex<float> _VFARC &, float);
  480.     friend complex<float> __cmf operator/(float, complex<float> _VFARC &);
  481.        // mixed-accuracy binary operators are declared at the higher-accuracy classes
  482.  
  483.     friend VBOOL __cmf operator==(complex<float> _VFARC &, complex<float> _VFARC &);
  484.     friend VBOOL __cmf operator==(complex<float> _VFARC &, float);
  485.     friend VBOOL __cmf operator!=(complex<float> _VFARC &, complex<float> _VFARC &);
  486.     friend VBOOL __cmf operator!=(complex<float> _VFARC &, float);
  487.  
  488.        //  Compound-assignment operators:
  489.     complex<float> _VFAR & __cmo  operator+= (complex<float> _VFARC &);
  490.     complex<float> _VFAR & __cmo  operator-= (complex<float> _VFARC &);
  491.     complex<float> _VFAR & __cmo  operator*= (complex<float> _VFARC &);
  492.     complex<float> _VFAR & __cmo  operator/= (complex<float> _VFARC &);
  493.  
  494.     complex<float> _VFAR & __cmo  operator+= (complex<double> _VFARC &);
  495.     complex<float> _VFAR & __cmo  operator-= (complex<double> _VFARC &);
  496.     complex<float> _VFAR & __cmo  operator*= (complex<double> _VFARC &);
  497.     complex<float> _VFAR & __cmo  operator/= (complex<double> _VFARC &);
  498.  
  499.     complex<float> _VFAR & __cmo  operator+= (complex<long double> _VFARC &);
  500.     complex<float> _VFAR & __cmo  operator-= (complex<long double> _VFARC &);
  501.     complex<float> _VFAR & __cmo  operator*= (complex<long double> _VFARC &);
  502.     complex<float> _VFAR & __cmo  operator/= (complex<long double> _VFARC &);
  503.  
  504.     // Overloaded ANSI C math functions
  505.     friend float          __cmf abs(complex<float>);
  506.     friend complex<float> __cmf acos(complex<float>);
  507.     friend complex<float> __cmf asin(complex<float>);
  508.     friend complex<float> __cmf atan(complex<float>);
  509.     friend complex<float> __cmf cos(complex<float>);
  510.     friend complex<float> __cmf cosh(complex<float>);
  511.     friend complex<float> __cmf cubic(complex<float>);  // raise to the third power
  512.     friend complex<float> __cmf exp(complex<float>);
  513.     friend complex<float> __cmf inv(complex<float>);    //   1.0 / z
  514.     friend complex<float> __cmf ipow(complex<float> __base, int __expon);  // integer power
  515.     friend complex<float> __cmf ln(complex<float>);
  516.     friend complex<float> __cmf log(complex<float>); // same as ln
  517.     friend complex<float> __cmf log2(complex<float>);
  518.     friend complex<float> __cmf log10(complex<float>);
  519.     friend complex<float> __cmf pow(complex<float> __base, float __expon);
  520.     friend complex<float> __cmf powReExpo(complex<float> __base, float __expon);
  521.     friend complex<float> __cmf pow(float __base, complex<float> __expon);
  522.     friend complex<float> __cmf powReBase(float __base, complex<float> __expon);
  523.     friend complex<float> __cmf pow(complex<float> __base, complex<float> __expon);
  524.     friend complex<float> __cmf quartic(complex<float>);  // raise to the fourth power
  525.     friend complex<float> __cmf sin(complex<float>);
  526.     friend complex<float> __cmf sinh(complex<float>);
  527.     friend complex<float> __cmf sqrt(complex<float>);
  528.     friend complex<float> __cmf square(complex<float>);
  529.     friend complex<float> __cmf tan(complex<float>);
  530.     friend complex<float> __cmf tanh(complex<float>);
  531.  
  532.     friend istream _VFAR & __cmf operator>> (istream _VFAR &, complex<float> _VFAR &);
  533.     friend ostream _VFAR & __cmf operator<< (ostream _VFAR &, complex<float> _VFARC &);
  534.  
  535.     float Re, Im;  // still public!
  536. };
  537.  
  538. class  complex<double>
  539. {
  540.   public:
  541.          // constructors:
  542.     #if !defined __BORLANDC__ || __BORLANDC__ >= 0x450
  543.         complex( double Re_part, double Im_part ) {Re=Re_part; Im=Im_part;}
  544.         complex( double Re_part )  {Re=Re_part; Im=0;}
  545.         complex() {};
  546.             // interconversions between the three levels of accuracy:
  547.             // with OVERFLOW error handling for the down-conversions
  548.         complex (complex<float> _VFARC &);
  549.     #else // problems with the template definitions in older BC versions
  550.         complex<double>( double Re_part, double Im_part ) {Re=Re_part; Im=Im_part;}
  551.         complex<double>( double Re_part )  {Re=Re_part; Im=0;}
  552.         complex<double>() {};
  553.         complex<double> (complex<float> _VFARC & zf) {Re = zf.Re; Im = zf.Im;}
  554.     #endif
  555.     #if !defined _MSC_VER && (!defined __BORLANDC__ || __BORLANDC__ > 0x500)
  556.             complex (complex<double> _VFARC &);
  557.     #endif
  558.     friend complex<double> __cmf cetocd( complex<long double> ce );
  559.     #if defined _MSC_VER || (defined __BORLANDC__ && __BORLANDC__ >= 0x500)
  560.         explicit complex (complex<long double> _VFARC &);
  561.     #else
  562.         #ifdef __BORLANDC__  // prior to v5.0
  563.             complex<double> (complex<long double> _VFARC & ze) {*this = cetocd( ze );}
  564.         #else  // Optima++ doesn't like "explicit"
  565.             complex (complex<long double> _VFARC & ze);
  566.         #endif
  567.     #endif
  568.           // simple assignments: no OVERFLOW error handling
  569.     complex<double> _VFAR & __cmo  operator= (complex<float> _VFARC &);
  570.     complex<double> _VFAR & __cmo  operator= (complex<double> _VFARC &);
  571.     complex<double> _VFAR & __cmo  operator= (complex<long double> _VFARC &);
  572.  
  573.     // Cartesian complex from polar coordinates:
  574.     friend complex<double> __cmf polar(double __mag, double __angle=0);
  575.  
  576.     // basic operations:
  577.     double real() { return Re; }                              // real part
  578.     friend double __cmf real(complex<double> _VFARC &_z);
  579.     double imag() { return Im; }                              // imaginary part
  580.     friend double __cmf imag(complex<double> _VFARC &_z);
  581.     friend complex<double> __cmf neg(complex<double> _VFARC &); // same as unary operator -
  582.     friend complex<double> __cmf conj(complex<double> _VFARC &);// complex conjugate
  583.     friend double  __cmf norm(complex<double>);         // square of the magnitude
  584.     friend double  __cmf arg(complex<double>);          // the angle in the plane
  585.  
  586.      // Unary operators
  587.     complex<double> _VFAR & __cmo operator+();
  588.     friend complex<double>  __cmf operator-( complex<double> _VFARC &);
  589.  
  590.         // Binary operators:
  591.     friend complex<double> __cmf operator+(complex<double> _VFARC &, complex<double> _VFARC &);
  592.     friend complex<double> __cmf operator+(double, complex<double> _VFARC &);
  593.     friend complex<double> __cmf operator+(complex<double> _VFARC &, double);
  594.     friend complex<double> __cmf operator-(complex<double> _VFARC &, complex<double> _VFARC &);
  595.     friend complex<double> __cmf operator-(double, complex<double> _VFARC &);
  596.     friend complex<double> __cmf operator-(complex<double> _VFARC &, double);
  597.     friend complex<double> __cmf operator*(complex<double> _VFARC &, complex<double> _VFARC &);
  598.     friend complex<double> __cmf operator*(complex<double> _VFARC &, double);
  599.     friend complex<double> __cmf operator*(double, complex<double> _VFARC &);
  600.     friend complex<double> __cmf operator/(complex<double> _VFARC &, complex<double> _VFARC &);
  601.     friend complex<double> __cmf operator/(complex<double> _VFARC &, double);
  602.     friend complex<double> __cmf operator/(double, complex<double> _VFARC &);
  603.         // float-double mixed-accuracy versions:
  604.     friend complex<double> __cmf operator+(complex<float> _VFARC &, complex<double> _VFARC &);
  605.     friend complex<double> __cmf operator+(complex<double> _VFARC &, complex<float> _VFARC &);
  606.     friend complex<double> __cmf operator-(complex<float> _VFARC &, complex<double> _VFARC &);
  607.     friend complex<double> __cmf operator-(complex<double> _VFARC &, complex<float> _VFARC &);
  608.     friend complex<double> __cmf operator*(complex<float> _VFARC &, complex<double> _VFARC &);
  609.     friend complex<double> __cmf operator*(complex<double> _VFARC &, complex<float> _VFARC &);
  610.     friend complex<double> __cmf operator/(complex<float> _VFARC &, complex<double> _VFARC &);
  611.     friend complex<double> __cmf operator/(complex<double> _VFARC &, complex<float> _VFARC &);
  612.  
  613.     friend VBOOL __cmf operator==(complex<double> _VFARC &, complex<double> _VFARC &);
  614.     friend VBOOL __cmf operator==(complex<double> _VFARC &, double);
  615.     friend VBOOL __cmf operator!=(complex<double> _VFARC &, complex<double> _VFARC &);
  616.     friend VBOOL __cmf operator!=(complex<double> _VFARC &, double);
  617.  
  618.        //  Compound-assignment operators:
  619.     complex<double> _VFAR & __cmo  operator+= (complex<float> _VFARC &);
  620.     complex<double> _VFAR & __cmo  operator-= (complex<float> _VFARC &);
  621.     complex<double> _VFAR & __cmo  operator*= (complex<float> _VFARC &);
  622.     complex<double> _VFAR & __cmo  operator/= (complex<float> _VFARC &);
  623.  
  624.     complex<double> _VFAR & __cmo  operator+= (complex<double> _VFARC &);
  625.     complex<double> _VFAR & __cmo  operator-= (complex<double> _VFARC &);
  626.     complex<double> _VFAR & __cmo  operator*= (complex<double> _VFARC &);
  627.     complex<double> _VFAR & __cmo  operator/= (complex<double> _VFARC &);
  628.  
  629.     complex<double> _VFAR & __cmo  operator+= (complex<long double> _VFARC &);
  630.     complex<double> _VFAR & __cmo  operator-= (complex<long double> _VFARC &);
  631.     complex<double> _VFAR & __cmo  operator*= (complex<long double> _VFARC &);
  632.     complex<double> _VFAR & __cmo  operator/= (complex<long double> _VFARC &);
  633.  
  634.     // Overloaded ANSI C math functions
  635.     friend double          __cmf abs(complex<double>);
  636.     friend complex<double> __cmf acos(complex<double>);
  637.     friend complex<double> __cmf asin(complex<double>);
  638.     friend complex<double> __cmf atan(complex<double>);
  639.     friend complex<double> __cmf cos(complex<double>);
  640.     friend complex<double> __cmf cosh(complex<double>);
  641.     friend complex<double> __cmf cubic(complex<double>);  // raise to the third power
  642.     friend complex<double> __cmf exp(complex<double>);
  643.     friend complex<double> __cmf inv(complex<double>);    //   1.0 / z
  644.     friend complex<double> __cmf ipow(complex<double> __base, int __expon);  // integer power
  645.     friend complex<double> __cmf ln(complex<double>);
  646.     friend complex<double> __cmf log(complex<double>); // same as ln
  647.     friend complex<double> __cmf log2(complex<double>);
  648.     friend complex<double> __cmf log10(complex<double>);
  649.     friend complex<double> __cmf pow(complex<double> __base, double __expon);
  650.     friend complex<double> __cmf powReExpo(complex<double> __base, double __expon);
  651.     friend complex<double> __cmf pow(double __base, complex<double> __expon);
  652.     friend complex<double> __cmf powReBase(double __base, complex<double> __expon);
  653.     friend complex<double> __cmf pow(complex<double> __base, complex<double> __expon);
  654.     friend complex<double> __cmf quartic(complex<double>);  // raise to the fourth power
  655.     friend complex<double> __cmf sin(complex<double>);
  656.     friend complex<double> __cmf sinh(complex<double>);
  657.     friend complex<double> __cmf sqrt(complex<double>);
  658.     friend complex<double> __cmf square(complex<double>);
  659.     friend complex<double> __cmf tan(complex<double>);
  660.     friend complex<double> __cmf tanh(complex<double>);
  661.  
  662.     friend istream _VFAR & __cmf operator>> (istream _VFAR &, complex<double> _VFAR &);
  663.     friend ostream _VFAR & __cmf operator<< (ostream _VFAR &, complex<double> _VFARC &);
  664.  
  665.     double Re, Im;  // still public!
  666. };
  667.  
  668. class complex<long double>
  669. {
  670.   public:
  671.          // constructors:
  672.     #if !defined __BORLANDC__ || __BORLANDC__ >= 0x450
  673.         complex( long double Re_part, long double Im_part ) {Re=Re_part; Im=Im_part;}
  674.         complex( long double Re_part )  {Re=Re_part; Im=0;}
  675.         complex() {};
  676.             // interconversions between the three levels of accuracy:
  677.         complex (complex<float> _VFARC &);
  678.         complex (complex<double> _VFARC &);
  679.     #else // problems with the template definitions in older BC versions
  680.         complex<long double>( long double Re_part, long double Im_part ) {Re=Re_part; Im=Im_part;}
  681.         complex<long double>( long double Re_part )  {Re=Re_part; Im=0;}
  682.         complex<long double>() {};
  683.                 // interconversions between the three levels of accuracy:
  684.         complex<long double> (complex<float> _VFARC & zf) {Re = zf.Re; Im = zf.Im;}
  685.         complex<long double> (complex<double> _VFARC & zd) {Re = zd.Re; Im = zd.Im;}
  686.     #endif
  687.     #if !defined _MSC_VER && (!defined __BORLANDC__ || __BORLANDC__ > 0x500)
  688.         complex (complex<long double> _VFARC &);
  689.     #endif
  690.           // simple assignments do the same:
  691.     complex<long double> _VFAR & __cmo  operator=  (complex<float> _VFARC &);
  692.     complex<long double> _VFAR & __cmo  operator=  (complex<double> _VFARC &);
  693.     complex<long double> _VFAR & __cmo  operator=  (complex<long double> _VFARC &);
  694.  
  695.           // Cartesian complex from polar coordinates:
  696.     friend complex<long double> __cmf polar(long double __mag, long double __angle=0);
  697.         // basic operations:
  698.     long double real() { return Re; }                              // real part
  699.     friend long double __cmf real(complex<long double> _VFARC &_z);
  700.     long double imag() { return Im; }                              // imaginary part
  701.     friend long double __cmf imag(complex<long double> _VFARC &_z);
  702.     friend complex<long double> __cmf neg(complex<long double> _VFARC &); // same as unary operator -
  703.     friend complex<long double> __cmf conj(complex<long double> _VFARC &);// complex conjugate
  704.     friend long double  __cmf norm(complex<long double>);         // square of the magnitude
  705.     friend long double  __cmf arg(complex<long double>);          // the angle in the plane
  706.  
  707.      // Unary operators
  708.     complex<long double> _VFAR & __cmo operator+();
  709.     friend complex<long double>  __cmf operator-( complex<long double> _VFARC &);
  710.  
  711.         // Binary operators:
  712.     friend complex<long double> __cmf operator+(complex<long double> _VFARC &, complex<long double> _VFARC &);
  713.     friend complex<long double> __cmf operator+(long double, complex<long double> _VFARC &);
  714.     friend complex<long double> __cmf operator+(complex<long double> _VFARC &, long double);
  715.     friend complex<long double> __cmf operator-(complex<long double> _VFARC &, complex<long double> _VFARC &);
  716.     friend complex<long double> __cmf operator-(long double, complex<long double> _VFARC &);
  717.     friend complex<long double> __cmf operator-(complex<long double> _VFARC &, long double);
  718.     friend complex<long double> __cmf operator*(complex<long double> _VFARC &, complex<long double> _VFARC &);
  719.     friend complex<long double> __cmf operator*(complex<long double> _VFARC &, long double);
  720.     friend complex<long double> __cmf operator*(long double, complex<long double> _VFARC &);
  721.     friend complex<long double> __cmf operator/(complex<long double> _VFARC & __dividend,
  722.                                                 complex<long double> _VFARC & __divisor);
  723.     friend complex<long double> __cmf operator/(complex<long double> _VFARC &, long double );
  724.     friend complex<long double> __cmf operator/(long double __dividend,
  725.                                                 complex<long double> _VFARC &__divisor);
  726.         // mixed-accuracy versions:
  727.     friend complex<long double> __cmf operator+(complex<float> _VFARC &, complex<long double> _VFARC &);
  728.     friend complex<long double> __cmf operator+(complex<long double> _VFARC &, complex<float> _VFARC &);
  729.     friend complex<long double> __cmf operator+(complex<double> _VFARC &, complex<long double> _VFARC &);
  730.     friend complex<long double> __cmf operator+(complex<long double> _VFARC &, complex<double> _VFARC &);
  731.     friend complex<long double> __cmf operator-(complex<float> _VFARC &, complex<long double> _VFARC &);
  732.     friend complex<long double> __cmf operator-(complex<long double> _VFARC &, complex<float> _VFARC &);
  733.     friend complex<long double> __cmf operator-(complex<double> _VFARC &, complex<long double> _VFARC &);
  734.     friend complex<long double> __cmf operator-(complex<long double> _VFARC &, complex<double> _VFARC &);
  735.     friend complex<long double> __cmf operator*(complex<float> _VFARC &, complex<long double> _VFARC &);
  736.     friend complex<long double> __cmf operator*(complex<long double> _VFARC &, complex<float> _VFARC &);
  737.     friend complex<long double> __cmf operator*(complex<double> _VFARC &, complex<long double> _VFARC &);
  738.     friend complex<long double> __cmf operator*(complex<long double> _VFARC &, complex<double> _VFARC &);
  739.     friend complex<long double> __cmf operator/(complex<long double> _VFARC & __dividend,
  740.                                                 complex<float> _VFARC & __divisor);
  741.     friend complex<long double> __cmf operator/(complex<long double> _VFARC & __dividend,
  742.                                                 complex<double> _VFARC & __divisor);
  743.     friend complex<long double> __cmf operator/(complex<float> _VFARC & __dividend,
  744.                                                 complex<long double> _VFARC & __divisor);
  745.     friend complex<long double> __cmf operator/(complex<double> _VFARC & __dividend,
  746.                                                 complex<long double> _VFARC & __divisor);
  747.  
  748.     friend VBOOL __cmf operator==(complex<long double> _VFARC &, complex<long double> _VFARC &);
  749.     friend VBOOL __cmf operator==(complex<long double> _VFARC &, long double);
  750.     friend VBOOL __cmf operator!=(complex<long double> _VFARC &, complex<long double> _VFARC &);
  751.     friend VBOOL __cmf operator!=(complex<long double> _VFARC &, long double);
  752.  
  753.        //  Compound-assignment operators:
  754.     complex<long double> _VFAR & __cmo  operator+= (complex<float> _VFARC &);
  755.     complex<long double> _VFAR & __cmo  operator-= (complex<float> _VFARC &);
  756.     complex<long double> _VFAR & __cmo  operator*= (complex<float> _VFARC &);
  757.     complex<long double> _VFAR & __cmo  operator/= (complex<float> _VFARC &);
  758.  
  759.     complex<long double> _VFAR & __cmo  operator+= (complex<double> _VFARC &);
  760.     complex<long double> _VFAR & __cmo  operator-= (complex<double> _VFARC &);
  761.     complex<long double> _VFAR & __cmo  operator*= (complex<double> _VFARC &);
  762.     complex<long double> _VFAR & __cmo  operator/= (complex<double> _VFARC &);
  763.  
  764.     complex<long double> _VFAR & __cmo  operator+= (complex<long double> _VFARC &);
  765.     complex<long double> _VFAR & __cmo  operator-= (complex<long double> _VFARC &);
  766.     complex<long double> _VFAR & __cmo  operator*= (complex<long double> _VFARC &);
  767.     complex<long double> _VFAR & __cmo  operator/= (complex<long double> _VFARC &);
  768.  
  769.     // Overloaded ANSI C math functions
  770.     friend long double          __cmf abs(complex<long double>);
  771.     friend complex<long double> __cmf acos(complex<long double>);
  772.     friend complex<long double> __cmf asin(complex<long double>);
  773.     friend complex<long double> __cmf atan(complex<long double>);
  774.     friend complex<long double> __cmf cos(complex<long double>);
  775.     friend complex<long double> __cmf cosh(complex<long double>);
  776.     friend complex<long double> __cmf cubic(complex<long double>);  // raise to the third power
  777.     friend complex<long double> __cmf exp(complex<long double>);
  778.     friend complex<long double> __cmf inv(complex<long double>);    //   1.0 / z
  779.     friend complex<long double> __cmf ipow(complex<long double> __base, int __expon);  // integer power
  780.     friend complex<long double> __cmf ln(complex<long double>);
  781.     friend complex<long double> __cmf log(complex<long double>); // same as ln
  782.     friend complex<long double> __cmf log2(complex<long double>);
  783.     friend complex<long double> __cmf log10(complex<long double>);
  784.     friend complex<long double> __cmf pow(complex<long double> __base, long double __expon);
  785.     friend complex<long double> __cmf powReExpo(complex<long double> __base, long double __expon);
  786.     friend complex<long double> __cmf pow(long double __base, complex<long double> __expon);
  787.     friend complex<long double> __cmf powReBase(long double __base, complex<long double> __expon);
  788.     friend complex<long double> __cmf pow(complex<long double> __base, complex<long double> __expon);
  789.     friend complex<long double> __cmf quartic(complex<long double>);  // raise to the fourth power
  790.     friend complex<long double> __cmf sin(complex<long double>);
  791.     friend complex<long double> __cmf sinh(complex<long double>);
  792.     friend complex<long double> __cmf sqrt(complex<long double>);
  793.     friend complex<long double> __cmf square(complex<long double>);
  794.     friend complex<long double> __cmf tan(complex<long double>);
  795.     friend complex<long double> __cmf tanh(complex<long double>);
  796.  
  797.     friend istream _VFAR & __cmf operator>> (istream _VFAR &,
  798.                                              complex<long double> _VFAR &);
  799.     friend ostream _VFAR & __cmf operator<< (ostream _VFAR &,
  800.                                              complex<long double> _VFARC &);
  801.     long double Re, Im; // still public!
  802. };
  803. #ifndef _CMATH_DEFS
  804.     #ifdef __BORLANDC__
  805.         typedef long double extended;
  806.     #else
  807.         typedef double extended;
  808.     #endif
  809.     typedef complex<float>      fComplex;
  810.     typedef complex<double>     dComplex;
  811.     typedef complex<extended>   eComplex; // for MSVC, this will be complex<double>, not complex<long double> !
  812.     #define _CMATH_DEFS
  813.     #define _CMATH_CLASSDEFS
  814. #endif  // _CMATH_DEFS
  815.  
  816. // inline-implementation of the simple functions and operators
  817.  
  818. //  data-type interconverting constructors:
  819. //  in the down-conversions, OVERFLOW errors are handled via _matherr
  820. #if !defined __BORLANDC__ || __BORLANDC__ >= 0x450
  821.     inline complex<float>::complex (complex<double> _VFARC & zd){ *this = cdtocf( zd ); }
  822.     inline complex<float>::complex (complex<long double> _VFARC & ze){*this = cetocf( ze );}
  823.     inline complex<double>::complex (complex<float> _VFARC & zf){Re = zf.Re; Im = zf.Im; }
  824.     inline complex<double>::complex (complex<long double> _VFARC & ze){*this = cetocd( ze );}
  825.     inline complex<long double>::complex (complex<float> _VFARC & zf){Re=zf.Re; Im=zf.Im;}
  826.     inline complex<long double>::complex (complex<double> _VFARC & zd){Re=zd.Re; Im=zd.Im;}
  827. #endif
  828. #if !defined _MSC_VER && (!defined __BORLANDC__ || __BORLANDC__ > 0x500)
  829.     inline complex<float>::complex (complex<float> _VFARC & zf){ Re = zf.Re; Im = zf.Im;}
  830.     inline complex<double>::complex (complex<double> _VFARC & zd){Re = zd.Re; Im = zd.Im; }
  831.     inline complex<long double>::complex (complex<long double> _VFARC & ze){Re=ze.Re; Im=ze.Im;}
  832. #endif
  833.  
  834. //  simple assignments:
  835. inline complex<float> _VFAR & __cmo complex<float>::operator= (complex<float> _VFARC & __z)
  836. {   Re = __z.Re; Im = __z.Im; return *this; }
  837. inline complex<float> _VFAR & complex<float>::operator= (complex<double> _VFARC & __z)
  838. {   Re = (float) __z.Re; Im = (float) __z.Im; return *this; }
  839. inline complex<float> _VFAR & complex<float>::operator= (complex<long double> _VFARC & __z)
  840. {   Re = (float) __z.Re; Im = (float) __z.Im; return *this; }
  841. inline complex<double> _VFAR & complex<double>::operator= (complex<float> _VFARC & __z)
  842. {   Re = __z.Re; Im = __z.Im; return *this; }
  843. inline complex<double> _VFAR & complex<double>::operator= (complex<double> _VFARC & __z)
  844. {   Re = __z.Re; Im = __z.Im; return *this; }
  845. inline complex<double> _VFAR & complex<double>::operator= (complex<long double> _VFARC & __z)
  846. {   Re = (double) __z.Re; Im = (double) __z.Im; return *this; }
  847. inline complex<long double> _VFAR & complex<long double>::operator= (complex<float> _VFARC & __z)
  848. {   Re = __z.Re; Im = __z.Im; return *this; }
  849. inline complex<long double> _VFAR & complex<long double>::operator= (complex<double> _VFARC & __z)
  850. {   Re = __z.Re; Im = __z.Im; return *this; }
  851. inline complex<long double> _VFAR & complex<long double>::operator= (complex<long double> _VFARC & __z)
  852. {   Re = __z.Re; Im = __z.Im; return *this; }
  853.  
  854. // basic operations:
  855. template<class T>
  856. inline T __cmf real( complex<T> _VFARC & __z) { return __z.Re; }
  857.  
  858. template<class T>
  859. inline T __cmf imag( complex<T> _VFARC & __z) { return __z.Im; }
  860.  
  861. template <class T>
  862. inline complex<T> __cmf neg( complex<T> _VFARC & __z )
  863. {   return complex<T>(-__z.Re, -__z.Im); }
  864.  
  865. template <class T>
  866. inline complex<T> __cmf conj( complex<T> _VFARC & __z )
  867. {   return complex<T>(__z.Re, -__z.Im); }
  868.  
  869.          // Unary operators:
  870. #if defined _MSC_VER   /* doesn't like templated version of operator +*/
  871.     inline complex<float> _VFAR & __cmo complex<float>::operator+()
  872.     {   return (*this); }
  873.     inline complex<double> _VFAR & __cmo complex<double>::operator+()
  874.     {   return (*this); }
  875.     inline complex<long double> _VFAR & __cmo complex<long double>::operator+()
  876.     {   return (*this); }
  877. #else
  878.     template <class T>
  879.     inline complex<T> _VFAR & __cmo complex<T>::operator+()
  880.     {   return (*this); }
  881. #endif
  882.  
  883. template <class T>
  884. inline complex<T> __cmf operator-( complex<T> _VFARC & __z)
  885. {   return complex<T>(-__z.Re, -__z.Im); }
  886.  
  887.                 // Binary operators:
  888. inline complex<float> __cmf operator+( complex<float> _VFARC & __z1, complex<float> _VFARC & __z2)
  889. {   return complex<float>(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  890. inline complex<float> __cmf operator-( complex<float> _VFARC & __z1, complex<float> _VFARC & __z2)
  891. {   return complex<float>(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  892. inline complex<float> __cmf operator*( complex<float> _VFARC & __z1, complex<float> _VFARC & __z2)
  893. {   return complex<float>( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  894.                            __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  895. }
  896. inline complex<double> __cmf operator+( complex<double> _VFARC & __z1, complex<double> _VFARC & __z2)
  897. {   return complex<double>(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  898. inline complex<double> __cmf operator-( complex<double> _VFARC & __z1, complex<double> _VFARC & __z2)
  899. {   return complex<double>(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  900. inline complex<double> __cmf operator*( complex<double> _VFARC & __z1, complex<double> _VFARC & __z2)
  901. {   return complex<double>( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  902.                            __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  903. }
  904. inline complex<long double> __cmf operator+( complex<long double> _VFARC & __z1, complex<long double> _VFARC & __z2)
  905. {   return complex<long double>(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  906. inline complex<long double> __cmf operator-( complex<long double> _VFARC & __z1, complex<long double> _VFARC & __z2)
  907. {   return complex<long double>(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  908. inline complex<long double> __cmf operator*( complex<long double> _VFARC & __z1, complex<long double> _VFARC & __z2)
  909. {   return complex<long double>( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  910.                            __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  911. }
  912.     // cannot use templates for the above operators,
  913.     // as some compilers will complain when they come
  914.     // to the mixed-type operators below.
  915.  
  916.  
  917. template <class T>
  918. inline complex<T> __cmf operator+( complex<T> _VFARC & __z1, T __z2Re )
  919. {   return complex<T>(__z1.Re+__z2Re, __z1.Im); }
  920.  
  921. template <class T>
  922. inline complex<T> __cmf operator+( T __z1Re, complex<T> _VFARC & __z2 )
  923. {   return complex<T>(__z1Re + __z2.Re, __z2.Im); }
  924.  
  925. template <class T>
  926. inline complex<T> __cmf operator-( complex<T> _VFARC & __z1, T __z2Re )
  927. {   return complex<T>(__z1.Re - __z2Re, __z1.Im); }
  928.  
  929. template <class T>
  930. inline complex<T> __cmf operator-( T __z1Re, complex<T> _VFARC & __z2 )
  931. {   return complex<T>(__z1Re - __z2.Re, -__z2.Im); }
  932.  
  933. template <class T>
  934. inline complex<T> __cmf operator*( complex<T> _VFARC & __z1, T __z2Re )
  935. {   return complex<T>( __z1.Re * __z2Re, __z1.Im * __z2Re ); }
  936.  
  937. template <class T>
  938. inline complex<T> __cmf operator*( T __z1Re, complex<T> _VFARC & __z2 )
  939. {   return complex<T>( __z1Re * __z2.Re, __z1Re * __z2.Im ); }
  940.  
  941. template <class T>
  942. inline complex<T> __cmf operator/( complex<T> _VFARC & __dividend, T __divisorRe)
  943. {   return complex<T>( __dividend.Re / __divisorRe, __dividend.Im / __divisorRe ); }
  944.  
  945. inline complex<float> __cmf operator/( complex<float> _VFARC & __dividend,
  946.                                        complex<float> _VFARC & __divisor )
  947. {     complex<float> Result;
  948.       double denom;
  949.       Result.Re = (float)((__dividend.Re *__divisor.Re +
  950.                            __dividend.Im *__divisor.Im) /
  951.          (denom = (double)(__divisor.Re) * __divisor.Re +
  952.                   (double)(__divisor.Im) * __divisor.Im));
  953.       Result.Im = (float)((__dividend.Im * __divisor.Re -
  954.                            __dividend.Re * __divisor.Im ) / denom);
  955.       return Result;
  956. }
  957.  
  958.     //  operator / (complex<double>, complex<double> ) and
  959.     //  operator / (complex<long double>, complex<long double> ) 
  960.     //  cannot safely be inlined
  961.  
  962. inline complex<float> __cmf operator /( float __dividendRe,
  963.                                         complex<float> _VFARC & __divisor )
  964. {     complex<float> Result;
  965.       double         denom;
  966.       Result.Re = (float)((__dividendRe * __divisor.Re) /
  967.         (denom = (double)(__divisor.Re) * __divisor.Re +
  968.                  (double)(__divisor.Im) * __divisor.Im));
  969.       Result.Im = -(float)((__dividendRe * __divisor.Im ) / denom);
  970.       return Result;
  971. }
  972.  
  973.     // Mixed-accuracy level binary operators:
  974. inline complex<double> __cmf operator+( complex<float> _VFARC & __z1, complex<double> _VFARC & __z2)
  975. {   return complex<double>(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  976. inline complex<double> __cmf operator+( complex<double> _VFARC & __z1, complex<float> _VFARC & __z2)
  977. {   return complex<double>(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  978. inline complex<long double> __cmf operator+( complex<float> _VFARC & __z1, complex<long double> _VFARC & __z2)
  979. {   return complex<long double>(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  980. inline complex<long double> __cmf operator+( complex<long double> _VFARC & __z1, complex<float> _VFARC & __z2)
  981. {   return complex<long double>(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  982. inline complex<long double> __cmf operator+( complex<double> _VFARC & __z1, complex<long double> _VFARC & __z2)
  983. {   return complex<long double>(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  984. inline complex<long double> __cmf operator+( complex<long double> _VFARC & __z1, complex<double> _VFARC & __z2)
  985. {   return complex<long double>(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  986.  
  987. inline complex<double> __cmf operator-( complex<float> _VFARC & __z1, complex<double> _VFARC & __z2)
  988. {   return complex<double>(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  989. inline complex<double> __cmf operator-( complex<double> _VFARC & __z1, complex<float> _VFARC & __z2)
  990. {   return complex<double>(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  991. inline complex<long double> __cmf operator-( complex<float> _VFARC & __z1, complex<long double> _VFARC & __z2)
  992. {   return complex<long double>(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  993. inline complex<long double> __cmf operator-( complex<long double> _VFARC & __z1, complex<float> _VFARC & __z2)
  994. {   return complex<long double>(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  995. inline complex<long double> __cmf operator-( complex<double> _VFARC & __z1, complex<long double> _VFARC & __z2)
  996. {   return complex<long double>(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  997. inline complex<long double> __cmf operator-( complex<long double> _VFARC & __z1, complex<double> _VFARC & __z2)
  998. {   return complex<long double>(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  999.  
  1000. inline complex<double> __cmf operator*( complex<float> _VFARC & __z1, complex<double> _VFARC & __z2 )
  1001. {   return complex<double>( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  1002.                             __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  1003. }
  1004. inline complex<double> __cmf operator*( complex<double> _VFARC & __z1, complex<float> _VFARC & __z2 )
  1005. {   return complex<double>( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  1006.                             __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  1007. }
  1008. inline complex<long double> __cmf operator*( complex<float> _VFARC & __z1, complex<long double> _VFARC & __z2 )
  1009. {   return complex<long double>( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  1010.                                  __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  1011. }
  1012. inline complex<long double> __cmf operator*( complex<long double> _VFARC & __z1, complex<float> _VFARC & __z2 )
  1013. {   return complex<long double>( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  1014.                                  __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  1015. }
  1016. inline complex<long double> __cmf operator*( complex<double> _VFARC & __z1, complex<long double> _VFARC & __z2 )
  1017. {   return complex<long double>( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  1018.                                  __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  1019. }
  1020. inline complex<long double> __cmf operator*( complex<long double> _VFARC & __z1, complex<double> _VFARC & __z2 )
  1021. {   return complex<long double>( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  1022.                                  __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  1023. }
  1024.  
  1025. inline complex<double> __cmf operator/( complex<double> _VFARC & __dividend,
  1026.                                         complex<float>  _VFARC & __divisor )
  1027. {     complex<double> Result;
  1028.       double          denom;
  1029.       Result.Re = (__dividend.Re *__divisor.Re +
  1030.                    __dividend.Im *__divisor.Im) /
  1031.          (denom = (double)(__divisor.Re) * __divisor.Re +
  1032.                   (double)(__divisor.Im) * __divisor.Im);
  1033.       Result.Im = (__dividend.Im * __divisor.Re -
  1034.                    __dividend.Re * __divisor.Im ) / denom;
  1035.       return Result;
  1036. }
  1037.  
  1038. inline complex<long double> __cmf operator/( complex<long double> _VFARC & __dividend,
  1039.                                              complex<float>  _VFARC & __divisor )
  1040. {     complex<long double> Result;
  1041.       double               denom;
  1042.       Result.Re = (__dividend.Re *__divisor.Re +
  1043.                    __dividend.Im *__divisor.Im) /
  1044.          (denom = (double)(__divisor.Re) * __divisor.Re +
  1045.                   (double)(__divisor.Im) * __divisor.Im);
  1046.       Result.Im = (__dividend.Im * __divisor.Re -
  1047.                    __dividend.Re * __divisor.Im ) / denom;
  1048.       return Result;
  1049. }
  1050.  
  1051. template <class T>
  1052. inline VBOOL __cmf operator== (complex<T> _VFARC & __z1, complex<T> _VFARC & __z2)
  1053. {   return __z1.Re == __z2.Re && __z1.Im == __z2.Im; }
  1054.  
  1055. template <class T>
  1056. inline VBOOL __cmf operator== (T __z1Re, complex<T> _VFARC & __z2)
  1057. {   return __z1Re == __z2.Re && __z2.Im == 0; }
  1058.  
  1059. template <class T>
  1060. inline VBOOL __cmf operator== (complex<T> _VFARC & __z1, T __z2Re)
  1061. {   return __z1.Re == __z2Re && __z1.Im == 0; }
  1062.  
  1063. template <class T>
  1064. inline VBOOL __cmf operator!= (complex<T> _VFARC & __z1, complex<T> _VFARC & __z2)
  1065. {   return __z1.Re != __z2.Re || __z1.Im != __z2.Im; }
  1066.  
  1067. template <class T>
  1068. inline VBOOL __cmf operator!= (T __z1Re, complex<T> _VFARC & __z2)
  1069. {   return __z1Re != __z2.Re || __z2.Im != 0; }
  1070.  
  1071. template <class T>
  1072. inline VBOOL __cmf operator!= (complex<T> _VFARC & __z1, T __z2Re)
  1073. {   return __z1.Re != __z2Re || __z1.Im != 0; }
  1074.  
  1075.       // Compound-assignment operators:
  1076. inline complex<float> _VFAR & __cmo complex<float>::operator+= (complex<float> _VFARC & __s2)
  1077. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1078.  
  1079. inline complex<float> _VFAR & __cmo complex<float>::operator+= (complex<double> _VFARC & __s2)
  1080. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1081.  
  1082. inline complex<float> _VFAR & __cmo complex<float>::operator+= (complex<long double> _VFARC & __s2)
  1083. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1084.  
  1085. inline complex<double> _VFAR & __cmo complex<double>::operator+= (complex<float> _VFARC & __s2)
  1086. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1087.  
  1088. inline complex<double> _VFAR & __cmo complex<double>::operator+= (complex<double> _VFARC & __s2)
  1089. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1090.  
  1091. inline complex<double> _VFAR & __cmo complex<double>::operator+= (complex<long double> _VFARC & __s2)
  1092. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1093.  
  1094. inline complex<long double> _VFAR & __cmo complex<long double>::operator+= (complex<float> _VFARC & __s2)
  1095. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1096.  
  1097. inline complex<long double> _VFAR & __cmo complex<long double>::operator+= (complex<double> _VFARC & __s2)
  1098. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1099.  
  1100. inline complex<long double> _VFAR & __cmo complex<long double>::operator+= (complex<long double> _VFARC & __s2)
  1101. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1102.  
  1103. inline complex<float> _VFAR & __cmo complex<float>::operator-= (complex<float> _VFARC & __s2)
  1104. {   Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1105.  
  1106. inline complex<float> _VFAR & __cmo complex<float>::operator-= (complex<double> _VFARC & __s2)
  1107. {   Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1108.  
  1109. inline complex<float> _VFAR & __cmo complex<float>::operator-= (complex<long double> _VFARC & __s2)
  1110. {   Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1111.  
  1112. inline complex<double> _VFAR & __cmo complex<double>::operator-= (complex<float> _VFARC & __s2)
  1113. {   Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1114.  
  1115. inline complex<double> _VFAR & __cmo complex<double>::operator-= (complex<double> _VFARC & __s2)
  1116. {   Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1117.  
  1118. inline complex<double> _VFAR & __cmo complex<double>::operator-= (complex<long double> _VFARC & __s2)
  1119. {   Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1120.  
  1121. inline complex<long double> _VFAR & __cmo complex<long double>::operator-= (complex<float> _VFARC & __s2)
  1122. {    Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1123.  
  1124. inline complex<long double> _VFAR & __cmo complex<long double>::operator-= (complex<double> _VFARC & __s2)
  1125. {   Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1126.  
  1127. inline complex<long double> _VFAR & __cmo complex<long double>::operator-= (complex<long double> _VFARC & __s2)
  1128. {   Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1129.  
  1130. inline complex<float> _VFAR & __cmo complex<float>::operator*= (complex<float> _VFARC & __fac2)
  1131. {   float tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1132.     Im          = Im * __fac2.Re + Re * __fac2.Im;
  1133.     Re          = tmpRe;
  1134.     return *this;
  1135. }
  1136.  
  1137. inline complex<float> _VFAR & __cmo complex<float>::operator*= (complex<double> _VFARC & __fac2)
  1138. {   float tmpRe = (float) (Re * __fac2.Re - Im * __fac2.Im);
  1139.     Im          = (float) (Im * __fac2.Re + Re * __fac2.Im);
  1140.     Re          = tmpRe;
  1141.     return *this;
  1142. }
  1143.  
  1144. inline complex<float> _VFAR & __cmo complex<float>::operator*= (complex<long double> _VFARC & __fac2)
  1145. {   float tmpRe = (float) (Re * __fac2.Re - Im * __fac2.Im);
  1146.     Im          = (float) (Im * __fac2.Re + Re * __fac2.Im);
  1147.     Re          = tmpRe;
  1148.     return *this;
  1149. }
  1150.  
  1151. inline complex<double> _VFAR & __cmo complex<double>::operator*= (complex<float> _VFARC & __fac2)
  1152. {   double tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1153.     Im           = Im * __fac2.Re + Re * __fac2.Im;
  1154.     Re           = tmpRe;
  1155.     return *this;
  1156. }
  1157.  
  1158. inline complex<double> _VFAR & __cmo complex<double>::operator*= (complex<double> _VFARC & __fac2)
  1159. {   double tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1160.     Im           = Im * __fac2.Re + Re * __fac2.Im;
  1161.     Re           = tmpRe;
  1162.     return *this;
  1163. }
  1164.  
  1165. inline complex<double> _VFAR & __cmo complex<double>::operator*= (complex<long double> _VFARC & __fac2)
  1166. {   double tmpRe = (double) (Re * __fac2.Re - Im * __fac2.Im);
  1167.     Im           = (double) (Im * __fac2.Re + Re * __fac2.Im);
  1168.     Re           = tmpRe;
  1169.     return *this;
  1170. }
  1171.  
  1172. inline complex<long double> _VFAR & __cmo complex<long double>::operator*= (complex<float> _VFARC & __fac2)
  1173. {   long double tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1174.     Im                = Im * __fac2.Re + Re * __fac2.Im;
  1175.     Re                = tmpRe;
  1176.     return *this;
  1177. }
  1178.  
  1179. inline complex<long double> _VFAR & __cmo complex<long double>::operator*= (complex<double> _VFARC & __fac2)
  1180. {   long double tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1181.     Im                = Im * __fac2.Re + Re * __fac2.Im;
  1182.     Re                = tmpRe;
  1183.     return *this;
  1184. }
  1185.  
  1186. inline complex<long double> _VFAR & __cmo complex<long double>::operator*= (complex<long double> _VFARC & __fac2)
  1187. {   long double tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1188.     Im                = Im * __fac2.Re + Re * __fac2.Im;
  1189.     Re                = tmpRe;
  1190.     return *this;
  1191. }
  1192.  
  1193. inline complex<float> _VFAR & __cmo complex<float>::operator/= (complex<float> _VFARC & __divisor)
  1194. {     double denom;
  1195.       float  tmpRe = (float)((Re * __divisor.Re + Im * __divisor.Im) /
  1196.             (denom = (double)(__divisor.Re) * __divisor.Re +
  1197.                      (double)(__divisor.Im) * __divisor.Im));
  1198.       Im = (float)((Im * __divisor.Re - Re * __divisor.Im ) / denom);
  1199.       Re = tmpRe;
  1200.       return *this;
  1201. }
  1202.  
  1203. inline complex<double> _VFAR & __cmo complex<double>::operator/= (complex<float> _VFARC & __divisor)
  1204. {     double denom;
  1205.       double tmpRe = (double)((Re * __divisor.Re + Im * __divisor.Im) /
  1206.             (denom = (double)(__divisor.Re) * __divisor.Re +
  1207.                      (double)(__divisor.Im) * __divisor.Im));
  1208.       Im = (Im * __divisor.Re - Re * __divisor.Im ) / denom;
  1209.       Re = tmpRe;
  1210.       return *this;
  1211. }
  1212.  
  1213. inline complex<long double> _VFAR & __cmo complex<long double>::operator/= (complex<float> _VFARC & __divisor)
  1214. {     double denom;
  1215.       long double tmpRe = (Re * __divisor.Re + Im * __divisor.Im) /
  1216.                  (denom = (double)(__divisor.Re) * __divisor.Re +
  1217.                           (double)(__divisor.Im) * __divisor.Im);
  1218.       Im = (Im * __divisor.Re - Re * __divisor.Im ) / denom;
  1219.       Re = tmpRe;
  1220.       return *this;
  1221. }
  1222.  
  1223. template <class T>
  1224. inline istream _VFAR &  __cmf operator>> (istream _VFAR & is, complex<T> _VFAR & __z)
  1225. {   // read a complex number __z in the form r or (r) or {r, i} or (r, i)
  1226.     T     r = 0, i = 0;
  1227.     char  c;
  1228.  
  1229.     is >> c;
  1230.     if (c == '(' || c == '{')  // notations (r), (r,i), or {r,i}
  1231.     {
  1232.         is >> r >> c;
  1233.         if (c == ',') { is >> i  >> c;}
  1234.         if (c != ')' && c != '}')   is.clear(ios::failbit);
  1235.     }
  1236.     else  // only real part
  1237.     {
  1238.         is.putback(c);
  1239.         is >> r;
  1240.     }
  1241.     if (is) { __z.Re = r; __z.Im = i; }
  1242.     return is;
  1243. }
  1244.  
  1245. template <class T>
  1246. inline ostream _VFAR &  __cmf operator<< (ostream _VFAR & os, complex<T> _VFARC & __z)
  1247. {   return (os << "{" << __z.Re << "," << __z.Im << "}"); }
  1248.  
  1249. #endif // CMATH_CLASSIC_COMPLEX
  1250. #ifdef __BORLANDC__
  1251.       #pragma option -a.
  1252. #else /* Visual C++ */
  1253.       #pragma pack( pop )
  1254. #endif    /* restore default data packing  */
  1255.  
  1256.        // error handling functions, borrowed from VectorLib:
  1257. extern "C" {
  1258. void  __cmf  V_noteError( char _VFAR *fname, unsigned why );
  1259. void  __cmf  V_printErrorMsg( char _VFAR *ErrMsg );
  1260. void  __cmf  V_setErrorEventFile( char _VFAR *filename,  unsigned ScreenAndFile );
  1261. void  __cmf  V_closeErrorEventFile( void );
  1262.  
  1263. /*** translation of calls to matherr() into _matherr() for BorlandC 4.0+ ***
  1264.  ***  (necessary only to maintain compatibility with BorlandC 3.x)       ***/
  1265.  
  1266. #if (__BORLANDC__ >= 0x450) && !defined (__FLAT__)
  1267.      #if !defined( __MATH_H )
  1268.             #include <math.h>
  1269.      #endif
  1270.      int  _Cdecl _FARFUNC matherr (struct exception _VFAR *__e);
  1271.      #define NEWMATHERR  \
  1272.          int matherr( struct exception _VFAR *__e ) \
  1273.          {  return( _matherr( __e )); }
  1274. #else
  1275.      #define NEWMATHERR
  1276. #endif
  1277. }  // end of extern "C" statement
  1278.  
  1279. #undef VBOOL
  1280. #undef __cmf
  1281. #undef __cmo
  1282. typedef fComplex fcomplex;
  1283. typedef dComplex dcomplex;
  1284. typedef eComplex ecomplex;  // tolerate all-lower case
  1285. #endif  // __NEWCPLX_H
  1286.