diff --git a/Eigen/src/Geometry/Quaternion.h b/Eigen/src/Geometry/Quaternion.h index dd1217e5e..bebfca422 100644 --- a/Eigen/src/Geometry/Quaternion.h +++ b/Eigen/src/Geometry/Quaternion.h @@ -197,20 +197,25 @@ class QuaternionBase : public RotationBase #else template - EIGEN_DEVICE_FUNC inline + EIGEN_DEVICE_FUNC inline typename internal::enable_if::value,const Derived&>::type cast() const { return derived(); } template - EIGEN_DEVICE_FUNC inline + EIGEN_DEVICE_FUNC inline typename internal::enable_if::value,Quaternion >::type cast() const { return Quaternion(coeffs().template cast()); } #endif + friend std::ostream& operator<<(std::ostream& s, const QuaternionBase& q) { + s << q.x() << "i + " << q.y() << "j + " << q.z() << "k" << " + " << q.w(); + return s; + } + #ifdef EIGEN_QUATERNIONBASE_PLUGIN # include EIGEN_QUATERNIONBASE_PLUGIN #endif diff --git a/test/geo_quaternion.cpp b/test/geo_quaternion.cpp index 1da683c0e..b339a5f39 100644 --- a/test/geo_quaternion.cpp +++ b/test/geo_quaternion.cpp @@ -75,6 +75,11 @@ template void quaternion(void) q1.coeffs().setRandom(); VERIFY_IS_APPROX(q1.coeffs(), (q1*q2).coeffs()); + // Printing + std::ostringstream ss; + ss << q2; + VERIFY(ss.str() == "0i + 0j + 0k + 1"); + // concatenation q1 *= q2;