+/*
+ * Print the vector to stdout.
+ */
+INLINE_MAYBE
+void vec_print(vec_t v)
+{
+#if (SCALAR_SIZE == 8)
+ const char* fmt = "[ %9.5lf %9.5lf %9.5lf %9.5lf ]";
+#else
+ const char* fmt = "[ %9.5f %9.5f %9.5f %9.5f ]";
+#endif
+ printf(fmt, v.x, v.y, v.z, v.w);
+}
+
+
+/*
+ * Calculate the magnitude of the vector, squared.
+ */
+INLINE_MAYBE
+scal_t vec_length2(vec_t v)
+{
+ return v.x * v.x + v.y * v.y + v.z * v.z;
+}
+
+/*
+ * Calculate the magnitude of the vector.
+ */
+INLINE_MAYBE
+scal_t vec_length(vec_t v)
+{
+ return scal_sqrt(vec_length2(v));
+}
+
+
+/*
+ * Determine whether or not two vectors are exactly equal.
+ */
+INLINE_MAYBE
+bool vec_isequal(vec_t a, vec_t b)
+{
+ return (a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w);
+}
+
+INLINE_MAYBE
+int vec_compare(vec_t a, vec_t b)
+{
+ if (vec_isequal(a, b)) {
+ return 0;
+ }
+ return vec_length2(a) < vec_length2(b) ? -1 : 1;
+}
+
+