Updated: 21 April 1999 |
DEC C++Class Library Reference ManualOrder Number: AA-PM9XD-TE
March 1996
This document describes a library of C++ classes. Revision/Update Information: This is a revised manual.
Software Version:
C++ Version 5.3
Compaq Computer Corporation
First Printing, September 1992 First Revision, June 1993 Second Revision, April 1996 First Printing, February 1992 First Revision, December 1992 Second Revision, March 1996 The information in this document is subject to change without notice and should not be construed as a commitment by Digital Equipment Corporation. Digital Equipment Corporation assumes no responsibility for any errors that may appear in this document. The software described in this document is furnished under a license and may be used or copied only in accordance with the terms of such license. No responsibility is assumed for the use or reliability of software on equipment that is not supplied by Digital Equipment Corporation or its affiliated companies. Restricted Rights: Use, duplication, or disclosure by the U.S. Government is subject to restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer Software clause at DFARS 252.227-7013. ©1992-1999 Digital Equipment Corporation Compaq, the Compaq logo, and Alpha, DEC, DEC FUSE, DECthreads, DIGITAL, OpenVMS, ULTRIX, VAX, VMS are Registered in U.S. Patent and Trademark Office. Compaq. the Compaq logo, and Alpha, DEC, DEC FUSE, DECthreads, DIGITAL, Ladebug, OpenVMS, Tru64 UNIX. ULTRIX, VAX, VMS are Registered in U.S. Patent and Trademark Office. The following are third-party trademarks: AT&T is a registered trademark of American Telephone & Telegraph Company. UNIX is a registered trademark in the United States and other countries, licensed exclusively through X/Open Company, Ltd. This document is available on CD-ROM.
PrefaceThis manual describes the library of classes supplied with C++ Version 5.3 for Compaq Tru64 UNIX systems. It contains detailed information on members of these classes (including member functions) and information on other associated functions, variables, and macros. Intended AudienceThis manual is intended for experienced programmers who have a basic understanding of the C++ language, and who are using C++ with the Compaq Tru64 UNIX operating system in either a single or multiple platform environment. Some familiarity with the operating system is assumed. Document StructureThis manual consists of an introductory chapter and 10 chapters describing each of the packages of predefined classes supplied with the C++ compiler. C++ DocumentsThe following documents are provided in the C++ documentation set:
Related DocumentsThe following documents are not included in the C++ documentation set; refer to them for additional information about the C++ programming language, C, or Compaq Tru64 UNIX programming.
ConventionsTable 1 lists the conventions used in this manual.
Reader's CommentsYou may send your comments or suggestions regarding this manual, or any C++ document, by electronic mail to the following Internet address:
Chapter 1
|
Identifiers beginning with cxxl or CXXL are reserved for the DEC C++ Class Library and should not be used by customer programs except as specified in this manual. |
Developers of multithreaded applications should note the following:
The complex package provides ways to perform arithmetical operations, such as initialization, assignment, input, and output, on complex values (that is, numbers with a real part and an imaginary part). Additionally, this package supports operations that are unique to complex values, such as principal argument operations, conjugate operations, and conversions to and from polar coordinates.
With the c_exception class and its c_exception function, the complex package also provides a mechanism for reporting and handling complex arithmetical errors.
The complex package makes use of other packages. To ensure that all necessary libraries are linked into the executable program image, certain switches need to be provided to the linker through the cxx command. For detailed information on the switches to use, see Using Compaq C++ for Tru64 UNIX.
These declarations are used by the complex package but they are not members of the complex class.
#include <complex.hxx>Alternative Header
#include <complex.h>
typedef int (*cxxl_p_complex_error_t)(c_exception &error_information); static const complex_zero (0, 0); cxxl_p_complex_error_t set_complex_error(cxxl_p_complex_error_t p_complex_error);
cxxl_p_complex_error_t
Is the type of the complex_error function.
static const complex_zero (0, 0)
Is a constant object of type complex and value 0 created in each module that uses the complex package.
cxxl_p_complex_error_t set_complex_error (cxxl_p_complex_error_t p_complex_error)
Causes the function pointed to by p_complex_error to be called instead of the complex_error function on subsequent complex arithmetical errors. If set_complex_error() previously has not been called, then it returns 0; otherwise, it returns the address of the last function passed to it.See the Other Function section of c_exception class for a description of the error-handling function.
Provides a representation of, and lets you perform operations on, complex values.
#include <complex.hxx>Alternative Header
#include <complex.h>
class complex { friend complex polar(double, double = 0); friend double abs(const complex &); friend double norm(const complex &); friend double arg(const complex &); friend double arg1(const complex &); friend complex conj(const complex &); friend complex sin(const complex &); friend complex sinh(const complex &); // c_exception OVERFLOW friend complex cos(const complex &); friend complex cosh(const complex &); // c_exception OVERFLOW friend complex tan(const complex &); friend complex tanh(const complex &); friend double imag(const complex &); friend double real(const complex &); friend complex log(const complex &); // c_exception SING // c_exception OVERFLOW UNDERFLOW friend complex exp(const complex &); friend complex pow(double, const complex &); friend complex pow(const complex &, int); friend complex pow(const complex &, double); friend complex pow(const complex &, const complex &); friend complex sqrt(const complex &); friend complex sqr(const complex &); friend complex operator-(const complex &); friend complex operator+(const complex &, const complex &); friend complex operator-(const complex &, const complex &); friend complex operator*(const complex &, const complex &); friend complex operator/(const complex &, const complex &); friend int operator==(const complex &, const complex &); friend int operator!=(const complex &, const complex &); friend ostream &operator<<(ostream &, const complex &); friend istream &operator>>(istream &, complex &); public: complex(double, double = 0); complex(); inline complex &operator-=(const complex &); inline complex &operator+=(const complex &); complex &operator*=(const complex &); complex &operator/=(const complex &); };
This class contains methods to perform complex value operations. These include arithmetical, assignment, and comparison operators for complex values; Cartesian and polar coordinates; mixed-mode arithmetic; and mathematical functions for complex values equivalent to standard mathematical functions.
When a complex arithmetical error is detected, a c_exception object is created with one of the following values for type:
Value Error Description OVERFLOW Value too large to be represented SING Function undefined for argument UNDERFLOW Value too small to be represented This object is then passed to the complex_error function (see the c_exception class).
complex()
Constructs and initializes a complex value to 0.complex(double x, double y = 0)
Constructs and initializes a complex value from Cartesian coordinates.
complex operator + (const complex &z1, const complex &z2)
Returns the arithmetical sum of the complex values z1 and z2.complex operator -- (const complex &z1)
Returns the arithmetical negation of a complex value.complex operator -- (const complex &z1, const complex &z2)
Returns the arithmetical difference of complex values. That is, z2 is subtracted from z1.complex operator * (const complex &z1, const complex &z2)
Returns the arithmetical product of the complex values z1 and z2.complex operator / (const complex &z1, const complex &z2)
Returns the arithmetical quotient of complex values. That is, z1 is divided by z2.inline complex &operator += (const complex &z1)
Assigns the arithmetical sum of complex values to the complex object on the left side of an equation. That is, z1+=z2 is equivalent to z1=z1+z2.inline complex &operator --= (const complex &z1)
Assigns the arithmetical difference of two complex numbers to the complex object on the left side of an equation. That is, z1--=z2 is equivalent to z1=z1--z2.complex &operator *= (const complex &z2)
Assigns the arithmetical product of two complex numbers to the complex object on the left side of an equation. That is, z1*=z2 is equivalent to z1=z1*z2.complex &operator /= (const complex &z2)
Assigns the arithmetical quotient of two complex numbers to the complex object on the left side of an equation. That is, z1/=z2 is equivalent to z1=z1/z2.ostream &operator << (ostream &s, const complex &z1)
Sends a complex value to an output stream in the format (real,imag). It returns the left argument s.istream &operator >> (istream &s, complex &z1)
Takes a complex value from an input stream. The numbers may be of the forms (real,imag) or (real), where real and imag are what the iostream library accepts for parameters of type double. The iostream library also determines how to handle white space. This operator returns the left argument s. The following input format omissions will cause an error:
- Parenthesis missing before a complex value
- Comma missing before the imaginary part of a complex value, if any
- Parenthesis missing after the complex value
int operator :=,= (const complex &z1, const complex &z2)
Compares two complex values and returns a nonzero value if the two numbers are equal; otherwise, it returns 0.int operator != (const complex &z1, const complex &z2)
Compares two complex values and returns a nonzero value if the two numbers are not equal; otherwise, it returns 0.
double abs(const complex &z1)
Returns the absolute value (magnitude) of a complex value.double arg(const complex &z1)
Returns the angle, in radians, of a complex value. The result is normalized such that it is greater than or equal to 0, and less than 2*Pi sign .double arg1(const complex &z1)
Returns the principal value of the angle, in radians, of a complex value. The result is normalized such that it is greater than -Pi sign , and less than or equal to Pi sign .complex conj(const complex &z1)
Returns the conjugate of a complex value; that is, if the number is
(real, imag), then the result is (real, -imag).complex cos(const complex &z1)
Returns the cosine of a complex value.complex cosh(const complex &z1)
Returns the hyperbolic cosine of a complex value. The value of real(z1) must be small enough so that exp(real(z1)) does not overflow; otherwise, the function creates a c_exception object and invokes the complex_error function.complex exp(const complex &z1)
Returns the value of e (2.71828...) raised to the power of a complex value. The conditions described for cosh() must be met; otherwise, it creates a c_exception object and invokes the complex_error function.double imag(const complex &z1)
Returns the imaginary part of a complex value.complex log(const complex &z1)
Returns the natural logarithm (base e, 2.71828...) of a complex value. The conditions described for cosh() must be met; otherwise, it creates a c_exception object and invokes the complex_error function.double norm(const complex &z1)
Returns the square of the absolute value (magnitude) of a complex value.complex polar(double rho, double theta = 0)
Creates a complex value given a pair of polar coordinates (magnitude rho and angle theta, in radians).complex pow(const complex &z1, int i2)
Returns the value of z1 raised to the power of i2.complex pow(const complex &z1, double x2)
Returns the value of z1 raised to the power of x2.complex pow(double z1, const complex &z2)
Returns the value of z1 raised to the power of z2.complex pow(const complex &z1, const complex &z2)
Returns the value of z1 raised to the power of z2.double real(const complex &z1)
Returns the real part of a complex value.complex sin(const complex &z1)
Returns the sine of a complex value.complex sinh(const complex &z1)
Returns the hyperbolic sine of a complex value. The conditions described for cosh() must be met; otherwise, it creates a c_exception object and invokes the complex_error function.complex sqr(const complex &z1)
Returns the square of a complex value.complex sqrt(const complex &z1)
Returns the square root of a complex value.complex tan(const complex &z1)
Returns the tangent of a complex value.complex tanh(const complex &z1)
Returns the hyperbolic tangent of a complex value. The conditions described for cosh() must be met; otherwise, it creates a c_exception object and invokes the complex_error function.
#1 |
---|
complex zz(3,-5); |
Declares zz to be a complex object and initializes it to the value of real part 3 and imaginary part -5.
#2 |
---|
complex myarray[30]; |
Declares an array of 30 complex objects, all initialized to (0,0).
#3 |
---|
complex zz; while (!(cin >> zz).eof()) cout << zz << endl; |
Reads a stream of complex values [for example, (3.400000,5.000000)] and writes them in the default format [for example, (3.4, 5)].
#4 |
---|
complex cc = complex (3.4,5); cout << real(cc) << "+" << imag(cc) << "*i"; |
Prints out 3.4 as the real part of a complex object and 5 as the imaginary part. The result is 3.4+5*i.
Next | Contents | Index |
Legal |