2000-04-22 04:33:34 +08:00
|
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
|
|
|
|
<HTML>
|
|
|
|
<HEAD>
|
|
|
|
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
|
2000-07-12 05:45:08 +08:00
|
|
|
<META NAME="AUTHOR" CONTENT="pme@sources.redhat.com (Phil Edwards)">
|
configopts.html, [...]: Remove many EGCS references...
* docs/configopts.html, docs/install.html, docs/17_intro/BADNAMES,
docs/17_intro/howto.html, docs/18_support/howto.html,
docs/19_diagnostics/howto.html, docs/20_util/howto.html,
docs/21_strings/howto.html, docs/22_locale/howto.html,
docs/23_containers/howto.html, docs/24_iterators/howto.html,
docs/25_algorithms/howto.html, docs/26_numerics/howto.html,
docs/27_io/howto.html, docs/ext/howto.html, docs/faq/index.html:
Remove many EGCS references; use current absolute URLs on
gcc.gnu.org or sources.redhat.com for messages in list archives.
* docs/faq/index.txt: Regenerate.
From-SVN: r36988
2000-10-21 08:51:50 +08:00
|
|
|
<META NAME="KEYWORDS" CONTENT="HOWTO, libstdc++, GCC, g++, libg++, STL">
|
2000-04-22 04:33:34 +08:00
|
|
|
<META NAME="DESCRIPTION" CONTENT="HOWTO for the libstdc++ chapter 26.">
|
|
|
|
<META NAME="GENERATOR" CONTENT="vi and eight fingers">
|
|
|
|
<TITLE>libstdc++-v3 HOWTO: Chapter 26</TITLE>
|
2000-07-12 05:45:08 +08:00
|
|
|
<LINK REL="home" HREF="http://sources.redhat.com/libstdc++/docs/26_numerics/">
|
2000-04-22 04:33:34 +08:00
|
|
|
<LINK REL=StyleSheet HREF="../lib3styles.css">
|
configopts.html, [...]: Remove many EGCS references...
* docs/configopts.html, docs/install.html, docs/17_intro/BADNAMES,
docs/17_intro/howto.html, docs/18_support/howto.html,
docs/19_diagnostics/howto.html, docs/20_util/howto.html,
docs/21_strings/howto.html, docs/22_locale/howto.html,
docs/23_containers/howto.html, docs/24_iterators/howto.html,
docs/25_algorithms/howto.html, docs/26_numerics/howto.html,
docs/27_io/howto.html, docs/ext/howto.html, docs/faq/index.html:
Remove many EGCS references; use current absolute URLs on
gcc.gnu.org or sources.redhat.com for messages in list archives.
* docs/faq/index.txt: Regenerate.
From-SVN: r36988
2000-10-21 08:51:50 +08:00
|
|
|
<!-- $Id: howto.html,v 1.5 2000/08/28 18:41:24 pme Exp $ -->
|
2000-04-22 04:33:34 +08:00
|
|
|
</HEAD>
|
|
|
|
<BODY>
|
|
|
|
|
|
|
|
<H1 CLASS="centered"><A NAME="top">Chapter 26: Numerics</A></H1>
|
|
|
|
|
2000-07-08 05:13:28 +08:00
|
|
|
<P>Chapter 26 deals with building block abstractions to aid in
|
|
|
|
numerical computing:
|
|
|
|
<UL>
|
|
|
|
<LI>Template data structures such as <TT>valarray<></TT>
|
|
|
|
and <TT>complex<></TT>.
|
|
|
|
<LI>Template numerical functions such as <TT>accumulate</TT>;
|
|
|
|
<TT>inner_product</TT>; <TT>partial_sum</TT> and
|
|
|
|
<TT>adjacent_difference</TT>.
|
|
|
|
</UL>
|
|
|
|
All of the Standard C math functions are of course included in C++,
|
|
|
|
and overloaded versions for <TT>long</TT>, <TT>float</TT>, and
|
|
|
|
<TT>long double</TT> have been added for all of them.
|
2000-04-22 04:33:34 +08:00
|
|
|
</P>
|
|
|
|
|
|
|
|
<!-- ####################################################### -->
|
|
|
|
<HR>
|
|
|
|
<H1>Contents</H1>
|
|
|
|
<UL>
|
2000-06-28 23:14:39 +08:00
|
|
|
<LI><A HREF="#1">Complex Number Processing</A>
|
|
|
|
<LI><A HREF="#2">Array Processing</A>
|
|
|
|
<LI><A HREF="#3">Numerical Functions</A>
|
2000-04-22 04:33:34 +08:00
|
|
|
</UL>
|
|
|
|
|
|
|
|
<HR>
|
|
|
|
|
|
|
|
<!-- ####################################################### -->
|
|
|
|
|
2000-06-28 23:14:39 +08:00
|
|
|
<H2><A NAME="1">Complex Number Processing</A></H2>
|
2000-07-08 05:13:28 +08:00
|
|
|
<P>Using <TT>complex<></TT> becomes even more comple- er, sorry,
|
|
|
|
<EM>complicated</EM>, with the not-quite-gratuitously-incompatible
|
|
|
|
addition of complex types to the C language. David Tribble has
|
2000-08-29 02:41:24 +08:00
|
|
|
compiled a list of C++98 and C99 conflict points; his description of
|
2000-07-08 05:13:28 +08:00
|
|
|
C's new type versus those of C++ and how to get them playing together
|
|
|
|
nicely is
|
|
|
|
<A HREF="http://home.flash.net/~dtribble/text/cdiffs.htm#C99.complex">here</A>.
|
|
|
|
</P>
|
|
|
|
<P><TT>complex<></TT> is intended to be instantiated with a
|
|
|
|
floating-point type. As long as you meet that and some other basic
|
|
|
|
requirements, then the resulting instantiation has all of the usual
|
|
|
|
math operators defined, as well as definitions of <TT>op<<</TT>
|
|
|
|
and <TT>op>></TT> that work with iostreams: <TT>op<<</TT>
|
|
|
|
prints <TT>(u,v)</TT> and <TT>op>></TT> can read <TT>u</TT>,
|
|
|
|
<TT>(u)</TT>, and <TT>(u,v)</TT>.
|
2000-04-22 04:33:34 +08:00
|
|
|
</P>
|
|
|
|
<P>Return <A HREF="#top">to top of page</A> or
|
|
|
|
<A HREF="../faq/index.html">to the FAQ</A>.
|
|
|
|
</P>
|
|
|
|
|
|
|
|
<HR>
|
2000-06-28 23:14:39 +08:00
|
|
|
<H2><A NAME="2">Array Processing</A></H2>
|
2000-07-08 05:13:28 +08:00
|
|
|
<P>One of the major reasons why FORTRAN can chew through numbers so well
|
|
|
|
is that it is defined to be free of pointer aliasing, an assumption
|
|
|
|
that C89 is not allowed to make, and neither is C++. C99 adds a new
|
|
|
|
keyword, <TT>restrict</TT>, to apply to individual pointers. The C++
|
|
|
|
solution is contained in the library rather than the language
|
|
|
|
(although many vendors can be expected to add this to their compilers
|
|
|
|
as an extension).
|
|
|
|
</P>
|
|
|
|
<P>That library solution is a set of two classes, five template classes,
|
|
|
|
and "a whole bunch" of functions. The classes are required
|
|
|
|
to be free of pointer aliasing, so compilers can optimize the
|
|
|
|
daylights out of them the same way that they have been for FORTRAN.
|
|
|
|
They are collectively called <TT>valarray</TT>, although strictly
|
|
|
|
speaking this is only one of the five template classes, and they are
|
|
|
|
designed to be familiar to people who have worked with the BLAS
|
|
|
|
libraries before.
|
|
|
|
</P>
|
|
|
|
<P>Some more stuff should go here once somebody has time to write it.
|
2000-04-22 04:33:34 +08:00
|
|
|
</P>
|
|
|
|
<P>Return <A HREF="#top">to top of page</A> or
|
|
|
|
<A HREF="../faq/index.html">to the FAQ</A>.
|
|
|
|
</P>
|
|
|
|
|
2000-06-28 23:14:39 +08:00
|
|
|
<HR>
|
|
|
|
<H2><A NAME="3">Numerical Functions</A></H2>
|
2000-07-08 05:13:28 +08:00
|
|
|
<P>There are four generalized functions in the <numeric> header
|
|
|
|
that follow the same conventions as those in <algorithm>. Each
|
|
|
|
of them is overloaded: one signature for common default operations,
|
|
|
|
and a second for fully general operations. Their names are
|
|
|
|
self-explanatory to anyone who works with numerics on a regular basis:
|
|
|
|
<UL>
|
|
|
|
<LI><TT>accumulate</TT>
|
|
|
|
<LI><TT>inner_product</TT>
|
|
|
|
<LI><TT>partial_sum</TT>
|
|
|
|
<LI><TT>adjacent_difference</TT>
|
|
|
|
</UL>
|
|
|
|
</P>
|
|
|
|
<P>Here is a simple example of the two forms of <TT>accumulate</TT>.
|
|
|
|
<PRE>
|
|
|
|
int ar[50];
|
|
|
|
int someval = somefunction();
|
|
|
|
|
|
|
|
// ...initialize members of ar to something...
|
|
|
|
|
|
|
|
int sum = std::accumulate(ar,ar+50,0);
|
|
|
|
int sum_stuff = std::accumulate(ar,ar+50,someval);
|
|
|
|
int product = std::accumulate(ar,ar+50,1,std::multiplies<int>());
|
|
|
|
</PRE>
|
|
|
|
The first call adds all the members of the array, using zero as an
|
|
|
|
initial value for <TT>sum</TT>. The second does the same, but uses
|
|
|
|
<TT>someval</TT> as the starting value (thus, <TT>sum_stuff == sum +
|
|
|
|
someval</TT>). The final call uses the second of the two signatures,
|
|
|
|
and multiplies all the members of the array; here we must obviously
|
|
|
|
use 1 as a starting value instead of 0.
|
|
|
|
</P>
|
|
|
|
<P>The other three functions have similar dual-signature forms.
|
2000-06-28 23:14:39 +08:00
|
|
|
</P>
|
|
|
|
<P>Return <A HREF="#top">to top of page</A> or
|
|
|
|
<A HREF="../faq/index.html">to the FAQ</A>.
|
|
|
|
</P>
|
2000-04-22 04:33:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- ####################################################### -->
|
|
|
|
|
|
|
|
<HR>
|
|
|
|
<P CLASS="fineprint"><EM>
|
|
|
|
Comments and suggestions are welcome, and may be sent to
|
2000-07-12 05:45:08 +08:00
|
|
|
<A HREF="mailto:pme@sources.redhat.com">Phil Edwards</A> or
|
configopts.html, [...]: Remove many EGCS references...
* docs/configopts.html, docs/install.html, docs/17_intro/BADNAMES,
docs/17_intro/howto.html, docs/18_support/howto.html,
docs/19_diagnostics/howto.html, docs/20_util/howto.html,
docs/21_strings/howto.html, docs/22_locale/howto.html,
docs/23_containers/howto.html, docs/24_iterators/howto.html,
docs/25_algorithms/howto.html, docs/26_numerics/howto.html,
docs/27_io/howto.html, docs/ext/howto.html, docs/faq/index.html:
Remove many EGCS references; use current absolute URLs on
gcc.gnu.org or sources.redhat.com for messages in list archives.
* docs/faq/index.txt: Regenerate.
From-SVN: r36988
2000-10-21 08:51:50 +08:00
|
|
|
<A HREF="mailto:gdr@gcc.gnu.org">Gabriel Dos Reis</A>.
|
|
|
|
<BR> $Id: howto.html,v 1.5 2000/08/28 18:41:24 pme Exp $
|
2000-04-22 04:33:34 +08:00
|
|
|
</EM></P>
|
|
|
|
|
|
|
|
|
|
|
|
</BODY>
|
|
|
|
</HTML>
|