DEC C++

DEC C++

Class Library Reference Manual

Order Number: AA–PM9XD–TE


March 1996

This document describes a library of C++ classes.

Revision/Update Information: This is a revised manual.

Software Version: DEC C++ Version 5.3 for Digital UNIX
DEC C++ Class Library Version 4.0


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.

Copyright ©1992, 1996

The following are trademarks of Digital Equipment Corporation: DEC, Digital, DECthreads, Ladebug, ULTRIX, VAX, VAX DOCUMENT, OpenVMS, the DEC C++ logo, and the DIGITAL logo.

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.

0

This document is available on CD–ROM.

This document was prepared using VAX DOCUMENT, Version V3.2-1a.

Contents Index


Preface

This manual describes the library of classes supplied with DEC C++ Version 5.3 for Digital UNIX systems. It contains detailed information on members of these classes (including member functions) and information on other associated functions, variables, and macros.

Intended Audience

This manual is intended for experienced programmers who have a basic understanding of the C++ language, and who are using DEC C++ with the Digital UNIX operating system in either a single or multiple platform environment. Some familiarity with the operating system is assumed.

Document Structure

This manual consists of an introductory chapter and 10 chapters describing each of the packages of predefined classes supplied with DEC C++ for Digital UNIX systems.

DEC C++ Documents

The following documents are provided in the DEC C++ documentation set:
Stroustrup, The C++ Programming Language, 2nd Edition, Addison-Wesley, 1992 Provides an exhaustive introduction to the C++ programming language, and includes the text but not the annotation of The Annotated C++ Reference Manual.
Using DEC C++ for Digital UNIX Systems Describes the specifics of Digital's C++ implementation.
DEC C++ Installation Guide for Digital UNIX Systems Describes how to install DEC C++ on your system.
DEC C++ Command Reference Pages Provides references for DEC C++ commands and libraries.
Musser and Saini, STL Tutorial and Reference Guide, Addison-Wesley, 1995 Describes how to use the Standard Templates Library (STL).

Related Documents

The following documents are not included in the DEC C++ documentation set; refer to them for additional information about the C++ programming language, DEC C, or Digital UNIX programming.
The Annotated C++ Reference Manual Contains the definitive language description of C++. The core text is the same as in the "r" section of The C++ Programming Language, 2nd Edition, but with additional annotation and commentary.
Digital UNIX Guide to Languages and Programming Describes the programming environment, languages, and tools for Digital UNIX systems.
DEC C User's Guide for Digital UNIX Systems Provides information on using the DEC C preprocessor, the DEC C compiler, and the ld linker to compile and run C programs on a Digital UNIX system.
Digital UNIX
Programmer's Guide
Describes the programming environment for Digital UNIX.
DEC C Language Reference Manual Provides a complete technical description of the C language, as specified by the ANSI X3J11 committee. This manual also fully describes all extensions to this standard implemented in DEC C.
Ladebug Debugger Manual Describes how to use Digital's Ladebug debugger.

Conventions

Table 1 lists the conventions used in this manual.

Table 1 Conventions Used in this Manual
Convention Description
class complex{
.
.
.
};
A vertical ellipsis indicates that some intervening program code or output is not shown. Only the more pertinent material is shown in the example.
,... A horizontal ellipsis in a syntax description indicates that you can enter additional parameters, options, or values. A comma preceding the ellipsis indicates that successive items must be separated by commas.
The complex class...
The get() function...
Monospaced type denotes the names of DEC C++ language elements, and also the names of classes, members, and nonmembers. Monospaced type is also used in text to reference code elements displayed in examples.
italic Italic type denotes the names of variables that appear as parameters or in arguments to functions.
boldface Boldface type in text indicates the first instance of terms defined in text.
UPPERCASE
lowercase
The Digital UNIX operating system differentiates between uppercase and lowercase characters. Literal strings that appear in examples, syntax descriptions, and function definitions must be typed exactly as shown.

Reader's Comments

You may send your comments or suggestions regarding this manual, or any DEC C++ document, by electronic mail to the following Internet address:

cxx_docs@casdoc.enet.dec.com


Chapter 1
Overview

The DEC C++ Class Library is a set of headers and other files implementing a collection of basic C++ classes. In the library, these classes are arranged in functionally related groups called packages.

The DEC C++ Class Library makes use of other run-time libraries. To ensure that all necessary libraries are linked into the executable image, certain switches need to be provided to the linker through the cxx command. For detailed information on the switches to use, see Using DEC C++ for Digital UNIX Systems.

Note

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.

1.1 Thread Safe Programming

Developers of multithreaded applications should note the following:


Chapter 2
complex Package

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 DEC C++ for Digital UNIX Systems.


Global Declarations

These declarations are used by the complex package but they are not members of the complex class.

HEADER

#include <complex.hxx>

Alternative Header

#include <complex.h>


DECLARATIONS


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); 


TYPE

cxxl_p_complex_error_t

Is the type of the complex_error function.

DATA

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.

FUNCTION

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.


complex class

Provides a representation of, and lets you perform operations on, complex values.

HEADER

#include <complex.hxx>

Alternative Header

#include <complex.h>


DECLARATION


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 
    friend complex   exp(const complex &); // c_exception OVERFLOW UNDERFLOW 
    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 &); 
}; 


DESCRIPTION

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.

EXCEPTION HANDLING

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).


CONSTRUCTORS AND DESTRUCTORS

complex()

Constructs and initializes a complex value to 0.

complex(double x, double y = 0)

Constructs and initializes a complex value from Cartesian coordinates.

OVERLOADED OPERATORS

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:

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.

OTHER FUNCTIONS

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 symbol> .

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 symbol> , and less than or equal to <pi symbol> .

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.

Examples

#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.


c_exception class

Contains information on a complex arithmetical exception.

HEADER

#include <complex.hxx>

Alternative Header


Next Contents Index