home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / INCLUDE / COMPLEX.H < prev    next >
Text File  |  1993-09-17  |  8KB  |  237 lines

  1. #pragma info( none )
  2. #ifndef __CHKHDR__
  3.    #pragma info( none )
  4. #endif
  5. #pragma info( restore )
  6.  
  7. #ifndef __complex_h
  8.    #define __complex_h
  9.  
  10.    /********************************************************************/
  11.    /*  <complex.h> header file                                         */
  12.    /*                                                                  */
  13.    /*  Licensed Materials - Property of IBM                            */
  14.    /*                                                                  */
  15.    /*  IBM C/C++ Tools Version 2.01                                    */
  16.    /*  Copyright (C) International Business Machines Corp., 1991, 1993.*/
  17.    /*  All rights reserved                                             */
  18.    /*                                                                  */
  19.    /*                                                                  */
  20.    /*                                                                  */
  21.    /*  Licensed Materials - Property of USL                            */
  22.    /*                                                                  */
  23.    /*  Standard Class Library Version 3.0                              */
  24.    /*  Copyright (C) Unix System Laboratories Inc. 1991.               */
  25.    /*  All rights reserved                                             */
  26.    /*                                                                  */
  27.    /********************************************************************/
  28.  
  29.    /**************************************************************************/
  30.    /*  C++ source for the C++ Language System, Release 3.0.  This product    */
  31.    /*  is a new release of the original cfront developed in the computer     */
  32.    /*  science research center of AT&T Bell Laboratories.                    */
  33.    /*                                                                        */
  34.    /*  Copyright (c) 1991 AT&T and UNIX System Laboratories, Inc.            */
  35.    /*  Copyright (c) 1984, 1989, 1990 AT&T.  All Rights Reserved.            */
  36.    /*                                                                        */
  37.    /*  THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE of AT&T and UNIX System   */
  38.    /*  Laboratories, Inc.  The copyright notice above does not evidence      */
  39.    /*  any actual or intended publication of such source code.               */
  40.    /*                                                                        */
  41.    /*  UNIX is a registered trademark of UNIX System Laboratories, Inc.      */
  42.    /*                                                                        */
  43.    /*  ident "@(#)C++env:incl-master/const-headers/complex.h 1.2"            */
  44.    /**************************************************************************/
  45.  
  46.    #include <iostream.h>
  47.    #include <errno.h>
  48.    #include <math.h>
  49.  
  50.    #pragma pack(4)
  51.  
  52.    #ifndef DOMAIN
  53.    #define DOMAIN          1
  54.    #endif
  55.    #ifndef SING
  56.    #define SING            2
  57.    #endif
  58.    #ifndef OVERFLOW
  59.    #define OVERFLOW        3
  60.    #endif
  61.    #ifndef UNDERFLOW
  62.    #define UNDERFLOW       4
  63.    #endif
  64.    #ifndef TLOSS
  65.    #define TLOSS           5
  66.    #endif
  67.    #ifndef PLOSS
  68.    #define PLOSS           6
  69.    #endif
  70.    #ifndef M_E
  71.    #define M_E     2.7182818284590452354
  72.    #endif
  73.    #ifndef M_LOG2E
  74.    #define M_LOG2E 1.4426950408889634074
  75.    #endif
  76.    #ifndef M_LOG10E
  77.    #define M_LOG10E        0.43429448190325182765
  78.    #endif
  79.    #ifndef M_LN2
  80.    #define M_LN2   0.69314718055994530942
  81.    #endif
  82.    #ifndef M_LN10
  83.    #define M_LN10  2.30258509299404568402
  84.    #endif
  85.    #ifndef M_PI
  86.    #define M_PI    3.14159265358979323846
  87.    #endif
  88.    #ifndef M_PI_2
  89.    #define M_PI_2  1.57079632679489661923
  90.    #endif
  91.    #ifndef M_PI_4
  92.    #define M_PI_4  0.78539816339744830962
  93.    #endif
  94.    #ifndef M_1_PI
  95.    #define M_1_PI  0.31830988618379067154
  96.    #endif
  97.    #ifndef M_2_PI
  98.    #define M_2_PI  0.63661977236758134308
  99.    #endif
  100.    #ifndef M_2_SQRTPI
  101.    #define M_2_SQRTPI      1.12837916709551257390
  102.    #endif
  103.    #ifndef M_SQRT2
  104.    #define M_SQRT2 1.41421356237309504880
  105.    #endif
  106.    #ifndef M_SQRT1_2
  107.    #define M_SQRT1_2       0.70710678118654752440
  108.    #endif
  109.  
  110.    class complex {
  111.            double  re, im;
  112.    public:
  113.            complex()       { re=0.0; im=0.0; }
  114.            complex(double r, double i = 0.0)       { re=r; im=i; }
  115.  
  116.            friend  inline  double  real(const complex&);
  117.            friend  inline  double  imag(const complex&);
  118.  
  119.            friend  double  abs(complex);
  120.            friend  double  norm(complex);
  121.            friend  double  arg(complex);
  122.            friend  inline  complex conj(complex);
  123.            friend  complex cos(complex);
  124.            friend  complex cosh(complex);
  125.            friend  complex exp(complex);
  126.            friend  complex log(complex);
  127.            friend  complex pow(double, complex);
  128.            friend  complex pow(complex, int);
  129.            friend  complex pow(complex, double);
  130.            friend  complex pow(complex, complex);
  131.            friend  complex polar(double, double = 0);
  132.            friend  complex sin(complex);
  133.            friend  complex sinh(complex);
  134.            friend  complex sqrt(complex);
  135.  
  136.            friend  inline  complex operator+(complex, complex);
  137.            friend  inline  complex operator-(complex);
  138.            friend  inline  complex operator-(complex, complex);
  139.            friend  complex operator*(complex, complex);
  140.            friend  complex operator/(complex, complex);
  141.            friend  inline  int     operator==(complex, complex);
  142.            friend  inline  int     operator!=(complex, complex);
  143.  
  144.            void operator+=(complex);
  145.            void operator-=(complex);
  146.            void operator*=(complex);
  147.            void operator/=(complex);
  148.    };
  149.  
  150.    ostream& operator<<(ostream&, complex);
  151.    istream& operator>>(istream&, complex&);
  152.  
  153.    inline double real(const complex& a)
  154.    {
  155.            return a.re;
  156.    }
  157.  
  158.    inline double imag(const complex& a)
  159.    {
  160.            return a.im;
  161.    }
  162.  
  163.    inline complex operator+(complex a1, complex a2)
  164.    {
  165.            return complex(a1.re+a2.re, a1.im+a2.im);
  166.    }
  167.  
  168.    inline complex operator-(complex a1,complex a2)
  169.    {
  170.            return complex(a1.re-a2.re, a1.im-a2.im);
  171.    }
  172.  
  173.    inline complex operator-(complex a)
  174.    {
  175.            return complex(-a.re, -a.im);
  176.    }
  177.  
  178.    inline complex conj(complex a)
  179.    {
  180.            return complex(a.re, -a.im);
  181.    }
  182.  
  183.    inline int operator==(complex a, complex b)
  184.    {
  185.            return (a.re==b.re && a.im==b.im);
  186.    }
  187.  
  188.    inline int operator!=(complex a, complex b)
  189.    {
  190.            return (a.re!=b.re || a.im!=b.im);
  191.    }
  192.  
  193.    inline void complex::operator+=(complex a)
  194.    {
  195.            re += a.re;
  196.            im += a.im;
  197.    }
  198.  
  199.    inline void complex::operator-=(complex a)
  200.    {
  201.            re -= a.re;
  202.            im -= a.im;
  203.    }
  204.  
  205.    extern const complex complex_zero;
  206.  
  207.    class c_exception
  208.    {
  209.            int     type;
  210.            char    *name;
  211.            complex arg1;
  212.            complex arg2;
  213.            complex retval;
  214.    public:
  215.  
  216.            c_exception( char *n, const complex& a1, const complex& a2 = complex_zero )
  217.                 : name(n), arg1(a1), arg2(a2), type(0) { }
  218.  
  219.            friend int complex_error( c_exception& );
  220.  
  221.            friend complex exp( complex );
  222.            friend complex sinh( complex );
  223.            friend complex cosh( complex );
  224.            friend complex log( complex );
  225.    };
  226.  
  227.    #pragma pack()
  228.  
  229. #endif
  230.  
  231. #pragma info( none )
  232. #ifndef __CHKHDR__
  233.    #pragma info( restore )
  234. #endif
  235. #pragma info( restore )
  236.  
  237.