📄 quaternion.hpp
字号:
return(*this); \ } #define BOOST_QUATERNION_MEMBER_ADD_GENERATOR_3(type) \ template<typename X> \ quaternion<type> & operator += (quaternion<X> const & rhs) \ { \ a += static_cast<type>(rhs.R_component_1()); \ b += static_cast<type>(rhs.R_component_2()); \ c += static_cast<type>(rhs.R_component_3()); \ d += static_cast<type>(rhs.R_component_4()); \ \ return(*this); \ } #define BOOST_QUATERNION_MEMBER_SUB_GENERATOR_1(type) \ quaternion<type> & operator -= (type const & rhs) \ { \ a -= rhs; \ \ return(*this); \ } #define BOOST_QUATERNION_MEMBER_SUB_GENERATOR_2(type) \ quaternion<type> & operator -= (::std::complex<type> const & rhs) \ { \ a -= rhs.real(); \ b -= rhs.imag(); \ \ return(*this); \ } #define BOOST_QUATERNION_MEMBER_SUB_GENERATOR_3(type) \ template<typename X> \ quaternion<type> & operator -= (quaternion<X> const & rhs) \ { \ a -= static_cast<type>(rhs.R_component_1()); \ b -= static_cast<type>(rhs.R_component_2()); \ c -= static_cast<type>(rhs.R_component_3()); \ d -= static_cast<type>(rhs.R_component_4()); \ \ return(*this); \ } #define BOOST_QUATERNION_MEMBER_MUL_GENERATOR_1(type) \ quaternion<type> & operator *= (type const & rhs) \ { \ a *= rhs; \ b *= rhs; \ c *= rhs; \ d *= rhs; \ \ return(*this); \ } #define BOOST_QUATERNION_MEMBER_MUL_GENERATOR_2(type) \ quaternion<type> & operator *= (::std::complex<type> const & rhs) \ { \ type ar = rhs.real(); \ type br = rhs.imag(); \ \ type at = +a*ar-b*br; \ type bt = +a*br+b*ar; \ type ct = +c*ar+d*br; \ type dt = -c*br+d*ar; \ \ a = at; \ b = bt; \ c = ct; \ d = dt; \ \ return(*this); \ } #define BOOST_QUATERNION_MEMBER_MUL_GENERATOR_3(type) \ template<typename X> \ quaternion<type> & operator *= (quaternion<X> const & rhs) \ { \ type ar = static_cast<type>(rhs.R_component_1()); \ type br = static_cast<type>(rhs.R_component_2()); \ type cr = static_cast<type>(rhs.R_component_3()); \ type dr = static_cast<type>(rhs.R_component_4()); \ \ type at = +a*ar-b*br-c*cr-d*dr; \ type bt = +a*br+b*ar+c*dr-d*cr; \ type ct = +a*cr-b*dr+c*ar+d*br; \ type dt = +a*dr+b*cr-c*br+d*ar; \ \ a = at; \ b = bt; \ c = ct; \ d = dt; \ \ return(*this); \ } // There is quite a lot of repetition in the code below. This is intentional.// The last conditional block is the normal form, and the others merely// consist of workarounds for various compiler deficiencies. Hopefuly, when// more compilers are conformant and we can retire support for those that are// not, we will be able to remove the clutter. This is makes the situation// (painfully) explicit. #define BOOST_QUATERNION_MEMBER_DIV_GENERATOR_1(type) \ quaternion<type> & operator /= (type const & rhs) \ { \ a /= rhs; \ b /= rhs; \ c /= rhs; \ d /= rhs; \ \ return(*this); \ }#if defined(__GNUC__) && (__GNUC__ < 3) #define BOOST_QUATERNION_MEMBER_DIV_GENERATOR_2(type) \ quaternion<type> & operator /= (::std::complex<type> const & rhs) \ { \ using ::std::valarray; \ \ valarray<type> tr(2); \ \ tr[0] = rhs.real(); \ tr[1] = rhs.imag(); \ \ type mixam = (BOOST_GET_VALARRAY(type,static_cast<type>(1)/abs(tr)).max)(); \ \ tr *= mixam; \ \ valarray<type> tt(4); \ \ tt[0] = +a*tr[0]+b*tr[1]; \ tt[1] = -a*tr[1]+b*tr[0]; \ tt[2] = +c*tr[0]-d*tr[1]; \ tt[3] = +c*tr[1]+d*tr[0]; \ \ tr *= tr; \ \ tt *= (mixam/tr.sum()); \ \ a = tt[0]; \ b = tt[1]; \ c = tt[2]; \ d = tt[3]; \ \ return(*this); \ }#elif defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) #define BOOST_QUATERNION_MEMBER_DIV_GENERATOR_2(type) \ quaternion<type> & operator /= (::std::complex<type> const & rhs) \ { \ using ::std::valarray; \ using ::std::abs; \ \ valarray<type> tr(2); \ \ tr[0] = rhs.real(); \ tr[1] = rhs.imag(); \ \ type mixam = static_cast<type>(1)/(abs(tr).max)(); \ \ tr *= mixam; \ \ valarray<type> tt(4); \ \ tt[0] = +a*tr[0]+b*tr[1]; \ tt[1] = -a*tr[1]+b*tr[0]; \ tt[2] = +c*tr[0]-d*tr[1]; \ tt[3] = +c*tr[1]+d*tr[0]; \ \ tr *= tr; \ \ tt *= (mixam/tr.sum()); \ \ a = tt[0]; \ b = tt[1]; \ c = tt[2]; \ d = tt[3]; \ \ return(*this); \ }#else #define BOOST_QUATERNION_MEMBER_DIV_GENERATOR_2(type) \ quaternion<type> & operator /= (::std::complex<type> const & rhs) \ { \ using ::std::valarray; \ \ valarray<type> tr(2); \ \ tr[0] = rhs.real(); \ tr[1] = rhs.imag(); \ \ type mixam = static_cast<type>(1)/(abs(tr).max)(); \ \ tr *= mixam; \ \ valarray<type> tt(4); \ \ tt[0] = +a*tr[0]+b*tr[1]; \ tt[1] = -a*tr[1]+b*tr[0]; \ tt[2] = +c*tr[0]-d*tr[1]; \ tt[3] = +c*tr[1]+d*tr[0]; \ \ tr *= tr; \ \ tt *= (mixam/tr.sum()); \ \ a = tt[0]; \ b = tt[1]; \ c = tt[2]; \ d = tt[3]; \ \ return(*this); \ }#endif /* defined(__GNUC__) && (__GNUC__ < 3) */ /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ #if defined(__GNUC__) && (__GNUC__ < 3) #define BOOST_QUATERNION_MEMBER_DIV_GENERATOR_3(type) \ template<typename X> \ quaternion<type> & operator /= (quaternion<X> const & rhs) \ { \ using ::std::valarray; \ \ valarray<type> tr(4); \ \ tr[0] = static_cast<type>(rhs.R_component_1()); \ tr[1] = static_cast<type>(rhs.R_component_2()); \ tr[2] = static_cast<type>(rhs.R_component_3()); \ tr[3] = static_cast<type>(rhs.R_component_4()); \ \ type mixam = (BOOST_GET_VALARRAY(type,static_cast<type>(1)/abs(tr)).max)(); \ \ tr *= mixam; \ \ valarray<type> tt(4); \ \ tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]; \ tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]; \ tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]; \ tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]; \ \ tr *= tr; \ \ tt *= (mixam/tr.sum()); \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -