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