summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@gmail.com>2013-08-20 12:35:45 -0400
committerErik Schnetter <schnetter@gmail.com>2013-08-20 12:35:45 -0400
commit321b65c347172eb2222fe8a540a6dd0a157cea72 (patch)
treeca720093c4b2ffe7c83a3a3187d6cf23ad65d378
parent4ae58dcb5e5c951d15a5e2052a299e2d2d98bee0 (diff)
downloadvecmathlib-321b65c347172eb2222fe8a540a6dd0a157cea72.zip
vecmathlib-321b65c347172eb2222fe8a540a6dd0a157cea72.tar.gz
Add single-precision example
-rw-r--r--.gitignore1
-rw-r--r--example_float.cc40
2 files changed, 41 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 8f80bb6..ff8b7cf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,3 +18,4 @@ loop
instantiations
.ninja_deps
interp
+example_float
diff --git a/example_float.cc b/example_float.cc
new file mode 100644
index 0000000..6cdf1a6
--- /dev/null
+++ b/example_float.cc
@@ -0,0 +1,40 @@
+// -*-C++-*-
+
+#include "vecmathlib.h"
+
+#include <iostream>
+
+using namespace std;
+using namespace vecmathlib;
+
+
+
+int main(int argc, char** argv)
+{
+ // Declare a float precision vector with an architecture-dependent
+ // number of elements
+ float_vec x;
+ // Set each element separately. This is inefficient and should be
+ // avoided if possible, but we want to demonstrate it here anyway.
+ for (int i=0; i<float_vec::size; ++i) x.set_elt(i, float(i));
+ float_vec y = x + float_vec(1.0);
+ y = sqrt(y);
+ float_vec z = log(y);
+
+ // Boolean vectors are closely related to either float or float
+ // vectors, thus we need to make a distinction
+ bool_float_vec b = x < y;
+ // Integer vectors are closely related to either float or float,
+ // thus we need to make a distinction -- there is "int_vec"
+ // corresponding to "float_vec", and there is "int_vec"
+ // correpsonding to "float_vec".
+ int_vec i = convert_int(y);
+
+ cout << "x=" << x << "\n";
+ cout << "y=" << y << "\n";
+ cout << "z=" << z << "\n";
+ cout << "b=" << b << "\n";
+ cout << "i=" << i << "\n";
+
+ return 0;
+}
OpenPOWER on IntegriCloud