ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
main.cpp
Go to the documentation of this file.
1 /* This file is part of the Vc library.
2 
3  Copyright (C) 2009-2012 Matthias Kretz <kretz@kde.org>
4 
5  Permission to use, copy, modify, and distribute this software
6  and its documentation for any purpose and without fee is hereby
7  granted, provided that the above copyright notice appear in all
8  copies and that both that the copyright notice and this
9  permission notice and warranty disclaimer appear in supporting
10  documentation, and that the name of the author not be used in
11  advertising or publicity pertaining to distribution of the
12  software without specific, written prior permission.
13 
14  The author disclaim all warranties with regard to this
15  software, including all implied warranties of merchantability
16  and fitness. In no event shall the author be liable for any
17  special, indirect or consequential damages or any damages
18  whatsoever resulting from loss of use, data or profits, whether
19  in an action of contract, negligence or other tortious action,
20  arising out of or in connection with the use or performance of
21  this software.
22 
23 */
24 
25 //! [includes]
26 #include <Vc/Vc>
27 #include <iostream>
28 #include <iomanip>
29 
30 using Vc::float_v;
31 //! [includes]
32 
33 //! [memory allocation]
34 int main()
35 {
36  // allocate memory for our initial x and y coordinates. Note that you can also put it into a
37  // normal float C-array but that you then must ensure alignment to Vc::VectorAlignment!
42 //! [memory allocation]
43 
44 //! [random init]
45  // fill the memory with values from -1.f to 1.f
46  for (size_t i = 0; i < x_mem.vectorsCount(); ++i) {
47  x_mem.vector(i) = float_v::Random() * 2.f - 1.f;
48  y_mem.vector(i) = float_v::Random() * 2.f - 1.f;
49  }
50 //! [random init]
51 
52 //! [conversion]
53  // calculate the polar coordinates for all coordinates and overwrite the euclidian coordinates
54  // with the result
55  for (size_t i = 0; i < x_mem.vectorsCount(); ++i) {
56  const float_v x = x_mem.vector(i);
57  const float_v y = y_mem.vector(i);
58 
59  r_mem.vector(i) = Vc::sqrt(x * x + y * y);
60  float_v phi = Vc::atan2(y, x) * 57.295780181884765625f; // 180/pi
61  phi(phi < 0.f) += 360.f;
62  phi_mem.vector(i) = phi;
63  }
64 //! [conversion]
65 
66 //! [output]
67  // print the results
68  for (size_t i = 0; i < x_mem.entriesCount(); ++i) {
69  std::cout << std::setw(3) << i << ": ";
70  std::cout << std::setw(10) << x_mem[i] << ", " << std::setw(10) << y_mem[i] << " -> ";
71  std::cout << std::setw(10) << r_mem[i] << ", " << std::setw(10) << phi_mem[i] << '\n';
72  }
73 
74  return 0;
75 }
76 //! [output]
_VC_CONSTEXPR size_t vectorsCount() const
Definition: memory.h:169
TFile * f
_VC_CONSTEXPR size_t entriesCount() const
Definition: memory.h:163
double sqrt(double)
Double_t x[n]
Definition: legend1.C:17
Vc_ALWAYS_INLINE Vc_PURE VectorPointerHelper< V, AlignedFlag > vector(size_t i)
Definition: memorybase.h:310
Float_t phi
Definition: shapesAnim.C:6
A helper class for fixed-size two-dimensional arrays.
Definition: memory.h:120
void Random()
Definition: utils.cpp:154
double atan2(double, double)
int main(int argc, char **argv)
Main program.
Definition: main.cpp:22
Double_t y[n]
Definition: legend1.C:17
Vector< float > float_v
Definition: vector.h:417