x
Yes
No
Do you want to visit DriveHQ English website?
首页
产品服务
价格
免费试用
下载客户端
关于我们
云文件服务
|
云备份服务
|
FTP服务
|
企业邮箱服务
|
网站托管
|
客户端软件
云文件服务
云备份服务
FTP服务
企业级邮箱服务
网站托管
客户端软件
octonion.hpp - Hosted on DriveHQ Cloud IT Platform
返回上层目录
上传
下载
共享
发布
新建文件夹
新建文件
复制
剪切
删除
粘贴
评论
升级服务
路径: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\references\boost_1_35_0\boost\math\octonion.hpp
旋转
特效
属性
历史版本
// boost octonion.hpp header file // (C) Copyright Hubert Holin 2001. // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // See http://www.boost.org for updates, documentation, and revision history. #ifndef BOOST_OCTONION_HPP #define BOOST_OCTONION_HPP #include
namespace boost { namespace math { #if BOOST_WORKAROUND(__GNUC__, < 3) // gcc 2.95.x uses expression templates for valarray calculations, but // the result is not conforming. We need BOOST_GET_VALARRAY to get an // actual valarray result when we need to call a member function #define BOOST_GET_VALARRAY(T,x) ::std::valarray
(x) // gcc 2.95.x has an "std::ios" class that is similar to // "std::ios_base", so we just use a #define #define BOOST_IOS_BASE ::std::ios // gcc 2.x ignores function scope using declarations, // put them in the scope of the enclosing namespace instead: using ::std::valarray; using ::std::sqrt; using ::std::cos; using ::std::sin; using ::std::exp; using ::std::cosh; #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ #define BOOST_OCTONION_ACCESSOR_GENERATOR(type) \ type real() const \ { \ return(a); \ } \ \ octonion
unreal() const \ { \ return( octonion
(static_cast
(0),b,c,d,e,f,g,h)); \ } \ \ type R_component_1() const \ { \ return(a); \ } \ \ type R_component_2() const \ { \ return(b); \ } \ \ type R_component_3() const \ { \ return(c); \ } \ \ type R_component_4() const \ { \ return(d); \ } \ \ type R_component_5() const \ { \ return(e); \ } \ \ type R_component_6() const \ { \ return(f); \ } \ \ type R_component_7() const \ { \ return(g); \ } \ \ type R_component_8() const \ { \ return(h); \ } \ \ ::std::complex
C_component_1() const \ { \ return(::std::complex
(a,b)); \ } \ \ ::std::complex
C_component_2() const \ { \ return(::std::complex
(c,d)); \ } \ \ ::std::complex
C_component_3() const \ { \ return(::std::complex
(e,f)); \ } \ \ ::std::complex
C_component_4() const \ { \ return(::std::complex
(g,h)); \ } \ \ ::boost::math::quaternion
H_component_1() const \ { \ return(::boost::math::quaternion
(a,b,c,d)); \ } \ \ ::boost::math::quaternion
H_component_2() const \ { \ return(::boost::math::quaternion
(e,f,g,h)); \ } #define BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(type) \ template
\ octonion
& operator = (octonion
const & a_affecter) \ { \ a = static_cast
(a_affecter.R_component_1()); \ b = static_cast
(a_affecter.R_component_2()); \ c = static_cast
(a_affecter.R_component_3()); \ d = static_cast
(a_affecter.R_component_4()); \ e = static_cast
(a_affecter.R_component_5()); \ f = static_cast
(a_affecter.R_component_6()); \ g = static_cast
(a_affecter.R_component_7()); \ h = static_cast
(a_affecter.R_component_8()); \ \ return(*this); \ } \ \ octonion
& operator = (octonion
const & a_affecter) \ { \ a = a_affecter.a; \ b = a_affecter.b; \ c = a_affecter.c; \ d = a_affecter.d; \ e = a_affecter.e; \ f = a_affecter.f; \ g = a_affecter.g; \ h = a_affecter.h; \ \ return(*this); \ } \ \ octonion
& operator = (type const & a_affecter) \ { \ a = a_affecter; \ \ b = c = d = e = f= g = h = static_cast
(0); \ \ return(*this); \ } \ \ octonion
& operator = (::std::complex
const & a_affecter) \ { \ a = a_affecter.real(); \ b = a_affecter.imag(); \ \ c = d = e = f = g = h = static_cast
(0); \ \ return(*this); \ } \ \ octonion
& operator = (::boost::math::quaternion
const & a_affecter) \ { \ a = a_affecter.R_component_1(); \ b = a_affecter.R_component_2(); \ c = a_affecter.R_component_3(); \ d = a_affecter.R_component_4(); \ \ e = f = g = h = static_cast
(0); \ \ return(*this); \ } #define BOOST_OCTONION_MEMBER_DATA_GENERATOR(type) \ type a; \ type b; \ type c; \ type d; \ type e; \ type f; \ type g; \ type h; \ template
class octonion { public: typedef T value_type; // constructor for O seen as R^8 // (also default constructor) explicit octonion( T const & requested_a = T(), T const & requested_b = T(), T const & requested_c = T(), T const & requested_d = T(), T const & requested_e = T(), T const & requested_f = T(), T const & requested_g = T(), T const & requested_h = T()) : a(requested_a), b(requested_b), c(requested_c), d(requested_d), e(requested_e), f(requested_f), g(requested_g), h(requested_h) { // nothing to do! } // constructor for H seen as C^4 explicit octonion( ::std::complex
const & z0, ::std::complex
const & z1 = ::std::complex
(), ::std::complex
const & z2 = ::std::complex
(), ::std::complex
const & z3 = ::std::complex
()) : a(z0.real()), b(z0.imag()), c(z1.real()), d(z1.imag()), e(z2.real()), f(z2.imag()), g(z3.real()), h(z3.imag()) { // nothing to do! } // constructor for O seen as H^2 explicit octonion( ::boost::math::quaternion
const & q0, ::boost::math::quaternion
const & q1 = ::boost::math::quaternion
()) : a(q0.R_component_1()), b(q0.R_component_2()), c(q0.R_component_3()), d(q0.R_component_4()), e(q1.R_component_1()), f(q1.R_component_2()), g(q1.R_component_3()), h(q1.R_component_4()) { // nothing to do! } // UNtemplated copy constructor // (this is taken care of by the compiler itself) // templated copy constructor template
explicit octonion(octonion
const & a_recopier) : a(static_cast
(a_recopier.R_component_1())), b(static_cast
(a_recopier.R_component_2())), c(static_cast
(a_recopier.R_component_3())), d(static_cast
(a_recopier.R_component_4())), e(static_cast
(a_recopier.R_component_5())), f(static_cast
(a_recopier.R_component_6())), g(static_cast
(a_recopier.R_component_7())), h(static_cast
(a_recopier.R_component_8())) { // nothing to do! } // destructor // (this is taken care of by the compiler itself) // accessors // // Note: Like complex number, octonions do have a meaningful notion of "real part", // but unlike them there is no meaningful notion of "imaginary part". // Instead there is an "unreal part" which itself is an octonion, and usually // nothing simpler (as opposed to the complex number case). // However, for practicallity, there are accessors for the other components // (these are necessary for the templated copy constructor, for instance). BOOST_OCTONION_ACCESSOR_GENERATOR(T) // assignment operators BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(T) // other assignment-related operators // // NOTE: Octonion multiplication is *NOT* commutative; // symbolically, "q *= rhs;" means "q = q * rhs;" // and "q /= rhs;" means "q = q * inverse_of(rhs);"; // octonion multiplication is also *NOT* associative octonion
& operator += (T const & rhs) { T at = a + rhs; // exception guard a = at; return(*this); } octonion
& operator += (::std::complex
const & rhs) { T at = a + rhs.real(); // exception guard T bt = b + rhs.imag(); // exception guard a = at; b = bt; return(*this); } octonion
& operator += (::boost::math::quaternion
const & rhs) { T at = a + rhs.R_component_1(); // exception guard T bt = b + rhs.R_component_2(); // exception guard T ct = c + rhs.R_component_3(); // exception guard T dt = d + rhs.R_component_4(); // exception guard a = at; b = bt; c = ct; d = dt; return(*this); } template
octonion
& operator += (octonion
const & rhs) { T at = a + static_cast
(rhs.R_component_1()); // exception guard T bt = b + static_cast
(rhs.R_component_2()); // exception guard T ct = c + static_cast
(rhs.R_component_3()); // exception guard T dt = d + static_cast
(rhs.R_component_4()); // exception guard T et = e + static_cast
(rhs.R_component_5()); // exception guard T ft = f + static_cast
(rhs.R_component_6()); // exception guard T gt = g + static_cast
(rhs.R_component_7()); // exception guard T ht = h + static_cast
(rhs.R_component_8()); // exception guard a = at; b = bt; c = ct; d = dt; e = et; f = ft; g = gt; h = ht; return(*this); } octonion
& operator -= (T const & rhs) { T at = a - rhs; // exception guard a = at; return(*this); } octonion
& operator -= (::std::complex
const & rhs) { T at = a - rhs.real(); // exception guard T bt = b - rhs.imag(); // exception guard a = at; b = bt; return(*this); } octonion
& operator -= (::boost::math::quaternion
const & rhs) { T at = a - rhs.R_component_1(); // exception guard T bt = b - rhs.R_component_2(); // exception guard T ct = c - rhs.R_component_3(); // exception guard T dt = d - rhs.R_component_4(); // exception guard a = at; b = bt; c = ct; d = dt; return(*this); } template
octonion
& operator -= (octonion
const & rhs) { T at = a - static_cast
(rhs.R_component_1()); // exception guard T bt = b - static_cast
(rhs.R_component_2()); // exception guard T ct = c - static_cast
(rhs.R_component_3()); // exception guard T dt = d - static_cast
(rhs.R_component_4()); // exception guard T et = e - static_cast
(rhs.R_component_5()); // exception guard T ft = f - static_cast
(rhs.R_component_6()); // exception guard T gt = g - static_cast
(rhs.R_component_7()); // exception guard T ht = h - static_cast
(rhs.R_component_8()); // exception guard a = at; b = bt; c = ct; d = dt; e = et; f = ft; g = gt; h = ht; return(*this); } octonion
& operator *= (T const & rhs) { T at = a * rhs; // exception guard T bt = b * rhs; // exception guard T ct = c * rhs; // exception guard T dt = d * rhs; // exception guard T et = e * rhs; // exception guard T ft = f * rhs; // exception guard T gt = g * rhs; // exception guard T ht = h * rhs; // exception guard a = at; b = bt; c = ct; d = dt; e = et; f = ft; g = gt; h = ht; return(*this); } octonion
& operator *= (::std::complex
const & rhs) { T ar = rhs.real(); T br = rhs.imag(); T at = +a*ar-b*br; T bt = +a*br+b*ar; T ct = +c*ar+d*br; T dt = -c*br+d*ar; T et = +e*ar+f*br; T ft = -e*br+f*ar; T gt = +g*ar-h*br; T ht = +g*br+h*ar; a = at; b = bt; c = ct; d = dt; e = et; f = ft; g = gt; h = ht; return(*this); } octonion
& operator *= (::boost::math::quaternion
const & rhs) { T ar = rhs.R_component_1(); T br = rhs.R_component_2(); T cr = rhs.R_component_2(); T dr = rhs.R_component_2(); T at = +a*ar-b*br-c*cr-d*dr; T bt = +a*br+b*ar+c*dr-d*cr; T ct = +a*cr-b*dr+c*ar+d*br; T dt = +a*dr+b*cr-c*br+d*ar; T et = +e*ar+f*br+g*cr+h*dr; T ft = -e*br+f*ar-g*dr+h*cr; T gt = -e*cr+f*dr+g*ar-h*br; T 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); } template
octonion
& operator *= (octonion
const & rhs) { T ar = static_cast
(rhs.R_component_1()); T br = static_cast
(rhs.R_component_2()); T cr = static_cast
(rhs.R_component_3()); T dr = static_cast
(rhs.R_component_4()); T er = static_cast
(rhs.R_component_5()); T fr = static_cast
(rhs.R_component_6()); T gr = static_cast
(rhs.R_component_7()); T hr = static_cast
(rhs.R_component_8()); T at = +a*ar-b*br-c*cr-d*dr-e*er-f*fr-g*gr-h*hr; T bt = +a*br+b*ar+c*dr-d*cr+e*fr-f*er-g*hr+h*gr; T ct = +a*cr-b*dr+c*ar+d*br+e*gr+f*hr-g*er-h*fr; T dt = +a*dr+b*cr-c*br+d*ar+e*hr-f*gr+g*fr-h*er; T et = +a*er-b*fr-c*gr-d*hr+e*ar+f*br+g*cr+h*dr; T ft = +a*fr+b*er-c*hr+d*gr-e*br+f*ar-g*dr+h*cr; T gt = +a*gr+b*hr+c*er-d*fr-e*cr+f*dr+g*ar-h*br; T 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); } octonion
& operator /= (T const & rhs) { T at = a / rhs; // exception guard T bt = b / rhs; // exception guard T ct = c / rhs; // exception guard T dt = d / rhs; // exception guard T et = e / rhs; // exception guard T ft = f / rhs; // exception guard T gt = g / rhs; // exception guard T ht = h / rhs; // exception guard a = at; b = bt; c = ct; d = dt; e = et; f = ft; g = gt; h = ht; return(*this); } octonion
& operator /= (::std::complex
const & rhs) { T ar = rhs.real(); T br = rhs.imag(); T denominator = ar*ar+br*br; T at = (+a*ar-b*br)/denominator; T bt = (-a*br+b*ar)/denominator; T ct = (+c*ar-d*br)/denominator; T dt = (+c*br+d*ar)/denominator; T et = (+e*ar-f*br)/denominator; T ft = (+e*br+f*ar)/denominator; T gt = (+g*ar+h*br)/denominator; T ht = (+g*br+h*ar)/denominator; a = at; b = bt; c = ct; d = dt; e = et; f = ft; g = gt; h = ht; return(*this); } octonion
& operator /= (::boost::math::quaternion
const & rhs) { T ar = rhs.R_component_1(); T br = rhs.R_component_2(); T cr = rhs.R_component_2(); T dr = rhs.R_component_2(); T denominator = ar*ar+br*br+cr*cr+dr*dr; T at = (+a*ar+b*br+c*cr+d*dr)/denominator; T bt = (-a*br+b*ar-c*dr+d*cr)/denominator; T ct = (-a*cr+b*dr+c*ar-d*br)/denominator; T dt = (-a*dr-b*cr+c*br+d*ar)/denominator; T et = (+e*ar-f*br-g*cr-h*dr)/denominator; T ft = (+e*br+f*ar+g*dr-h*cr)/denominator; T gt = (+e*cr-f*dr+g*ar+h*br)/denominator; T ht = (+e*dr+f*cr-g*br+h*ar)/denominator; a = at; b = bt; c = ct; d = dt; e = et; f = ft; g = gt; h = ht; return(*this); } template
octonion
& operator /= (octonion
const & rhs) { T ar = static_cast
(rhs.R_component_1()); T br = static_cast
(rhs.R_component_2()); T cr = static_cast
(rhs.R_component_3()); T dr = static_cast
(rhs.R_component_4()); T er = static_cast
(rhs.R_component_5()); T fr = static_cast
(rhs.R_component_6()); T gr = static_cast
(rhs.R_component_7()); T hr = static_cast
(rhs.R_component_8()); T denominator = ar*ar+br*br+cr*cr+dr*dr+er*er+fr*fr+gr*gr+hr*hr; T at = (+a*ar+b*br+c*cr+d*dr+e*er+f*fr+g*gr+h*hr)/denominator; T bt = (-a*br+b*ar-c*dr+d*cr-e*fr+f*er+g*hr-h*gr)/denominator; T ct = (-a*cr+b*dr+c*ar-d*br-e*gr-f*hr+g*er+h*fr)/denominator; T dt = (-a*dr-b*cr+c*br+d*ar-e*hr+f*gr-g*fr+h*er)/denominator; T et = (-a*er+b*fr+c*gr+d*hr+e*ar-f*br-g*cr-h*dr)/denominator; T ft = (-a*fr-b*er+c*hr-d*gr+e*br+f*ar+g*dr-h*cr)/denominator; T gt = (-a*gr-b*hr-c*er+d*fr+e*cr-f*dr+g*ar+h*br)/denominator; T ht = (-a*hr+b*gr-c*fr-d*er+e*dr+f*cr-g*br+h*ar)/denominator; a = at; b = bt; c = ct; d = dt; e = et; f = ft; g = gt; h = ht; return(*this); } protected: BOOST_OCTONION_MEMBER_DATA_GENERATOR(T) private: }; // declaration of octonion specialization template<> class octonion
; template<> class octonion
; template<> class octonion
; // helper templates for converting copy constructors (declaration) namespace detail { template< typename T, typename U > octonion
octonion_type_converter(octonion
const & rhs); } // implementation of octonion specialization #define BOOST_OCTONION_CONSTRUCTOR_GENERATOR(type) \ explicit octonion( type const & requested_a = static_cast
(0), \ type const & requested_b = static_cast
(0), \ type const & requested_c = static_cast
(0), \ type const & requested_d = static_cast
(0), \ type const & requested_e = static_cast
(0), \ type const & requested_f = static_cast
(0), \ type const & requested_g = static_cast
(0), \ type const & requested_h = static_cast
(0)) \ : a(requested_a), \ b(requested_b), \ c(requested_c), \ d(requested_d), \ e(requested_e), \ f(requested_f), \ g(requested_g), \ h(requested_h) \ { \ } \ \ explicit octonion( ::std::complex
const & z0, \ ::std::complex
const & z1 = ::std::complex
(), \ ::std::complex
const & z2 = ::std::complex
(), \ ::std::complex
const & z3 = ::std::complex
()) \ : a(z0.real()), \ b(z0.imag()), \ c(z1.real()), \ d(z1.imag()), \ e(z2.real()), \ f(z2.imag()), \ g(z3.real()), \ h(z3.imag()) \ { \ } \ \ explicit octonion( ::boost::math::quaternion
const & q0, \ ::boost::math::quaternion
const & q1 = ::boost::math::quaternion
()) \ : a(q0.R_component_1()), \ b(q0.R_component_2()), \ c(q0.R_component_3()), \ d(q0.R_component_4()), \ e(q1.R_component_1()), \ f(q1.R_component_2()), \ g(q1.R_component_3()), \ h(q1.R_component_4()) \ { \ } #define BOOST_OCTONION_MEMBER_ADD_GENERATOR_1(type) \ octonion
& operator += (type const & rhs) \ { \ a += rhs; \ \ return(*this); \ } #define BOOST_OCTONION_MEMBER_ADD_GENERATOR_2(type) \ octonion
& operator += (::std::complex
const & rhs) \ { \ a += rhs.real(); \ b += rhs.imag(); \ \ return(*this); \ } #define BOOST_OCTONION_MEMBER_ADD_GENERATOR_3(type) \ octonion
& operator += (::boost::math::quaternion
const & rhs) \ { \ a += rhs.R_component_1(); \ b += rhs.R_component_2(); \ c += rhs.R_component_3(); \ d += rhs.R_component_4(); \ \ return(*this); \ } #define BOOST_OCTONION_MEMBER_ADD_GENERATOR_4(type) \ template
\ octonion
& operator += (octonion
const & rhs) \ { \ a += static_cast
(rhs.R_component_1()); \ b += static_cast
(rhs.R_component_2()); \ c += static_cast
(rhs.R_component_3()); \ d += static_cast
(rhs.R_component_4()); \ e += static_cast
(rhs.R_component_5()); \ f += static_cast
(rhs.R_component_6()); \ g += static_cast
(rhs.R_component_7()); \ h += static_cast
(rhs.R_component_8()); \ \ return(*this); \ } #define BOOST_OCTONION_MEMBER_SUB_GENERATOR_1(type) \ octonion
& operator -= (type const & rhs) \ { \ a -= rhs; \ \ return(*this); \ } #define BOOST_OCTONION_MEMBER_SUB_GENERATOR_2(type) \ octonion
& operator -= (::std::complex
const & rhs) \ { \ a -= rhs.real(); \ b -= rhs.imag(); \ \ return(*this); \ } #define BOOST_OCTONION_MEMBER_SUB_GENERATOR_3(type) \ octonion
& operator -= (::boost::math::quaternion
const & rhs) \ { \ a -= rhs.R_component_1(); \ b -= rhs.R_component_2(); \ c -= rhs.R_component_3(); \ d -= rhs.R_component_4(); \ \ return(*this); \ } #define BOOST_OCTONION_MEMBER_SUB_GENERATOR_4(type) \ template
\ octonion
& operator -= (octonion
const & rhs) \ { \ a -= static_cast
(rhs.R_component_1()); \ b -= static_cast
(rhs.R_component_2()); \ c -= static_cast
(rhs.R_component_3()); \ d -= static_cast
(rhs.R_component_4()); \ e -= static_cast
(rhs.R_component_5()); \ f -= static_cast
(rhs.R_component_6()); \ g -= static_cast
(rhs.R_component_7()); \ h -= static_cast
(rhs.R_component_8()); \ \ return(*this); \ } #define BOOST_OCTONION_MEMBER_MUL_GENERATOR_1(type) \ octonion
& operator *= (type const & rhs) \ { \ a *= rhs; \ b *= rhs; \ c *= rhs; \ d *= rhs; \ e *= rhs; \ f *= rhs; \ g *= rhs; \ h *= rhs; \ \ return(*this); \ } #define BOOST_OCTONION_MEMBER_MUL_GENERATOR_2(type) \ octonion
& operator *= (::std::complex
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; \ 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
& operator *= (::boost::math::quaternion
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
\ octonion
& operator *= (octonion
const & rhs) \ { \ type ar = static_cast
(rhs.R_component_1()); \ type br = static_cast
(rhs.R_component_2()); \ type cr = static_cast
(rhs.R_component_3()); \ type dr = static_cast
(rhs.R_component_4()); \ type er = static_cast
(rhs.R_component_5()); \ type fr = static_cast
(rhs.R_component_6()); \ type gr = static_cast
(rhs.R_component_7()); \ type hr = static_cast
(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
& 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
& operator /= (::std::complex
const & rhs) \ { \ using ::std::valarray; \ \ valarray
tr(2); \ \ tr[0] = rhs.real(); \ tr[1] = rhs.imag(); \ \ type mixam = (BOOST_GET_VALARRAY(type,static_cast
(1)/abs(tr)).max)(); \ \ tr *= mixam; \ \ valarray
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
& operator /= (::std::complex
const & rhs) \ { \ using ::std::valarray; \ using ::std::abs; \ \ valarray
tr(2); \ \ tr[0] = rhs.real(); \ tr[1] = rhs.imag(); \ \ type mixam = static_cast
(1)/(abs(tr).max)(); \ \ tr *= mixam; \ \ valarray
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
& operator /= (::std::complex
const & rhs) \ { \ using ::std::valarray; \ \ valarray
tr(2); \ \ tr[0] = rhs.real(); \ tr[1] = rhs.imag(); \ \ type mixam = static_cast
(1)/(abs(tr).max)(); \ \ tr *= mixam; \ \ valarray
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); \ } #endif /* defined(__GNUC__) && (__GNUC__ < 3) */ /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ #if defined(__GNUC__) && (__GNUC__ < 3) #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_3(type) \ octonion
& operator /= (::boost::math::quaternion
const & rhs) \ { \ using ::std::valarray; \ \ valarray
tr(4); \ \ tr[0] = static_cast
(rhs.R_component_1()); \ tr[1] = static_cast
(rhs.R_component_2()); \ tr[2] = static_cast
(rhs.R_component_3()); \ tr[3] = static_cast
(rhs.R_component_4()); \ \ type mixam = (BOOST_GET_VALARRAY(type,static_cast
(1)/abs(tr)).max)();\ \ tr *= mixam; \ \ valarray
tt(8); \ \ 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]; \ tt[4] = +e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \ tt[5] = +e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \ tt[6] = +e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \ tt[7] = +e*tr[3]+f*tr[2]-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_3(type) \ octonion
& operator /= (::boost::math::quaternion
const & rhs) \ { \ using ::std::valarray; \ using ::std::abs; \ \ valarray
tr(4); \ \ tr[0] = static_cast
(rhs.R_component_1()); \ tr[1] = static_cast
(rhs.R_component_2()); \ tr[2] = static_cast
(rhs.R_component_3()); \ tr[3] = static_cast
(rhs.R_component_4()); \ \ type mixam = static_cast
(1)/(abs(tr).max)(); \ \ tr *= mixam; \ \ valarray
tt(8); \ \ 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]; \ tt[4] = +e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \ tt[5] = +e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \ tt[6] = +e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \ tt[7] = +e*tr[3]+f*tr[2]-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_3(type) \ octonion
& operator /= (::boost::math::quaternion
const & rhs) \ { \ using ::std::valarray; \ \ valarray
tr(4); \ \ tr[0] = static_cast
(rhs.R_component_1()); \ tr[1] = static_cast
(rhs.R_component_2()); \ tr[2] = static_cast
(rhs.R_component_3()); \ tr[3] = static_cast
(rhs.R_component_4()); \ \ type mixam = static_cast
(1)/(abs(tr).max)(); \ \ tr *= mixam; \ \ valarray
tt(8); \ \ 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]; \ tt[4] = +e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \ tt[5] = +e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \ tt[6] = +e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \ tt[7] = +e*tr[3]+f*tr[2]-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); \ } #endif /* defined(__GNUC__) && (__GNUC__ < 3) */ /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ #if defined(__GNUC__) && (__GNUC__ < 3) #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_4(type) \ template
\ octonion
& operator /= (octonion
const & rhs) \ { \ using ::std::valarray; \ \ valarray
tr(8); \ \ tr[0] = static_cast
(rhs.R_component_1()); \ tr[1] = static_cast
(rhs.R_component_2()); \ tr[2] = static_cast
(rhs.R_component_3()); \ tr[3] = static_cast
(rhs.R_component_4()); \ tr[4] = static_cast