📄 octonion.hpp
字号:
type ct = +c*ar+d*br; \ type dt = -c*br+d*ar; \ type et = +e*ar+f*br; \ type ft = -e*br+f*ar; \ type gt = +g*ar-h*br; \ type ht = +g*br+h*ar; \ \ a = at; \ b = bt; \ c = ct; \ d = dt; \ e = et; \ f = ft; \ g = gt; \ h = ht; \ \ return(*this); \ } #define BOOST_OCTONION_MEMBER_MUL_GENERATOR_3(type) \ octonion<type> & operator *= (::boost::math::quaternion<type> const & rhs) \ { \ type ar = rhs.R_component_1(); \ type br = rhs.R_component_2(); \ type cr = rhs.R_component_2(); \ type dr = rhs.R_component_2(); \ \ 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; \ type et = +e*ar+f*br+g*cr+h*dr; \ type ft = -e*br+f*ar-g*dr+h*cr; \ type gt = -e*cr+f*dr+g*ar-h*br; \ type ht = -e*dr-f*cr+g*br+h*ar; \ \ a = at; \ b = bt; \ c = ct; \ d = dt; \ e = et; \ f = ft; \ g = gt; \ h = ht; \ \ return(*this); \ } #define BOOST_OCTONION_MEMBER_MUL_GENERATOR_4(type) \ template<typename X> \ octonion<type> & operator *= (octonion<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 er = static_cast<type>(rhs.R_component_5()); \ type fr = static_cast<type>(rhs.R_component_6()); \ type gr = static_cast<type>(rhs.R_component_7()); \ type hr = static_cast<type>(rhs.R_component_8()); \ \ type at = +a*ar-b*br-c*cr-d*dr-e*er-f*fr-g*gr-h*hr; \ type bt = +a*br+b*ar+c*dr-d*cr+e*fr-f*er-g*hr+h*gr; \ type ct = +a*cr-b*dr+c*ar+d*br+e*gr+f*hr-g*er-h*fr; \ type dt = +a*dr+b*cr-c*br+d*ar+e*hr-f*gr+g*fr-h*er; \ type et = +a*er-b*fr-c*gr-d*hr+e*ar+f*br+g*cr+h*dr; \ type ft = +a*fr+b*er-c*hr+d*gr-e*br+f*ar-g*dr+h*cr; \ type gt = +a*gr+b*hr+c*er-d*fr-e*cr+f*dr+g*ar-h*br; \ type ht = +a*hr-b*gr+c*fr+d*er-e*dr-f*cr+g*br+h*ar; \ \ a = at; \ b = bt; \ c = ct; \ d = dt; \ e = et; \ f = ft; \ g = gt; \ h = ht; \ \ 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_OCTONION_MEMBER_DIV_GENERATOR_1(type) \ octonion<type> & operator /= (type const & rhs) \ { \ a /= rhs; \ b /= rhs; \ c /= rhs; \ d /= rhs; \ \ return(*this); \ } #if defined(__GNUC__) && (__GNUC__ < 3) #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_2(type) \ octonion<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(8); \ \ 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]; \ tt[4] = +e*tr[0]-f*tr[1]; \ tt[5] = +e*tr[1]+f*tr[0]; \ tt[6] = +g*tr[0]+h*tr[1]; \ tt[7] = +g*tr[1]+h*tr[0]; \ \ tr *= tr; \ \ tt *= (mixam/tr.sum()); \ \ a = tt[0]; \ b = tt[1]; \ c = tt[2]; \ d = tt[3]; \ e = tt[4]; \ f = tt[5]; \ g = tt[6]; \ h = tt[7]; \ \ return(*this); \ }#elif defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_2(type) \ octonion<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(8); \ \ 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]; \ tt[4] = +e*tr[0]-f*tr[1]; \ tt[5] = +e*tr[1]+f*tr[0]; \ tt[6] = +g*tr[0]+h*tr[1]; \ tt[7] = +g*tr[1]+h*tr[0]; \ \ tr *= tr; \ \ tt *= (mixam/tr.sum()); \ \ a = tt[0]; \ b = tt[1]; \ c = tt[2]; \ d = tt[3]; \ e = tt[4]; \ f = tt[5]; \ g = tt[6]; \ h = tt[7]; \ \ return(*this); \ }#else #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_2(type) \ octonion<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(8); \ \ 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]; \ tt[4] = +e*tr[0]-f*tr[1]; \ tt[5] = +e*tr[1]+f*tr[0]; \ tt[6] = +g*tr[0]+h*tr[1]; \ tt[7] = +g*tr[1]+h*tr[0]; \ \ tr *= tr; \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -