Merge -r 127928:132243 from trunk
[official-gcc.git] / libstdc++-v3 / doc / xml / manual / numerics.xml
blob835cd1e745403b8e7aba1dafbde2a492ffc52a68
1 <?xml version='1.0'?>
2 <!DOCTYPE part PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" 
3  "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" 
4 [ ]>
6 <part id="manual.numerics" xreflabel="Numerics">
7 <?dbhtml filename="numerics.html"?>
8  
9 <partinfo>
10   <keywordset>
11     <keyword>
12       ISO C++
13     </keyword>
14     <keyword>
15       library
16     </keyword>
17   </keywordset>
18 </partinfo>
20 <title>Numerics</title>
22 <!-- Chapter 01 : Complex -->
23 <chapter id="manual.numerics.complex" xreflabel="complex">
24   <title>Complex</title>
25   <para>
26   </para>
27   <sect1 id="numerics.complex.processing" xreflabel="complex Processing">
28     <title>complex Processing</title>
29     <para>
30     </para>
31    <para>Using <code>complex&lt;&gt;</code> becomes even more comple- er, sorry,
32       <emphasis>complicated</emphasis>, with the not-quite-gratuitously-incompatible
33       addition of complex types to the C language.  David Tribble has
34       compiled a list of C++98 and C99 conflict points; his description of
35       C's new type versus those of C++ and how to get them playing together
36       nicely is
37 <ulink url="http://david.tribble.com/text/cdiffs.htm#C99-complex">here</ulink>.
38    </para>
39    <para><code>complex&lt;&gt;</code> is intended to be instantiated with a
40       floating-point type.  As long as you meet that and some other basic
41       requirements, then the resulting instantiation has all of the usual
42       math operators defined, as well as definitions of <code>op&lt;&lt;</code>
43       and <code>op&gt;&gt;</code> that work with iostreams: <code>op&lt;&lt;</code>
44       prints <code>(u,v)</code> and <code>op&gt;&gt;</code> can read <code>u</code>,
45       <code>(u)</code>, and <code>(u,v)</code>.
46    </para>
48   </sect1>
49 </chapter>
51 <!-- Chapter 02 : Generalized Operations -->
52 <chapter id="manual.numerics.generalized_ops" xreflabel="Generalized Ops">
53   <title>Generalized Operations</title>
54   <para>
55   </para>
57    <para>There are four generalized functions in the &lt;numeric&gt; header
58       that follow the same conventions as those in &lt;algorithm&gt;.  Each
59       of them is overloaded:  one signature for common default operations,
60       and a second for fully general operations.  Their names are
61       self-explanatory to anyone who works with numerics on a regular basis:
62    </para>
63    <itemizedlist>
64       <listitem><para><code>accumulate</code></para></listitem>
65       <listitem><para><code>inner_product</code></para></listitem>
66       <listitem><para><code>partial_sum</code></para></listitem>
67       <listitem><para><code>adjacent_difference</code></para></listitem>
68    </itemizedlist>
69    <para>Here is a simple example of the two forms of <code>accumulate</code>.
70    </para>
71    <programlisting>
72    int   ar[50];
73    int   someval = somefunction();
75    // ...initialize members of ar to something...
77    int  sum       = std::accumulate(ar,ar+50,0);
78    int  sum_stuff = std::accumulate(ar,ar+50,someval);
79    int  product   = std::accumulate(ar,ar+50,1,std::multiplies&lt;int&gt;());
80    </programlisting>
81    <para>The first call adds all the members of the array, using zero as an
82       initial value for <code>sum</code>.  The second does the same, but uses
83       <code>someval</code> as the starting value (thus, <code>sum_stuff == sum +
84       someval</code>).  The final call uses the second of the two signatures,
85       and multiplies all the members of the array; here we must obviously
86       use 1 as a starting value instead of 0.
87    </para>
88    <para>The other three functions have similar dual-signature forms.
89    </para>
91 </chapter>
93 <!-- Chapter 03 : Interacting with C -->
94 <chapter id="manual.numerics.c" xreflabel="Interacting with C">
95   <title>Interacting with C</title>
97   <sect1 id="numerics.c.array" xreflabel="Numerics vs. Arrays">
98     <title>Numerics vs. Arrays</title>
100    <para>One of the major reasons why FORTRAN can chew through numbers so well
101       is that it is defined to be free of pointer aliasing, an assumption
102       that C89 is not allowed to make, and neither is C++98.  C99 adds a new
103       keyword, <code>restrict</code>, to apply to individual pointers.  The
104       C++ solution is contained in the library rather than the language
105       (although many vendors can be expected to add this to their compilers
106       as an extension).
107    </para>
108    <para>That library solution is a set of two classes, five template classes,
109       and &quot;a whole bunch&quot; of functions.  The classes are required
110       to be free of pointer aliasing, so compilers can optimize the
111       daylights out of them the same way that they have been for FORTRAN.
112       They are collectively called <code>valarray</code>, although strictly
113       speaking this is only one of the five template classes, and they are
114       designed to be familiar to people who have worked with the BLAS
115       libraries before.
116    </para>
118   </sect1>
120   <sect1 id="numerics.c.c99" xreflabel="C99">
121     <title>C99</title>
123    <para>In addition to the other topics on this page, we'll note here some
124       of the C99 features that appear in libstdc++.
125    </para>
126    <para>The C99 features depend on the <code>--enable-c99</code> configure flag.
127       This flag is already on by default, but it can be disabled by the
128       user.  Also, the configuration machinery will disable it if the
129       necessary support for C99 (e.g., header files) cannot be found.
130    </para>
131    <para>As of GCC 3.0, C99 support includes classification functions
132       such as <code>isnormal</code>, <code>isgreater</code>,
133       <code>isnan</code>, etc.
134       The functions used for 'long long' support such as <code>strtoll</code>
135       are supported, as is the <code>lldiv_t</code> typedef.  Also supported
136       are the wide character functions using 'long long', like
137       <code>wcstoll</code>.
138    </para>
140   </sect1>
141 </chapter>
143 </part>