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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libstdc++-v3/] [doc/] [xml/] [manual/] [numerics.xml] - Blame information for rev 833

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

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

powered by: WebSVN 2.1.0

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