OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [libstdc++-v3/] [doc/] [xml/] [manual/] [numerics.xml] - Blame information for rev 424

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.