CPLX.INTRO(3CC4)CPLX.INTRO(3CC4)NAMEcplx.intro complex - introduction to C++ complex number math library
SYNOPSIS
#include <complex.h>
class complex {
public:
complex(double real, double imag= 0.0);
complex();
... // remainder not shown here
};
#include <iostream.h>
ostream& operator<< (ostream&, const complex&);
istream& operator>> (istream&, complex&);
DESCRIPTION
This implementation of a complex number class and library is based on
the complex math library supplied by USL. Code written for use with
the USL library should work the same way with this implementation.
Class complex, whose definition is found in header file <complex.h>,
uses a typical Cartesian coordinate implementation of mathematical com‐
plex numbers. The class includes:
· functions to convert between polar and Cartesian coordinates. See
cartpol(3CC4).
· overloaded versions of the arithmetic operations, some of which are
optimized for combining real and complex operations. See cplx‐
ops(3CC4).
· overloaded versions of the usual trigonometric functions. See cplx‐
trig(3CC4).
· overloaded versions of the usual exponential and logarithm functions.
See cplxexp(3CC4).
· error handling which may be overridden by the user. See cplx‐
err(3CC4).
· functions to read and write complex numbers via iostreams. See
ios.intro(3CC4).
Constructors
complex()
Creates a complex number initialized to (0.0, 0.0).
complex(x, y)
Creates a complex number initialized to (x, y), where x and y
have numerical types. Argument y may be omitted, in which case
its value is taken as 0.
Input/Output
The library provides default input and output routines for complex.
Either or both of these may be replaced by the programmer by writing
functions with the same signatures. The default versions are described
here.
input_stream >> x
Expects the representation of a complex number to have the form
( real , imag )
where and are integral or floating-point numbers in standard C++
format. Any amount of whitespace may preceed or follow the
parentheses and comma. If the first non-whitespace character is
not `(', that character will be replaced in the stream and there
will be nothing further extracted. Otherwise, if the value is
not well-formed, extraction from the stream will stop as soon as
this is determined, and the stream will be put into a "failed"
state. (See the iostream documentation.) In either case, or if
there is any other error condition, complex variable x will get
the value (0,0). If the input is in the proper form, x will get
the represented complex value.
output_stream << x
Writes the value of complex x to the output stream in the form
expected by the input function as noted above.
SEE ALSOcartpol(3CC4), cplxerr(3CC4), cplxexp(3CC4), cplxops(3CC4), cplx‐
trig(3CC4), ios.intro(3CC4), intro(2), ieee_values(3M), and perror(3C).
DIAGNOSTICS
In general, one of the values (0, 0), (0, ±HUGE_VAL), (±HUGE_VAL, 0),
or (±HUGE_VAL, ±HUGE_VAL) will be returned when a result is too large
or is mathematically undefined. HUGE_VAL is defined in the header
<math.h>, which is included by <complex.h>, and in this implementation
has the value corresponding to infinity. See ieee_values(3M). When
such an error condition occurs, external variable errno is set to EDOM
or ERANGE. See perror(3C), intro(2).
08 August 2000 CPLX.INTRO(3CC4)