[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

 

Chapter 11.

 

26 Numerics Library



This chapter is a reference guide to the ANSI/ISO standard Numeric classes which are used to perform the semi-numerical operations.


Overview of Numerics Library

The Numerics Library consist of


26.1 Numeric type requirements

The complex and valarray components are parameterized by the type of information they contain and manipulate.

A C + + program shall instantiate these components only with a type TYPE that satisfies the following requirements:

Tis not an abstract class (it has no pure virtual member functions);

Destruction of an object, followed by initialization of its raw storage using the copy constructor, is semantically equivalent to assignment to the original object.

If TYPE is a class, it shall not overload unary operator&.

If an operation on TYPE throws an exception then the effects are undefined.

Specific classes member functions or general functions may have other restrictions.


26.2 Complex Class Library

The header <complex> defines classes, operators, and functions for representing and manipulating complex numbers

The topics in this section are:


_MSL_CX_LIMITED_RANGE

This flag effects the * and / operators of complex.

When defined, the "normal" formulas for multiplication and division are used. They may execute faster on some machines. However, infinities will not be properly calculated, and there is more roundoff error potential.

If the flag is undefined (default), then more complicated algorithms (from the C standard) are used which have better overflow and underflow characteristics and properly propagate infinity. Flipping this switch requires recompilation of the C++ library.


NOTE

It is recommend that the ansi_prefix.xxx.h is the place to define this flag if you want the simpler and faster multiplication and division algorithms.



Header <complex>

The header <complex> defines classes, operators, and functions for representing and manipulating complex numbers

Header <complex> forward declarations:


namespace std {
// forward declarations
template<class T> class complex;
template<> class complex<float>; 
template<> class complex<double>; 
template<> class complex<long double>; 


26.2.6 operators: 
template<class T> complex<T> operator+
		const complex<T>&, const complex<T>&);
template<class T> complex<T> operator+
		(const complex<T>&, const T&);
template<class T> complex<T> operator+
		(const T&, const complex<T>&);
template<class T> complex<T> operator- 
		(const complex<T>&, const complex<T>&); 
template<class T> complex<T> operator-
		(const complex<T>&, const T&);
template<class T> complex<T> operator-
		(const T&, const complex<T>&);
template<class T> complex<T> operator* 
		(const complex<T>&, const complex<T>&); 
template<class T> complex<T> operator*
		(const complex<T>&, const T&);
template<class T> complex<T> operator*
		(const T&, const complex<T>&);
template<class T> complex<T> operator/ 
		(const complex<T>&, const complex<T>&); 
template<class T> complex<T> operator/
		(const complex<T>&, const T&);
template<class T> complex<T> operator/
		(const T&, const complex<T>&);
template<class T> complex<T> operator+
		(const complex<T>&);
template<class T> complex<T> operator-
		(const complex<T>&);
template<class T> bool operator== 
		(const complex<T>&, const complex<T>&); 
template<class T> bool operator==
		(const complex<T>&, const T&);
template<class T> bool operator==
		(const T&, const complex<T>&);
template<class T> bool operator!=
		(const complex<T>&, const complex<T>&);
template<class T> bool operator!=
		(const complex<T>&, const T&);
template<class T> bool operator!=
		(const T&, const complex<T>&);
template<class T, class charT, class traits>
basic_istream<charT, traits>& operator>>
		(basic_istream<charT, traits>&, complex<T>&);
template<class T, class charT, class traits>
basic_ostream<charT, traits>& operator<<
		(basic_ostream<charT, traits>&, const complex<T>&);


26.2.7 values: 
template<class T> T real(const complex<T>&);
template<class T> T imag(const complex<T>&);
template<class T> T abs(const complex<T>&);
template<class T> T arg(const complex<T>&);
template<class T> T norm(const complex<T>&);
template<class T> complex<T> conj(const complex<T>&);
template<class T> complex<T> polar(const T&, const T&);


26.2.8 transcendentals: 
template<class T> complex<T> cos (const complex<T>&);
template<class T> complex<T> cosh (const complex<T>&);
template<class T> complex<T> exp (const complex<T>&);
template<class T> complex<T> log (const complex<T>&);
template<class T> complex<T> log10(const complex<T>&);
template<class T> complex<T> pow(const complex<T>&, int);
template<class T> complex<T> pow(const complex<T>&, const T&);
template<class T> complex<T> pow
		(const complex<T>&, const complex<T>&);
template<class T> complex<T> pow(const T&, const complex<T>&);
template<class T> complex<T> sin (const complex<T>&);
template<class T> complex<T> sinh (const complex<T>&);
template<class T> complex<T> sqrt (const complex<T>&);
template<class T> complex<T> tan (const complex<T>&);
template<class T> complex<T> tanh (const complex<T>&);
template <class T> complex<T> acos(const complex<T>& x);
template <class T> complex<T> asin(const complex<T>& x);
template <class T> complex<T> atan(const complex<T>& x);
template <class T> complex<T> acosh(const complex<T>& x);
template <class T> complex<T> asinh(const complex<T>& x);
template <class T> complex<T> atanh(const complex<T>& x);
}


Template Class Complex
namespace std {
template<class T>
class complex {
public:
typedef T value_type;
complex(const T& re = T(), const T& im = T());
complex(const complex&);
template<class X> complex(const complex<X>&);
T real() const;
T imag() const;
complex<T>& operator= (const T&);
complex<T>& operator+=(const T&);
complex<T>& operator-=(const T&);
complex<T>& operator*=(const T&);
complex<T>& operator/=(const T&);
complex& operator=(const complex&);
template<class X> complex<T>& operator= (const complex<X>&);
template<class X> complex<T>& operator+=(const complex<X>&);
template<class X> complex<T>& operator-=(const complex<X>&);
template<class X> complex<T>& operator*=(const complex<X>&);
template<class X> complex<T>& operator/=(const complex<X>&);
};
template<class T> complex<T> operator+ 
		(const complex<T>&, const complex<T>&);
template<class T> complex<T> operator+
		(const complex<T>&, const T&);
template<class T> complex<T> operator+
		(const T&, const complex<T>&);
template<class T> complex<T> operator- 
		(const complex<T>&, const complex<T>&); 
template<class T> complex<T> operator-
		(const complex<T>&, const T&);
template<class T> complex<T> operator-
		(const T&, const complex<T>&);
template<class T> complex<T> operator* 
		(const complex<T>&, const complex<T>&); 
template<class T> complex<T> operator*
		(const complex<T>&, const T&);
template<class T> complex<T> operator*
		(const T&, const complex<T>&);
template<class T> complex<T> operator/ 
		(const complex<T>&, const complex<T>&); 
template<class T> complex<T> operator/
		(const complex<T>&, const T&);
template<class T> complex<T> operator/
		(const T&, const complex<T>&);
template<class T> complex<T> operator+
		(const complex<T>&); 
template<class T> complex<T> operator-
		(const complex<T>&); 
template<class T> bool operator==
		(const complex<T>&, const complex<T>&); 
template<class T> bool operator==
		(const complex<T>&, const T&); 
template<class T> bool operator==
		(const T&, const complex<T>&); 
template<class T> bool operator!=
		(const complex<T>&, const complex<T>&); 
template<class T> bool operator!=
		(const complex<T>&, const T&); 
template<class T> bool operator!=
		(const T&, const complex<T>&); 
template<class T, class charT, class traits> 
basic_istream<charT, traits>& operator>>
		(basic_istream<charT, traits>&, complex<T>&); 
template<class T, class charT, class traits> 
basic_ostream<charT, traits>& operator<<
		(basic_ostream<charT, traits>&, const complex<T>&); 
};


26.2.3 Complex Specializations

The standard specialize the template complex class for float, double and long double types.

Float specializations:


template<> class complex<float> { 
public:
typedef float value_type;
complex(float re = 0.0f, float im = 0.0f);
explicit complex(const complex<double>&);
explicit complex(const complex<long double>&);
float real() const;
float imag() const;
complex<float>& operator= (float);
complex<float>& operator+=(float);
complex<float>& operator-=(float);
complex<float>& operator*=(float);
complex<float>& operator/=(float);
complex<float>& operator=(const complex<float>&);
template<class X> complex<float>& operator= (const complex<X>&);
template<class X> complex<float>& operator+=(const complex<X>&);
template<class X> complex<float>& operator-=(const complex<X>&);
template<class X> complex<float>& operator*=(const complex<X>&);
template<class X> complex<float>& operator/=(const complex<X>&);
};

Double specializations:
template<> class complex<double> { 
public:
typedef double value_type;
complex(double re = 0.0, double im = 0.0);
complex(const complex<float>&);
explicit complex(const complex<long double>&);
double real() const;
double imag() const;
complex<double>& operator= (double);
complex<double>& operator+=(double);
complex<double>& operator-=(double);
complex<double>& operator*=(double);
complex<double>& operator/=(double);
complex<double>& operator=(const complex<double>&);
template<class X> complex<double>& operator= (const complex<X>&);
template<class X> complex<double>& operator+=(const complex<X>&);
template<class X> complex<double>& operator-=(const complex<X>&);
template<class X> complex<double>& operator*=(const complex<X>&);
template<class X> complex<double>& operator/=(const complex<X>&);
};

Long Double specializations:
template<> class complex<long double> { 
public:
typedef long double value_type;
complex(long double re = 0.0L, long double im = 0.0L);
complex(const complex<float>&);
complex(const complex<double>&);
long double real() const;
long double imag() const;
complex<long double>& operator=(const complex<long double>&);
complex<long double>& operator= (long double); 
complex<long double>& operator+=(long double); 
complex<long double>& operator-=(long double); 
complex<long double>& operator*=(long double); 
complex<long double>& operator/=(long double); 
template<class X> complex<long double>& operator= 
		(const complex<X>&);
template<class X> complex<long double>& operator+=
		(const complex<X>&);
template<class X> complex<long double>& operator-=
		(const complex<X>&);
template<class X> complex<long double>& operator*=
		(const complex<X>&);
template<class X> complex<long double>& operator/=
		(const complex<X>&);
};


Complex Template Class

The template class complex contains Cartesian components real and imag for a complex number.

Remarks:

The effect of instantiating the template complex for any type other than float, double or long double is unspecified.

If the result of a function is not mathematically defined or not in the range of representable values for its type, the behavior is undefined.

The complex class consists of:


Constructors and Assignments

Constructor, destructor and assignment operators and functions.


Constructors

Description:

Construct an object of a complex class.

Prototype:

complex(const T& re = T(), const T& im = T());


complex(const complex&);


template<class X> complex(const complex<X>&);
Remarks:

After construction real equal re and imag equals im.


Assignment Operator

Description:

An assignment operator for complex classes.

Prototype:

complex<T>& operator= (const T&);


complex& operator= (const complex&);


template<class X> complex<T>& operator= 
  (const complex<X>&);
Remarks:

Assigns a floating point type to the Cartesian complex class.


Complex Member Functions

There are two public member functions


real

Description:

Retrieves the real component.

Prototype:

T real() const;

imag

Description:

Retrieves the imag component.

Prototype:

T imag() const;

Operators

Several assignment operators are overloaded for the complex class manipulations.


operator +=

Description:

Adds and assigns to a complex class.

Prototype:

complex<T>& operator+=(const T&);


template<class X> complex<T>& operator+=
  (const complex<X>&);
Remarks:

The first operator with a scalar argument adds the scalar value of the right hand side to the real component and stores the result in the object. The imaginary component is left alone.

The second operator with a complex type, adds the complex value of the right hand side to the object and stores the resultant in the object.

Returns:

The this pointer is returned.


operator -=

Description:

Subtracts and assigns from a complex class.

Prototype:

complex<T>& operator-=(const T&);


template<class X> complex<T>& operator-=
  (const complex<X>&);
Remarks:

The first operator with a scalar argument subtracts the scalar value of the right hand side from the real component and stores the result in the object. The imaginary component is left alone.

The second operator with a complex type, subtracts the complex value of the right hand side from the object and stores the resultant in the object.

Returns:

The this pointer is returned.


operator *=

Description:

Multiplies by and assigns to a complex class.

Prototype:

complex<T>& operator*=(const T&);


template<class X> complex<T>& operator*=
  (const complex<X>&);
Remarks:

The first operator with a scalar argument multiplies the scalar value of the right hand side to class object and stores result in the object.

The second operator with a complex type, multiplies the complex value of the right hand side to the object and stores the resultant in the object.

Returns:

The this pointer is returned.


operator /=

Description:

Divides by and assigns to a complex class.

Prototype:

complex<T>& operator/=(const T&);


template<class X> complex<T>& operator/=
  (const complex<X>&);
Remarks:

The first operator with a scalar argument divides the scalar value of the right hand side to class object and stores result in the object.

The second operator with a complex type, divides the complex value of the right hand side into the object and stores the resultant in the object.

Returns:

The this pointer is returned.


Overloaded Operators and Functions

There are several non member functions and overloaded operators in the complex class library.

"Complex Operators"

"Complex Value Operations"

"Complex Transcendentals"


Complex Operators

The overloaded complex operators consists of:


operator +

Description:

Adds to the complex class.

Prototype:

template<class T> complex<T> operator+
  const complex<T>&, const complex<T>&);
template<class T> complex<T> operator+
  (const complex<T>&, const T&);
template<class T> complex<T> operator+
  (const T&, const complex<T>&);
  
template<class T> complex<T> operator+
  (const complex<T>&);
Remarks:

The addition performs an += operation.

Returns:

The complex class after the addition.


operator -

Description:

Subtracts from the complex class.

Prototype:

template<class T> complex<T> operator- 
  (const complex<T>&, const complex<T>&);
template<class T> complex<T> operator-
  (const complex<T>&, const T&);
template<class T> complex<T> operator-
  (const T&, const complex<T>&);
  
template<class T> complex<T> operator-
  (const complex<T>&);
Remarks:

The subtraction performs a -= operation.

Returns:

The complex class after the Subtraction.


operator *

Description:

Multiplies the complex class.

Prototype:

template<class T> complex<T> operator* 
  (const complex<T>&, const complex<T>&);
template<class T> complex<T> operator*
  (const complex<T>&, const T&);
template<class T> complex<T> operator*
  (const T&, const complex<T>&);
Remarks:

The multiplication performs a *= operation.

Returns:

The complex class after the multiplication.


operator /

Description:

Divides from the complex class.

Prototype:

template<class T> complex<T> operator/ 
  (const complex<T>&, const complex<T>&);
template<class T> complex<T> operator/
  (const complex<T>&, const T&);
template<class T> complex<T> operator/
  (const T&, const complex<T>&);
Remarks:

The division performs an /= operation.

Returns:

The complex class after the division.


operator ==

Description:

A boolean equality comparison.

Prototype:

template<class T> bool operator== 
  (const complex<T>&, const complex<T>&);
template<class T> bool operator==
  (const complex<T>&, const T&);
template<class T> bool operator==
  (const T&, const complex<T>&);
Remarks:

Returns true if the real and the imaginary components are equal.


operator!=

Description:

A boolean non equality comparison.

Prototype:

template<class T> bool operator!=
  (const complex<T>&, const complex<T>&);
template<class T> bool operator!=
  (const complex<T>&, const T&);
template<class T> bool operator!=
  (const T&, const complex<T>&);
Remarks:

Returns true if the real or the imaginary components are not equal.


operator >>

Description:

Extracts a complex type from a stream.

Prototype:

template<class T, class charT, class traits>


basic_istream<charT, traits>& operator>>
  (basic_istream<charT, traits>&, complex<T>&);
Remarks:

Extracts in the form of u, (u), or (u,v) where u is the real part and v is the imaginary part.

Any failure in extraction will set the failbit and result in undefined behavior.


operator <<

Description:

Inserts a complex number into a stream.

Prototype:

template<class T, class charT, class traits>


basic_ostream<charT, traits>& operator<< 
  (basic_ostream<charT, traits>&,
  const complex<T>&);

Complex Value Operations

The complex value operations consists of:


real

Description:

Retrieves the real component of a complex class.

Prototype:

template<class T> 
  T real(const complex<T>&);
Remarks:

Returns the real component of the argument.


imag

Description:

Retrieves the imaginary component of a complex class.

Prototype:

template<class T> 
  T imag(const complex<T>&);
Remarks:

Returns the imaginary component of the argument.


abs

Description:

Determines the absolute value of a complex class.

Prototype:

template<class T>
  T abs(const complex<T>&);
Remarks:

Returns the absolute value of the complex class argument.


arg

Description:

Determines the phase angle.

Prototype:

template<class T> 
  T arg(const complex<T>&);
Remarks:

Returns the phase angle of the complex class argument or atan2(imag(x), real(x).


norm

Description:

Determines the squared magnitude.

Prototype:

template<class T> 
  T norm(const complex<T>&);
Remarks:

The squared magnitude of the complex class.


conj

Description:

Determines the complex conjugate.

Prototype:

template<class T> 
  complex<T> conj(const complex<T>&);
Remarks:

Returns the complex conjugate of the complex class argument.


polar

Description:

Determines the polar coordinates.

Prototype:

template<class T> 
  complex<T> polar(const T&, const T&);
Remarks:

Returns the complex value corresponding to a complex number whose magnitude is the first argument and whose phase angle is the second argument.


Complex Transcendentals

The complex transcendentals consists of:


cos

Description:

Determines the cosine.

Prototype:

template<class T> 
  complex<T> cos (const complex<T>&);
Remarks:

Returns the cosine of the complex class argument.


cosh

Description:

Determines the hyperbolic cosine.

Prototype:

template<class T> 
  complex<T> cosh (const complex<T>&);
Remarks:

Returns the cosine of the complex class argument.


exp

Description:

Determines the exponential.

Prototype:

template<class T> 
  complex<T> exp (const complex<T>&);
Remarks:

Returns the base exponential of the complex class argument.


log

Description:

Determines the natural base logarithm.

Prototype:

template<class T> 
  complex<T> log (const complex<T>&);
Remarks:

Returns the natural base logarithm of the complex class argument, in the range of a strip mathematically unbounded along the real axis and in the interval of [i*pi, i*pi] along the imaginary axis.Where the argument is a negative real number, imag(log(cpx)), is pi.


log10

Description:

Determines the logarithm to base ten.

Prototype:

template<class T> 
  complex<T> log10(const complex<T>&);
Remarks:

Returns the logarithm base(10) of the argument cpx defined as log(cpx)/log(10).


pow

Description:

Raises the complex class to a set power.

Prototype:

template<class T> 
  complex<T> pow(const complex<T>&, int);
template<class T> 
  complex<T> pow(const complex<T>&, const T&);
template<class T> complex<T> pow
   (const complex<T>&, const complex<T>&);
template<class T> 
  complex<T> pow(const T&, const complex<T>&);
Remarks:

Returns the complex class raised to the power of second argument defined as the exponent of (the second argument times the log of the first argument).

The value for pow(0,0)will return (nan, nan).


sin

Description:

Determines the sine.

Prototype:

template<class T> 
  complex<T> sin (const complex<T>&);
Remarks:

Returns the sine of the complex class argument.


sinh

Description:

Determines the hyperbolic sine.

Prototype:

template<class T> 
  complex<T> sinh (const complex<T>&);
Remarks:

Returns the hyperbolic sine of the complex class argument.


sqrt

Description:

Determines the square root.

Prototype:

template<class T> 
  complex<T> sqrt (const complex<T>&);
Remarks:

Returns the square root of the complex class argument in the range of right half plane. If the argument is a negative real number, the value returned lies on the positive imaginary axis.


tan

Description:

Determines the tangent.

Prototype:

template<class T> 
  complex<T> tan (const complex<T>&);
Remarks:

Returns the tangent of the complex class argument.


tanh

Description:

Determines the hyperbolic tangent.

Prototype:

template<class T> 
  complex<T> tanh (const complex<T>&);
Remarks:

This non standard function returns the hyperbolic tangent of the complex class argument.


acos

Description:

Determines the arc cosine value.

Prototype:

template <class T> complex<T> acos(const complex<T>& x);

Remarks:

This non standard function returns the complex arc cosine value. This value is in the range of a strip mathematically unbounded along the imaginary axis and in the interval [0, ] along the real axis.


asin

Description:

Determines the arc sine.

Prototype:

template <class T> complex<T> asin(const complex<T>& x);

Remarks:

This non standard function returns the complex arc sine value. This value in the range of a strip mathematically unbounded along the imaginary axis and in the interval [- /2, + /2] along the real axis.


atan

Description:

Determines the arc tangent.

Prototype:

template <class T> complex<T> atan(const complex<T>& x);

Remarks:

This non standard function returns the complex arc tangent value. This value is in the range of a strip mathematically unbounded along the imaginary axis and in the interval [- /2, + /2] along the real axis.


acosh

Description:

Determines the hyperbolic arch cosine.

Prototype:

template <class T> complex<T> acosh(const complex<T>& x);

Remarks:

Returns the complex arc hyperbolic cosine value, in the range of a half-strip of non-negative values along the real axis and in the interval [-i , +i ] along the imaginary axis.


asinh

Description:

Determines the hyperbolic arc sine.

Prototype:

template <class T> complex<T> asinh(const complex<T>& x);

Remarks:

This non standard function returns the complex arc hyperbolic sine value, in the range of a strip mathematically unbounded along the real axis and in the interval [-i /2, +i /2] along the imaginary axis.


atanh

Description:

Determines the hyperbolic arc tangent.

Prototype:

template <class T> complex<T> atanh(const complex<T>& x);

Remarks:

This non standard function returns the complex arc hyperbolic tangent value, in the range of a strip mathematically unbounded along the real axis and in the interval [-i /2, +i /2] along the imaginary axis.


26.3 Numeric arrays

The numeric array library consists of several classes and non member operators for the manipulation of array objects.


26.3.1 Header <valarray>

A synopsis of the valarray header is listed in "Header <valarray> synopsis"

Header <valarray> synopsis:


namespace std {
template<class T> class valarray; 
class slice;  
template<class T> class slice_array;
class gslice;  
template<class T> class gslice_array;
template<class T> class mask_array;  
template<class T> class indirect_array;  
template<class T> valarray<T> operator*
	(const valarray<T>&, const valarray<T>&);
template<class T> valarray<T> operator* 
	(const valarray<T>&, const T&);
template<class T> valarray<T> operator* 
	(const T&, const valarray<T>&);
template<class T> valarray<T> operator/
	(const valarray<T>&, const valarray<T>&);
template<class T> valarray<T> operator/ 
	(const valarray<T>&, const T&);
template<class T> valarray<T> operator/ (
	const T&, const valarray<T>&);
template<class T> valarray<T> operator%
	(const valarray<T>&, const valarray<T>&);
template<class T> valarray<T> operator% 
	(const valarray<T>&, const T&);
template<class T> valarray<T> operator% 
	(const T&, const valarray<T>&);
template<class T> valarray<T> operator+
	(const valarray<T>&, const valarray<T>&);
template<class T> valarray<T> operator+ 
	(const valarray<T>&, const T&);
template<class T> valarray<T> operator+
	 (const T&, const valarray<T>&);
template<class T> valarray<T> operator-(
	const valarray<T>&, const valarray<T>&);
template<class T> valarray<T> operator- 
	(const valarray<T>&, const T&);
template<class T> valarray<T> operator- 
	(const T&, const valarray<T>&);
template<class T> valarray<T> operator^
	(const valarray<T>&, const valarray<T>&);
template<class T> valarray<T> operator^
	 (const valarray<T>&, const T&);
template<class T> valarray<T> operator^
	 (const T&, const valarray<T>&);
template<class T> valarray<T> operator&
	(const valarray<T>&, const valarray<T>&);
template<class T> valarray<T> operator& 
	(const valarray<T>&, const T&);
template<class T> valarray<T> operator&
	 (const T&, const valarray<T>&);
template<class T> valarray<T> operator|
	(const valarray<T>&, const valarray<T>&);
template<class T> valarray<T> operator|
	 (const valarray<T>&, const T&);
template<class T> valarray<T> operator|
	 (const T&, const valarray<T>&);
template<class T> valarray<T> operator<<
	(const valarray<T>&, const valarray<T>&);
template<class T> valarray<T> operator<<
	(const valarray<T>&, const T&);
template<class T> valarray<T> operator<<
	(const T&, const valarray<T>&);
template<class T> valarray<T> operator>>
	(const valarray<T>&, const valarray<T>&);
template<class T> valarray<T> operator>>
	(const valarray<T>&, const T&);
template<class T> valarray<T> operator>>
	(const T&, const valarray<T>&);
template<class T> valarray<bool> operator&&
	(const valarray<T>&, const valarray<T>&);
template<class T> valarray<bool> operator&&
	(const valarray<T>&, const T&);
template<class T> valarray<bool> operator&&
	(const T&, const valarray<T>&);
template<class T> valarray<bool> operator||
	(const valarray<T>&, const valarray<T>&);
template<class T> valarray<bool> operator||
	(const valarray<T>&, const T&);
template<class T> valarray<bool> operator||
	(const T&, const valarray<T>&);
template<class T> valarray<bool> operator==
	(const valarray<T>&, const valarray<T>&);
template<class T> valarray<bool> operator==
	(const valarray<T>&, const T&);
template<class T> valarray<bool> operator==
	(const T&, const valarray<T>&);
template<class T> valarray<bool> operator!=
	(const valarray<T>&, const valarray<T>&);
template<class T> valarray<bool> operator!=
	(const valarray<T>&, const T&);
template<class T> valarray<bool> operator!=
	(const T&, const valarray<T>&);
template<class T> valarray<bool> operator< 
	(const valarray<T>&, const valarray<T>&);
template<class T> valarray<bool> operator< 
	(const valarray<T>&, const T&);
template<class T> valarray<bool> operator< 
	(const T&, const valarray<T>&);
template<class T> valarray<bool> operator>
	 (const valarray<T>&, const valarray<T>&);
template<class T> valarray<bool> operator> 
	(const valarray<T>&, const T&);
template<class T> valarray<bool> operator> 
	(const T&, const valarray<T>&);
template<class T> valarray<bool> operator<=
	(const valarray<T>&, const valarray<T>&);
template<class T> valarray<bool> operator<=
	(const valarray<T>&, const T&);
template<class T> valarray<bool> operator<=
	(const T&, const valarray<T>&);
template<class T> valarray<bool> operator>=
	(const valarray<T>&, const valarray<T>&);
template<class T> valarray<bool> operator>=
	(const valarray<T>&, const T&);
template<class T> valarray<bool> operator>=
	(const T&, const valarray<T>&);
template<class T> valarray<T> abs 
	(const valarray<T>&);
template<class T> valarray<T> acos 
	(const valarray<T>&);
template<class T> valarray<T> asin 
	(const valarray<T>&);
template<class T> valarray<T> atan 
	(const valarray<T>&);
template<class T> valarray<T> atan2 
	(const valarray<T>&, const valarray<T>&); 
template<class T> valarray<T> atan2(
	const valarray<T>&, const T&);
template<class T> valarray<T> atan2
	(const T&, const valarray<T>&);
template<class T> valarray<T> cos 
	(const valarray<T>&);
template<class T> valarray<T> cosh 
	(const valarray<T>&);
template<class T> valarray<T> exp 
	(const valarray<T>&);
template<class T> valarray<T> log 
	(const valarray<T>&);
template<class T> valarray<T> log10
	(const valarray<T>&);
template<class T> valarray<T> pow
	(const valarray<T>&, const valarray<T>&); 
template<class T> valarray<T> pow
	(const valarray<T>&, const T&); 
template<class T> valarray<T> pow
	(const T&, const valarray<T>&); 
template<class T> valarray<T> sin 
	(const valarray<T>&);
template<class T> valarray<T> sinh 
	(const valarray<T>&);
template<class T> valarray<T> sqrt 
	(const valarray<T>&);
template<class T> valarray<T> tan 
	(const valarray<T>&);
template<class T> valarray<T> tanh 
	(const valarray<T>&);
}


26.3.2 Template Class Valarray

The template class valarray is a single direction smart array with element indexing beginning with the zero element.

Template Class Valarray Synopsis:


namespace std {
template<class T> class valarray {
public:
typedef T value_type;
valarray();
explicit valarray(size_t);
valarray(const T&, size_t);
valarray(const T*, size_t);
valarray(const valarray&);
valarray(const slice_array<T>&);
valarray(const gslice_array<T>&);
valarray(const mask_array<T>&);
valarray(const indirect_array<T>&);
~valarray();

valarray<T>& operator=(const valarray<T>&);
valarray<T>& operator=(const T&);
valarray<T>& operator=(const slice_array<T>&);
valarray<T>& operator=(const gslice_array<T>&);
valarray<T>& operator=(const mask_array<T>&);
valarray<T>& operator=(const indirect_array<T>&);

T operator[](size_t) const;
T& operator[](size_t);

valarray<T> operator[](slice) const;
slice_array<T> operator[](slice);
valarray<T> operator[](const gslice&) const;
gslice_array<T> operator[](const gslice&);
valarray<T> operator[](const valarray<bool>&) const;
mask_array<T> operator[](const valarray<bool>&);
valarray<T> operator[](const valarray<size_t>&) const;
indirect_array<T> operator[](const valarray<size_t>&);

valarray<T> operator+() const;
valarray<T> operator-() const;
valarray<T> operator~() const;
valarray<T> operator!() const;

valarray<T>& operator*= (const T&);
valarray<T>& operator/= (const T&);
valarray<T>& operator%= (const T&);
valarray<T>& operator+= (const T&);
valarray<T>& operator-= (const T&);
valarray<T>& operator^= (const T&);
valarray<T>& operator&= (const T&);
valarray<T>& operator|= (const T&);
valarray<T>& operator<<=(const T&);
valarray<T>& operator>>=(const T&);
valarray<T>& operator*= (const valarray<T>&);
valarray<T>& operator/= (const valarray<T>&);
valarray<T>& operator%= (const valarray<T>&);
valarray<T>& operator+= (const valarray<T>&);
valarray<T>& operator-= (const valarray<T>&);
valarray<T>& operator^= (const valarray<T>&);
valarray<T>& operator|= (const valarray<T>&);
valarray<T>& operator&= (const valarray<T>&);
valarray<T>& operator<<=(const valarray<T>&);
valarray<T>& operator>>=(const valarray<T>&);

size_t size() const;
T sum() const;
T min() const;
T max() const;
valarray<T> shift (int) const;
valarray<T> cshift(int) const;
valarray<T> apply(T func(T)) const;
valarray<T> apply(T func(const T&)) const;
void resize(size_t sz, T c = T());
};
}


Constructors

The class valarray provides overloaded constructors to create an object of valarray in several manners.

Prototype:

valarray();


explicit valarray(size_t);


valarray(const T&, size_t);


valarray(const T*, size_t);


valarray(const valarray<T>&);


valarray(const slice_array<T>&);


valarray(const gslice_array<T>&);


valarray(const mask_array<T>&);


valarray(const indirect_array<T>&);

Destructor

Removes a valarray object from memory.

Prototype:

~valarray();

Assignment Operator

The valarray class provides for various means of assignment to an already created object.

Prototype:

valarray<T>& operator=(const valarray<T>&);


valarray<T>& operator=(const T&);


valarray<T>& operator=(const slice_array<T>&);


valarray<T>& operator=(const gslice_array<T>&);


valarray<T>& operator=(const mask_array<T>&);


valarray<T>& operator=(const indirect_array<T>&);
Return:

Avalarray object is returned.


26.3.2.3 valarray element access

An index operator is provided for single element access of valarray objects.


operator[]

This operator provide element access for read and write operations.

Prototype:

T operator[](size_t) const;


T& operator[](size_t);
Return:

A type is returned.


26.3.2.4 valarray subset operations

An index operator is provided for subset array access.


operator[]

The index operator is specialized for subset access to allow both read and write operations.

Prototype:

valarray<T> operator[]
  (slice) const;
slice_array<T> operator[]
  (slice);
valarray<T> operator[]
  (const gslice&) const;
gslice_array<T> operator[]
  (const gslice&);
valarray<T> operator[]
  (const valarray<bool>&) const;
mask_array<T> operator[]
  (const valarray<bool>&);
valarray<T> operator[]
  (const valarray<size_t>&) const;
indirect_array<T> operator[]
  (const valarray<size_t>&);
Return:

The return corresponds to the index type.


26.3.2.5 valarray unary operators

The valarray class provides operators for array manipulation.

Prototype:

valarray<T> operator+() const;

Returns a valarray sum of x+y;

Prototype:

valarray<T> operator-() const;

Returns a valarray result of x-y;

Prototype:

valarray<T> operator~() const;

Returns a valarray result of x~y;

Prototype:

valarray<bool> operator!() const;

Returns a bool valarray of!x;


26.3.2.6 Valarray Computed Assignment

The valarray class provides for a means of compound assignment and math operation. A valarray object is returned.

Prototype:

valarray<T>& operator*= (const valarray<T>&);


valarray<T>& operator*= (const T&);

Returns a valarray result of x*=y;

Prototype:

valarray<T>& operator/= (const valarray<T>&);


valarray<T>& operator/= (const T&);

Returns a valarray result of x/=y;

Prototype:

valarray<T>& operator%= (const valarray<T>&);


valarray<T>& operator%= (const T&);

Returns a valarray result of x%=y;

Prototype:

valarray<T>& operator+= (const valarray<T>&);


valarray<T>& operator+= (const T&);

Returns a valarray result of x+=y;

Prototype:

valarray<T>& operator-= (const valarray<T>&);


valarray<T>& operator-= (const T&);

Returns a valarray result of x-=y;

Prototype:

valarray<T>& operator^= (const valarray<T>&);


valarray<T>& operator^= (const T&);

Returns a valarray result of x^=y;

Prototype:

valarray<T>& operator&= (const valarray<T>&);


valarray<T>& operator&= (const T&);

Returns a valarray result of x&=y;

Prototype:

valarray<T>& operator|= (const valarray<T>&);


valarray<T>& operator|= (const T&);

Returns a valarray result of x!=y;

Prototype:

valarray<T>& operator<<=(const valarray<T>&);


valarray<T>& operator<<=(const T&);

Returns a valarray result of x<<=y;

Prototype:

valarray<T>& operator>>=(const valarray<T>&);


valarray<T>& operator>>=(const T&);

Returns a valarray result of x>>=y;


26.3.2.7 Valarray Member Functions

The valarray class provides member functions for array information.


size

Tells the size of the array.

Prototype:

size_t size() const;
Return:

Returns the size of the array.


sum

Tells the sum of the array elements.

Prototype:

T sum() const;
Return:

Returns the sum of the array elements.


min

Tells the smallest element of an array.

Prototype:

T min() const;
Return:

Returns the smallest element in an array.


max

Tells the largest element in an array.

Prototype:

T max() const;
Return:

Returns the largest element in an array.


shift

Returns a new array where the elements have been shifted a set amount.

Prototype:

valarray<T> shift(int n) const;
Return:

Returns the modified array.


cshift

A cyclical shift of an array.

Prototype:

valarray<T> cshift(int n) const;
Return:

Returns the modified array.


apply

Processes the elements of an array.

Prototype:

valarray<T> apply(T func(T)) const;


valarray<T> apply(T func(const T&)) const;
Remarks:

This function "applies" the function specified to all the elements of an array.

Return:

Return the modified array.


resize

Resizes an array and initializes the elements

Prototype:

void resize(size_t sz, T c = T());
Remarks:

If no object is provided the array is initialized with the default constructor.


26.3.3 Valarray Non-member Operations

Non-member operators are provided for manipulation or arrays.

26.3.3.1 Valarray Binary Operators

Non-member valarray operators are provided for the manipulation of arrays.

Prototype:

template<class T> valarray<T> operator*
  (const valarray<T>&, const valarray<T>&);
Prototype:
template<class T> valarray<T> operator/
  (const valarray<T>&, const valarray<T>&);
Prototype:
template<class T> valarray<T> operator%
  (const valarray<T>&, const valarray<T>&);
Prototype:
template<class T> valarray<T> operator+
  (const valarray<T>&, const valarray<T>&);
Prototype:
Template<class T> valarray<T> operator-
  (const valarray<T>&, const valarray<T>&);
Prototype:
template<class T> valarray<T> operator^
  (const valarray<T>&, const valarray<T>&);
Prototype:
template<class T> valarray<T> operator&
  (const valarray<T>&, const valarray<T>&);
Prototype:
template<class T> valarray<T> operator|
  (const valarray<T>&, const valarray<T>&);
Prototype:
template<class T> valarray<T> operator<<
  (const valarray<T>&, const valarray<T>&);
template<class T> valarray<T> operator>>
  (const valarray<T>&, const valarray<T>&);
Prototype:
template<class T> valarray<T> operator* 
  (const valarray<T>&, const T&);
Prototype:
template<class T> valarray<T> operator* 
  (const T&, const valarray<T>&);
Prototype:
template<class T> valarray<T> operator/ 
  (const valarray<T>&, const T&);
template<class T> valarray<T> operator/ 
  (const T&, const valarray<T>&);
Prototype:
template<class T> valarray<T> operator% 
  (const valarray<T>&, const T&);
template<class T> valarray<T> operator% 
  (const T&, const valarray<T>&);
Prototype:
template<class T> valarray<T> operator+
  (const valarray<T>&, const T&);
template<class T> valarray<T> operator+ 
  (const T&, const valarray<T>&);
Prototype:
template<class T> valarray<T> operator- 
  (const valarray<T>&, const T&);
template<class T> valarray<T> operator- 
  (const T&, const valarray<T>&);
Prototype:
template<class T> valarray<T> operator^ 
  (const valarray<T>&, const T&);
template<class T> valarray<T> operator^ 
  (const T&, const valarray<T>&);
Prototype:
template<class T> valarray<T> operator&
   (const valarray<T>&, const T&);
template<class T> valarray<T> operator& 
  (const T&, const valarray<T>&);
Prototype:
template<class T> valarray<T> operator| 
  (const valarray<T>&, const T&);
template<class T> valarray<T> operator| 
  (const T&, const valarray<T>&);
Prototype:
template<class T> valarray<T> operator<<
  (const valarray<T>&, const T&);
template<class T> valarray<T> operator<<
  (const T&, const valarray<T>&);
Prototype:
template<class T> valarray<T> operator>>
  (const valarray<T>&, const T&);
template<class T> valarray<T> operator>>
  (const T&, const valarray<T>&);
Return:

Each operator returns an array whose length is equal to the lengths of the argument arrays and initialized with the result of applying the operator.


26.3.3.2 Valarray Logical Operators

The valarray class provides logical operators for the comparison of like arrays.

Prototype:

template<class T> valarray<bool> operator==
  (const valarray<T>&, const valarray<T>&);
Prototype:
template<class T> valarray<bool> operator!=
  (const valarray<T>&, const valarray<T>&);
Prototype:
template<class T> valarray<bool> operator<
  (const valarray<T>&, const valarray<T>&);
Prototype:
template<class T> valarray<bool> operator>
  (const valarray<T>&, const valarray<T>&);
Prototype:
template<class T> valarray<bool> operator<=
  (const valarray<T>&, const valarray<T>&);
Prototype:
template<class T> valarray<bool> operator>=
  (const valarray<T>&, const valarray<T>&);
Prototype:
template<class T> valarray<bool> operator&&
  (const valarray<T>&, const valarray<T>&);
Prototype:
template<class T> valarray<bool> operator||
  (const valarray<T>&, const valarray<T>&);
Return:

All of the logical operators returns a bool array whose length is equal to the length of the array arguments. The elements of the returned array are initialized with a boolean result of the match.


Non-member logical operations

Non-member logical operators are provided to allow for variations of order of the operation.

Prototype:

template<class T> valarray<bool> operator==
  (const valarray&, const T&);
template<class T> valarray<bool> operator==
  (const T&, const valarray&);
Prototype:
template<class T> valarray<bool> operator!=
  (const valarray&, const T&);
template<class T> valarray<bool> operator!=
  (const T&, const valarray&);
Prototype:
template<class T> valarray<bool> operator< 
  (const valarray&, const T&);
template<class T> valarray<bool> operator< 
  (const T&, const valarray&);
Prototype:
template<class T> valarray<bool> operator>
   (const valarray&, const T&);
template<class T> valarray<bool> operator> 
  (const T&, const valarray&);
Prototype:
template<class T> valarray<bool> operator<=
  (const valarray&, const T&);
template<class T> valarray<bool> operator<=
  (const T&, const valarray&);
Prototype:
template<class T> valarray<bool> operator>=
  (const valarray&, const T&);
template<class T> valarray<bool> operator>=
  (const T&, const valarray&);
Prototype:
template<class T> valarray<bool> operator&&
  (const valarray<T>&, const T&);
template<class T> valarray<bool> operator&&
  (const T&, const valarray<T>&);
Prototype:
template<class T> valarray<bool> operator||
  (const valarray<T>&, const T&);
template<class T> valarray<bool> operator||
  (const T&, const valarray<T>&);
Return:

The result of these operations is bool array whose length is equal to the length of the array argument. Each element of the returned array is the result of a logical match.

26.3.3.3 valarray transcendentals

Trigonometric and expotential functions are provided for the valarray classes.

Prototype:

template<class T> valarray<T> abs 
  (const valarray<T>&);
Prototype:
template<class T> valarray<T> acos 
  (const valarray<T>&);
Prototype:
template<class T> valarray<T> asin 
  (const valarray<T>&);
Prototype:
template<class T> valarray<T> atan 
  (const valarray<T>&);
Prototype:
template<class T> valarray<T> atan2
  (const valarray<T>&, const valarray<T>&);
template<class T> valarray<T> atan2
  (const valarray<T>&, const T&);
template<class T> valarray<T> atan2
  (const T&, const valarray<T>&);
Prototype:
template<class T> valarray<T> cos 
  (const valarray<T>&);
Prototype:
template<class T> valarray<T> cosh 
  (const valarray<T>&);
Prototype:
template<class T> valarray<T> exp 
  (const valarray<T>&);
Prototype:
template<class T> valarray<T> log 
  (const valarray<T>&);
Prototype:
template<class T> valarray<T> log10
  (const valarray<T>&);
Prototype:
template<class T> valarray<T> pow
  (const valarray<T>&, const valarray<T>&);
template<class T> valarray<T> pow 
  (const valarray<T>&, const T&);
template<class T> valarray<T> pow 
  (const T&, const valarray<T>&);
Prototype:
template<class T> valarray<T> sin 
  (const valarray<T>&);
Prototype:
template<class T> valarray<T> sinh 
  (const valarray<T>&);
Prototype:
template<class T> valarray<T> sqrt 
  (const valarray<T>&);
Prototype:
template<class T> valarray<T> tan 
  (const valarray<T>&);
Prototype:
template<class T> valarray<T> tanh 
  (const valarray<T>&);
Result:

A valarray object is returned with the individual elements initialized with the result of the corresponding operation.


26.3.4 Class slice

Aslice is a set of indices that have three properties, a starting index, the number of elements and the distance between the elements.

Class Slice Synopsis:


namespace std {
class slice {
public:
slice();
slice(size_t, size_t, size_t);
size_t start() const;
size_t size() const;
size_t stride() const;
};
}


Constructors

A constructor is overloaded to initialize an object with values or without values.

Prototype:

slice();


slice(size_t start, size_t length, size_t stride);


slice(const slice&);

26.3.4.2 slice access functions


The slice class has three member functions.


start

Start tells start is the position where the slice starts.

Prototype:

size_t start() const;

Return:

The starting position is returned.


size

Size tells the size of the slice.

Prototype:

size_t size() const;

Return:

The size of the slice is returned by the size member function.


stride

The distance between elements is given by the stride function.

Prototype:

size_t stride() const;

Return:

The distance between each element is returned by stride.


26.3.5 Template Class Slice_array

The slice_array class is a helper class used by the slice subscript operator.

Template Class Slice_array Synopsis:


namespace std {
template <class T> class slice_array {
public:
typedef T value_type;
void operator= (const valarray<T>&) const;
void operator*= (const valarray<T>&) const;
void operator/= (const valarray<T>&) const;
void operator%= (const valarray<T>&) const;
void operator+= (const valarray<T>&) const;
void operator-= (const valarray<T>&) const;
void operator^= (const valarray<T>&) const;
void operator&= (const valarray<T>&) const;
void operator|= (const valarray<T>&) const;
void operator<<=(const valarray<T>&) const;
void operator>>=(const valarray<T>&) const;
void operator=(const T&); 
~slice_array();
private:
slice_array();
slice_array(const slice_array&);
slice_array& operator=(const slice_array&);
};
}


Constructors

Constructs a slice_array object.

Prototype:

private:
  slice_array();
  slice_array(const slice_array&);

Assignment Operator

The assignment operator allows for the initialization of a slice_array after construction.

Prototype:

void operator=(const valarray<T>&) const;


slice_array& operator=(const slice_array&);

26.3.5.3 slice_array computed assignment

Several compound assignment operators are provided.

Prototype:

void operator*= (const valarray<T>&) const;
Prototype:
void operator/= (const valarray<T>&) const;
Prototype:
void operator%= (const valarray<T>&) const;
Prototype:
void operator+= (const valarray<T>&) const;
Prototype:
void operator-= (const valarray<T>&) const;
Prototype:
void operator^= (const valarray<T>&) const;
Prototype:
void operator&= (const valarray<T>&) const;
Prototype:
void operator|= (const valarray<T>&) const;
Prototype:
void operator<<=(const valarray<T>&) const;
Prototype:
void operator>>=(const valarray<T>&) const;

There is no return for the compound operators.


26.3.5.4 Slice_array Fill Function

An assignment operation is provided to fill individual elements of the array.

Prototype:

void operator=(const T&);

No value is returned.


26.3.6 Class Gslice

A general slice class is provided for multidimensional arrays.

Gslice Class Synopsis:


namespace std {
class gslice {
public:
gslice();
gslice
	(size_t s, const valarray<size_t>& l,
	const valarray<size_t>& d);
size_t start() const;
valarray<size_t> size() const;
valarray<size_t> stride() const;
};
}


Constructors

An overloaded constructor is provided for the creation of a gslice object.

Prototype:

gslice();


gslice(size_t start, const valarray<size_t>& 
lengths,


const valarray<size_t>& strides);


gslice(const gslice&);

26.3.6.2 Gslice Access Functions


The gslice class provides for access to the start, size and stride of the slice class.


start

The start function give the starting position.

Prototype:

size_t start() const;
Return:

The starting position of the gslice is returned.


size

The size function returns the number of elements.

Prototype:

valarray<size_t> size() const;
Return:

The number of elements as a valarray is returned.


stride

The stride function tells the size of each element.

Prototype:

valarray<size_t> stride() const;
Return:

The size of the element as a valarray is returned.


26.3.7 Template Class Gslice_array

The gslice_array class is a helper class used by the gslice subscript operator.

Template Class Gslice_array Synopsis:


namespace std {
template <class T> class gslice_array {
public:
typedef T value_type;
void operator= (const valarray<T>&) const;
void operator*= (const valarray<T>&) const;
void operator/= (const valarray<T>&) const;
void operator%= (const valarray<T>&) const;
void operator+= (const valarray<T>&) const;
void operator-= (const valarray<T>&) const;
void operator^= (const valarray<T>&) const;
void operator&= (const valarray<T>&) const;
void operator|= (const valarray<T>&) const;
void operator<<=(const valarray<T>&) const;
void operator>>=(const valarray<T>&) const;
void operator=(const T&); 
~gslice_array();
private:
gslice_array();
gslice_array(const gslice_array&);
gslice_array& operator=(const gslice_array&);
};
}


Constructors

An overloaded constructor is provided for the creation of a gslice_array object.

Prototype:

gslice_array();


gslice_array(const gslice_array&);

Assignment Operators

An assignment operator is provided for initializing a gslice_array after it has been created.

Prototype:

void operator=(const valarray<T>&) const;


gslice_array& operator=(const gslice_array&);
Return:

A copy of the modified gslice_array is returned for the second assignment operator.


26.3.7.3 Gslice_array Computed Assignment

Several compound assignment operators are provided.

Prototype:

void operator*= (const valarray<T>&) const;
Prototype:
void operator/= (const valarray<T>&) const;
Prototype:
void operator%= (const valarray<T>&) const;
Prototype:
void operator+= (const valarray<T>&) const;
Prototype:
void operator-= (const valarray<T>&) const;
Prototype:
void operator^= (const valarray<T>&) const;
Prototype:
void operator&= (const valarray<T>&) const;
Prototype:
void operator|= (const valarray<T>&) const;
Prototype:
void operator<<=(const valarray<T>&) const;
Prototype:
void operator>>=(const valarray<T>&) const;

No return is given for the compound operators.


26.3.7.4 Fill Function

An assignment operation is provided to fill individual elements of the array.

Prototype:

void operator=(const T&); 

There is no return for the fill function.


26.3.8 Template Class Mask_array

The mask_array class is a helper class used by the mask subscript operator.

Template Class Mask_array Synopsis:


namespace std {
template <class T> class mask_array {
public:
typedef T value_type;
void operator= (const valarray<T>&) const;
void operator*= (const valarray<T>&) const;
void operator/= (const valarray<T>&) const;
void operator%= (const valarray<T>&) const;
void operator+= (const valarray<T>&) const;
void operator-= (const valarray<T>&) const;
void operator^= (const valarray<T>&) const;
void operator&= (const valarray<T>&) const;
void operator|= (const valarray<T>&) const;
void operator<<=(const valarray<T>&) const;
void operator>>=(const valarray<T>&) const;
void operator=(const T&);
~mask_array();
private:
mask_array();
mask_array(const mask_array&);
mask_array& operator=(const mask_array&);
};
}


Constructors

An overloaded constructor is provided for creating a mask_array object.

Prototype:

private:
  mask_array();
  mask_array(const mask_array&);

Assignment Operators

An overloaded assignment operator is provided for assigning values to a mask_array after construction.

Prototype:

void operator=(const valarray<T>&) const;


mask_array& operator=(const mask_array&);
Return:

The copy assignment operator returns a mask_array reference.


26.3.8.3 Mask_array Computed Assignment

Several compound assignment operators are provided.

Prototype:

void operator*= (const valarray<T>&) const;
Prototype:
void operator/= (const valarray<T>&) const;
Prototype:
void operator%= (const valarray<T>&) const;
Prototype:
void operator+= (const valarray<T>&) const;
Prototype:
void operator-= (const valarray<T>&) const;
Prototype:
void operator^= (const valarray<T>&) const;
Prototype:
void operator&= (const valarray<T>&) const;
Prototype:
void operator|= (const valarray<T>&) const;
Prototype:
void operator<<=(const valarray<T>&) const;
Prototype:
void operator>>=(const valarray<T>&) const;

There is no return value for the compound assignment operators.


26.3.8.4 Mask_array Fill Function

An assignment operation is provided to fill individual elements of the array.

Prototype:

void operator =(const T&);

There is no return for the fill function.


26.3.9 Template Class Indirect_array

The indirect_array class is a helper class used by the indirect subscript operator.

Template Class Indirect_array Synopsis:


namespace std {
template <class T> class indirect_array {
public:
typedef T value_type;
void operator= (const valarray<T>&) const;
void operator*= (const valarray<T>&) const;
void operator/= (const valarray<T>&) const;
void operator%= (const valarray<T>&) const;
void operator+= (const valarray<T>&) const;
void operator-= (const valarray<T>&) const;
void operator^= (const valarray<T>&) const;
void operator&= (const valarray<T>&) const;
void operator|= (const valarray<T>&) const;
void operator<<=(const valarray<T>&) const;
void operator>>=(const valarray<T>&) const;
void operator=(const T&);
~indirect_array();
private:
indirect_array();
indirect_array(const indirect_array&);
indirect_array& operator=(const indirect_array&);
};
}

1 This template is a helper template used by the indirect subscript operator indirect_array<T> valarray<T>::operator[](const valarray<size_t>&).

It has reference semantics to a subset of an array specified by an indirect_array.


Constructors

An overloaded constructor is provided for creating a indirect_array object.

Prototype:

indirect_array();


indirect_array(const indirect_array&);

Assignment Operators

An overloaded assignment operator is provided for assigning values to a indirect_array after construction.

Prototype:

void operator=(const valarray<T>&) const;


indirect_array& operator=(const indirect_array&);
Return:

The copy assignment operator returns a indirect_array reference.


26.3.9.3 Indirect_array Computed Assignment

Several compound assignment operators are provided.

Prototype:

void operator*= (const valarray<T>&) const;
Prototype:
void operator/= (const valarray<T>&) const;
Prototype:
void operator%= (const valarray<T>&) const;
Prototype:
void operator+= (const valarray<T>&) const;
Prototype:
void operator-= (const valarray<T>&) const;
Prototype:
void operator^= (const valarray<T>&) const;
Prototype:
void operator&= (const valarray<T>&) const;
Prototype:
void operator|= (const valarray<T>&) const;
Prototype:
void operator<<=(const valarray<T>&) const;
Prototype:
void operator>>=(const valarray<T>&) const;

There is no return value for the compound assignment operators.


26.3.9.4 indirect_array fill function

An assignment operation is provided to fill individual elements of the array.

Prototype:

void operator=(const T&);

There is no return for the fill function.


26.4 Generalized Numeric Operations

The standard library provides general algorithms for numeric processing.


Header <numeric>

The header <numeric> includes templated functions for generalize numeric processing.

Header <numeric> synopsis:


namespace std {
template <class InputIterator, class T> T accumulate
	(InputIterator first, InputIterator last, T init);
template <class InputIterator, class T, class BinaryOperation>
T accumulate
	(InputIterator first, InputIterator last, T init,
	BinaryOperation binary_op);
template <class InputIterator1, class InputIterator2, class T>
T inner_product
	(InputIterator1 first1, InputIterator1 last1,
	InputIterator2 first2, T init);
template <class InputIterator1, class InputIterator2, class T,
class BinaryOperation1, class BinaryOperation2> T inner_product
	(InputIterator1 first1, InputIterator1 last1,
	InputIterator2 first2, T init, BinaryOperation1 binary_op1, 
	BinaryOperation2 binary_op2); 
template <class InputIterator, class OutputIterator>
OutputIterator partial_sum
	(InputIterator first, InputIterator last, 
	OutputIterator result);
template <class InputIterator, class OutputIterator, 
	class BinaryOperation> 
OutputIterator partial_sum
	(InputIterator first, InputIterator last, 
	OutputIterator result, BinaryOperation binary_op); 
template <class InputIterator, class OutputIterator>
OutputIterator adjacent_difference
	(InputIterator first, InputIterator last, 
	OutputIterator result);
template <class InputIterator, class OutputIterator, 
	class BinaryOperation> 
OutputIterator adjacent_difference
	(InputIterator first, InputIterator last, 
	OutputIterator result, BinaryOperation binary_op);
}


accumulate

Accumulate the sum of a sequence.

Prototype:

template <class InputIterator, class T>


T accumulate(
  InputIterator first, InputIterator last,
  T init);
template <class InputIterator, class T, 
  class BinaryOperation>
T accumulate
  (InputIterator first, InputIterator last,
  T init, BinaryOperation binary_op);
Return:

The sum of the values in a range or the some of the values after being processed by an operation is returned.


inner_product

Computes and returns the value of a product of the values in a range.

Prototype:

template <class InputIterator1, 
  class InputIterator2, class T>
T inner_product
  (InputIterator1 first1, InputIterator1 last1,
  InputIterator2 first2, T init);
template <class InputIterator1, 
  class InputIterator2, class T,
  class BinaryOperation1, class BinaryOperation2>
T inner_product
  (InputIterator1 first1, InputIterator1 last1,
  InputIterator2 first2, T init,
  BinaryOperation1 binary_op1,
  BinaryOperation2 binary_op2);
Return:

The value of the product starting with an initial value in a range is returned. In the function with the operation argument it is the product after the operation is performed.


partial_sum

Computes the partial sum of a sequence of numbers.

Prototype:

template <class InputIterator, 
   class OutputIterator>
OutputIterator partial_sum
  (InputIterator first, InputIterator last,
  OutputIterator result);
template <class InputIterator, 
  class OutputIterator, class BinaryOperation>
OutputIterator partial_sum
  (InputIterator first, InputIterator last,
  OutputIterator result,
  BinaryOperation binary_op);

The first computes the partial sum and sends it to the output iterator argument.


  x, y, z   x, x+y, y+z.

The second form computes according to the operational argument and sends it to the output iterator argument. For example if the operational argument was a multiplication operation


  x, y, z   x, x*y, y*z
Return:

The range as the result plus the last minus the first.


adjacent_difference

Computed the adjacent difference in a sequence of numbers.

Prototype:

template <class InputIterator, 
  class OutputIterator>
OutputIterator adjacent_difference
  (InputIterator first, InputIterator last,
  OutputIterator result);
template <class InputIterator, 
  class OutputIterator, class BinaryOperation>
OutputIterator adjacent_difference
  (InputIterator first, InputIterator last,
  OutputIterator result,
  BinaryOperation binary_op);

The first computes the adjacent difference and sends it to the output iterator argument.


  x, y, z   x, y-x, z-y.

The second form computes according to the operational argument and sends it to the output iterator argument. For example if the operational argument was a division operation


  x, y, z   x, y/x, z/y
Return:

The range as the result plus the last minus the first.


26.5 C Library

The standard provides for the math functions included in the standard C library with some overloading for various types.


<cmath>

The contents of the <cmath> headers is the same as the Standard C library headers <math.h> with the addition to the double versions of the math functions in <cmath>, C + + adds float and long double overloaded versions of some functions, with the same semantics.


<cstdlib>

The contents of the <cstdlib> headers is the same as the Standard C library headers <stdlib.h>. In addition to the int versions of certain math functions in <cstdlib>, C + + adds long overloaded versions of some functions, with the same semantics.

The Added C++ Signatures in Cstdlib and Cmath:

long double abs (long double);


long double acos (long double);


long double asin (long double);


long double atan (long double);


long double atan2(long double, long double);


long double ceil (long double);


long double cos (long double);


long double cosh (long double);


long double exp (long double);


long double fabs (long double);


long double floor(long double);


long double fmod (long double, long double);


long double frexp(long double, int*);


long double ldexp(long double, int);


long double log (long double);


long double log10(long double);


long double modf (long double, long double*);


long double pow (long double, long double);


long double pow (long double, int);


long double sin (long double);


long double sinh (long double);


long double sqrt (long double);


long double tan (long double);


long double tanh (long double);



float abs (float);


float acos (float);


float asin (float);


float atan (float);


float atan2(float, float);


float ceil (float);


float cos (float);


float cosh (float);


float exp (float);


float fabs (float);


float floor(float);


float fmod (float, float);


float frexp(float, int*);


float ldexp(float, int);


float log (float);


float log10(float);


float modf (float, float*);


float pow (float, float);


float pow (float, int);


float sin (float);


float sinh (float);


float sqrt (float);


float tan (float);


float tanh (float);



double abs(double); 


double pow(double, int);

 


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: July 21, 2000