mirror of
git://gcc.gnu.org/git/gcc.git
synced 2024-12-28 04:14:38 +08:00
462b73969e
2001-05-30 Phil Edwards <pme@sources.redhat.com> * docs/doxygen/user.cfg.in: Minor addition. * docs/html/documentation.html: Reorganize. Put most-looked-at stuff first. * docs/html/install.html: Update for 3.0. HTML fixups. * docs/html/17_intro/howto.html: Likewise. * docs/html/18_support/howto.html: Likewise. * docs/html/19_diagnostics/howto.html: Likewise. * docs/html/20_util/howto.html: Likewise. * docs/html/23_containers/howto.html: Likewise. * docs/html/24_iterators/howto.html: Likewise. More notes. * docs/html/25_algorithms/howto.html: Likewise. * docs/html/26_numerics/howto.html: Likewise. More notes. * docs/html/27_io/howto.html: Likewise. * docs/html/ext/howto.html: Likewise. * docs/html/faq/index.html: Likewise. * docs/html/faq/index.txt: Regenerate. * docs/html/27_io/iostreams_hierarchy.pdf: Remove in favor of Doxygen-created documentation. From-SVN: r42723
164 lines
6.6 KiB
HTML
164 lines
6.6 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
|
|
<META NAME="AUTHOR" CONTENT="pme@sources.redhat.com (Phil Edwards)">
|
|
<META NAME="KEYWORDS" CONTENT="HOWTO, libstdc++, GCC, g++, libg++, STL">
|
|
<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>
|
|
<LINK REL=StyleSheet HREF="../lib3styles.css">
|
|
<!-- $Id: howto.html,v 1.2 2001/04/03 00:26:56 pme Exp $ -->
|
|
</HEAD>
|
|
<BODY>
|
|
|
|
<H1 CLASS="centered"><A NAME="top">Chapter 26: Numerics</A></H1>
|
|
|
|
<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.
|
|
</P>
|
|
|
|
<!-- ####################################################### -->
|
|
<HR>
|
|
<H1>Contents</H1>
|
|
<UL>
|
|
<LI><A HREF="#1">Complex Number Processing</A>
|
|
<LI><A HREF="#2">Array Processing</A>
|
|
<LI><A HREF="#3">Numerical Functions</A>
|
|
<LI><A HREF="#4">C99</A>
|
|
</UL>
|
|
|
|
<HR>
|
|
|
|
<!-- ####################################################### -->
|
|
|
|
<H2><A NAME="1">Complex Number Processing</A></H2>
|
|
<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
|
|
compiled a list of C++98 and C99 conflict points; his description of
|
|
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>.
|
|
</P>
|
|
<P>Return <A HREF="#top">to top of page</A> or
|
|
<A HREF="../faq/index.html">to the FAQ</A>.
|
|
</P>
|
|
|
|
<HR>
|
|
<H2><A NAME="2">Array Processing</A></H2>
|
|
<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.
|
|
</P>
|
|
<P>Return <A HREF="#top">to top of page</A> or
|
|
<A HREF="../faq/index.html">to the FAQ</A>.
|
|
</P>
|
|
|
|
<HR>
|
|
<H2><A NAME="3">Numerical Functions</A></H2>
|
|
<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.
|
|
</P>
|
|
<P>Return <A HREF="#top">to top of page</A> or
|
|
<A HREF="../faq/index.html">to the FAQ</A>.
|
|
</P>
|
|
|
|
<HR>
|
|
<H2><A NAME="4">C99</A></H2>
|
|
<P>In addition to the other topics on this page, we'll note here some
|
|
of the C99 features that appear in libstdc++-v3.
|
|
</P>
|
|
<P>The C99 features depend on the <TT>--enable-c99</TT> configure flag.
|
|
This flag is already on by default, but it can be disabled by the
|
|
user. Also, the configuration machinery will disable it if the
|
|
neccessary support for C99 (e.g., header files) cannot be found.
|
|
</P>
|
|
<P>As of GCC 3.0, C99 support includes classification functions
|
|
such as <TT>isnormal</TT>, <TT>isgreater</TT>, <TT>isnan</TT>, etc.
|
|
The functions used for 'long long' support such as <TT>strtoll</TT>
|
|
are supported, as is the <TT>lldiv_t</TT> typedef. Also supported
|
|
are the wide character functions using 'long long', like
|
|
<TT>wcstoll</TT>.
|
|
</P>
|
|
<P>Return <A HREF="#top">to top of page</A> or
|
|
<A HREF="../faq/index.html">to the FAQ</A>.
|
|
</P>
|
|
|
|
|
|
|
|
<!-- ####################################################### -->
|
|
|
|
<HR>
|
|
<P CLASS="fineprint"><EM>
|
|
Comments and suggestions are welcome, and may be sent to
|
|
<A HREF="mailto:libstdc++@gcc.gnu.org">the mailing list</A>.
|
|
<BR> $Id: howto.html,v 1.2 2001/04/03 00:26:56 pme Exp $
|
|
</EM></P>
|
|
|
|
|
|
</BODY>
|
|
</HTML>
|