sl@0: // boost octonion.hpp header file sl@0: sl@0: // (C) Copyright Hubert Holin 2001. sl@0: // Distributed under the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: sl@0: // See http://www.boost.org for updates, documentation, and revision history. sl@0: sl@0: sl@0: #ifndef BOOST_OCTONION_HPP sl@0: #define BOOST_OCTONION_HPP sl@0: sl@0: #include sl@0: sl@0: sl@0: namespace boost sl@0: { sl@0: namespace math sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: // gcc 2.95.x uses expression templates for valarray calculations, but sl@0: // the result is not conforming. We need BOOST_GET_VALARRAY to get an sl@0: // actual valarray result when we need to call a member function sl@0: #define BOOST_GET_VALARRAY(T,x) ::std::valarray(x) sl@0: // gcc 2.95.x has an "std::ios" class that is similar to sl@0: // "std::ios_base", so we just use a #define sl@0: #define BOOST_IOS_BASE ::std::ios sl@0: // gcc 2.x ignores function scope using declarations, sl@0: // put them in the scope of the enclosing namespace instead: sl@0: using ::std::valarray; sl@0: using ::std::sqrt; sl@0: using ::std::cos; sl@0: using ::std::sin; sl@0: using ::std::exp; sl@0: using ::std::cosh; sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: sl@0: #define BOOST_OCTONION_ACCESSOR_GENERATOR(type) \ sl@0: type real() const \ sl@0: { \ sl@0: return(a); \ sl@0: } \ sl@0: \ sl@0: octonion unreal() const \ sl@0: { \ sl@0: return( octonion(static_cast(0),b,c,d,e,f,g,h)); \ sl@0: } \ sl@0: \ sl@0: type R_component_1() const \ sl@0: { \ sl@0: return(a); \ sl@0: } \ sl@0: \ sl@0: type R_component_2() const \ sl@0: { \ sl@0: return(b); \ sl@0: } \ sl@0: \ sl@0: type R_component_3() const \ sl@0: { \ sl@0: return(c); \ sl@0: } \ sl@0: \ sl@0: type R_component_4() const \ sl@0: { \ sl@0: return(d); \ sl@0: } \ sl@0: \ sl@0: type R_component_5() const \ sl@0: { \ sl@0: return(e); \ sl@0: } \ sl@0: \ sl@0: type R_component_6() const \ sl@0: { \ sl@0: return(f); \ sl@0: } \ sl@0: \ sl@0: type R_component_7() const \ sl@0: { \ sl@0: return(g); \ sl@0: } \ sl@0: \ sl@0: type R_component_8() const \ sl@0: { \ sl@0: return(h); \ sl@0: } \ sl@0: \ sl@0: ::std::complex C_component_1() const \ sl@0: { \ sl@0: return(::std::complex(a,b)); \ sl@0: } \ sl@0: \ sl@0: ::std::complex C_component_2() const \ sl@0: { \ sl@0: return(::std::complex(c,d)); \ sl@0: } \ sl@0: \ sl@0: ::std::complex C_component_3() const \ sl@0: { \ sl@0: return(::std::complex(e,f)); \ sl@0: } \ sl@0: \ sl@0: ::std::complex C_component_4() const \ sl@0: { \ sl@0: return(::std::complex(g,h)); \ sl@0: } \ sl@0: \ sl@0: ::boost::math::quaternion H_component_1() const \ sl@0: { \ sl@0: return(::boost::math::quaternion(a,b,c,d)); \ sl@0: } \ sl@0: \ sl@0: ::boost::math::quaternion H_component_2() const \ sl@0: { \ sl@0: return(::boost::math::quaternion(e,f,g,h)); \ sl@0: } sl@0: sl@0: sl@0: #define BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(type) \ sl@0: template \ sl@0: octonion & operator = (octonion const & a_affecter) \ sl@0: { \ sl@0: a = static_cast(a_affecter.R_component_1()); \ sl@0: b = static_cast(a_affecter.R_component_2()); \ sl@0: c = static_cast(a_affecter.R_component_3()); \ sl@0: d = static_cast(a_affecter.R_component_4()); \ sl@0: e = static_cast(a_affecter.R_component_5()); \ sl@0: f = static_cast(a_affecter.R_component_6()); \ sl@0: g = static_cast(a_affecter.R_component_7()); \ sl@0: h = static_cast(a_affecter.R_component_8()); \ sl@0: \ sl@0: return(*this); \ sl@0: } \ sl@0: \ sl@0: octonion & operator = (octonion const & a_affecter) \ sl@0: { \ sl@0: a = a_affecter.a; \ sl@0: b = a_affecter.b; \ sl@0: c = a_affecter.c; \ sl@0: d = a_affecter.d; \ sl@0: e = a_affecter.e; \ sl@0: f = a_affecter.f; \ sl@0: g = a_affecter.g; \ sl@0: h = a_affecter.h; \ sl@0: \ sl@0: return(*this); \ sl@0: } \ sl@0: \ sl@0: octonion & operator = (type const & a_affecter) \ sl@0: { \ sl@0: a = a_affecter; \ sl@0: \ sl@0: b = c = d = e = f= g = h = static_cast(0); \ sl@0: \ sl@0: return(*this); \ sl@0: } \ sl@0: \ sl@0: octonion & operator = (::std::complex const & a_affecter) \ sl@0: { \ sl@0: a = a_affecter.real(); \ sl@0: b = a_affecter.imag(); \ sl@0: \ sl@0: c = d = e = f = g = h = static_cast(0); \ sl@0: \ sl@0: return(*this); \ sl@0: } \ sl@0: \ sl@0: octonion & operator = (::boost::math::quaternion const & a_affecter) \ sl@0: { \ sl@0: a = a_affecter.R_component_1(); \ sl@0: b = a_affecter.R_component_2(); \ sl@0: c = a_affecter.R_component_3(); \ sl@0: d = a_affecter.R_component_4(); \ sl@0: \ sl@0: e = f = g = h = static_cast(0); \ sl@0: \ sl@0: return(*this); \ sl@0: } sl@0: sl@0: sl@0: #define BOOST_OCTONION_MEMBER_DATA_GENERATOR(type) \ sl@0: type a; \ sl@0: type b; \ sl@0: type c; \ sl@0: type d; \ sl@0: type e; \ sl@0: type f; \ sl@0: type g; \ sl@0: type h; \ sl@0: sl@0: sl@0: template sl@0: class octonion sl@0: { sl@0: public: sl@0: sl@0: typedef T value_type; sl@0: sl@0: // constructor for O seen as R^8 sl@0: // (also default constructor) sl@0: sl@0: explicit octonion( T const & requested_a = T(), sl@0: T const & requested_b = T(), sl@0: T const & requested_c = T(), sl@0: T const & requested_d = T(), sl@0: T const & requested_e = T(), sl@0: T const & requested_f = T(), sl@0: T const & requested_g = T(), sl@0: T const & requested_h = T()) sl@0: : a(requested_a), sl@0: b(requested_b), sl@0: c(requested_c), sl@0: d(requested_d), sl@0: e(requested_e), sl@0: f(requested_f), sl@0: g(requested_g), sl@0: h(requested_h) sl@0: { sl@0: // nothing to do! sl@0: } sl@0: sl@0: sl@0: // constructor for H seen as C^4 sl@0: sl@0: explicit octonion( ::std::complex const & z0, sl@0: ::std::complex const & z1 = ::std::complex(), sl@0: ::std::complex const & z2 = ::std::complex(), sl@0: ::std::complex const & z3 = ::std::complex()) sl@0: : a(z0.real()), sl@0: b(z0.imag()), sl@0: c(z1.real()), sl@0: d(z1.imag()), sl@0: e(z2.real()), sl@0: f(z2.imag()), sl@0: g(z3.real()), sl@0: h(z3.imag()) sl@0: { sl@0: // nothing to do! sl@0: } sl@0: sl@0: sl@0: // constructor for O seen as H^2 sl@0: sl@0: explicit octonion( ::boost::math::quaternion const & q0, sl@0: ::boost::math::quaternion const & q1 = ::boost::math::quaternion()) sl@0: : a(q0.R_component_1()), sl@0: b(q0.R_component_2()), sl@0: c(q0.R_component_3()), sl@0: d(q0.R_component_4()), sl@0: e(q1.R_component_1()), sl@0: f(q1.R_component_2()), sl@0: g(q1.R_component_3()), sl@0: h(q1.R_component_4()) sl@0: { sl@0: // nothing to do! sl@0: } sl@0: sl@0: sl@0: // UNtemplated copy constructor sl@0: // (this is taken care of by the compiler itself) sl@0: sl@0: sl@0: // templated copy constructor sl@0: sl@0: template sl@0: explicit octonion(octonion const & a_recopier) sl@0: : a(static_cast(a_recopier.R_component_1())), sl@0: b(static_cast(a_recopier.R_component_2())), sl@0: c(static_cast(a_recopier.R_component_3())), sl@0: d(static_cast(a_recopier.R_component_4())), sl@0: e(static_cast(a_recopier.R_component_5())), sl@0: f(static_cast(a_recopier.R_component_6())), sl@0: g(static_cast(a_recopier.R_component_7())), sl@0: h(static_cast(a_recopier.R_component_8())) sl@0: { sl@0: // nothing to do! sl@0: } sl@0: sl@0: sl@0: // destructor sl@0: // (this is taken care of by the compiler itself) sl@0: sl@0: sl@0: // accessors sl@0: // sl@0: // Note: Like complex number, octonions do have a meaningful notion of "real part", sl@0: // but unlike them there is no meaningful notion of "imaginary part". sl@0: // Instead there is an "unreal part" which itself is an octonion, and usually sl@0: // nothing simpler (as opposed to the complex number case). sl@0: // However, for practicallity, there are accessors for the other components sl@0: // (these are necessary for the templated copy constructor, for instance). sl@0: sl@0: BOOST_OCTONION_ACCESSOR_GENERATOR(T) sl@0: sl@0: // assignment operators sl@0: sl@0: BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(T) sl@0: sl@0: // other assignment-related operators sl@0: // sl@0: // NOTE: Octonion multiplication is *NOT* commutative; sl@0: // symbolically, "q *= rhs;" means "q = q * rhs;" sl@0: // and "q /= rhs;" means "q = q * inverse_of(rhs);"; sl@0: // octonion multiplication is also *NOT* associative sl@0: sl@0: octonion & operator += (T const & rhs) sl@0: { sl@0: T at = a + rhs; // exception guard sl@0: sl@0: a = at; sl@0: sl@0: return(*this); sl@0: } sl@0: sl@0: sl@0: octonion & operator += (::std::complex const & rhs) sl@0: { sl@0: T at = a + rhs.real(); // exception guard sl@0: T bt = b + rhs.imag(); // exception guard sl@0: sl@0: a = at; sl@0: b = bt; sl@0: sl@0: return(*this); sl@0: } sl@0: sl@0: sl@0: octonion & operator += (::boost::math::quaternion const & rhs) sl@0: { sl@0: T at = a + rhs.R_component_1(); // exception guard sl@0: T bt = b + rhs.R_component_2(); // exception guard sl@0: T ct = c + rhs.R_component_3(); // exception guard sl@0: T dt = d + rhs.R_component_4(); // exception guard sl@0: sl@0: a = at; sl@0: b = bt; sl@0: c = ct; sl@0: d = dt; sl@0: sl@0: return(*this); sl@0: } sl@0: sl@0: sl@0: template sl@0: octonion & operator += (octonion const & rhs) sl@0: { sl@0: T at = a + static_cast(rhs.R_component_1()); // exception guard sl@0: T bt = b + static_cast(rhs.R_component_2()); // exception guard sl@0: T ct = c + static_cast(rhs.R_component_3()); // exception guard sl@0: T dt = d + static_cast(rhs.R_component_4()); // exception guard sl@0: T et = e + static_cast(rhs.R_component_5()); // exception guard sl@0: T ft = f + static_cast(rhs.R_component_6()); // exception guard sl@0: T gt = g + static_cast(rhs.R_component_7()); // exception guard sl@0: T ht = h + static_cast(rhs.R_component_8()); // exception guard sl@0: sl@0: a = at; sl@0: b = bt; sl@0: c = ct; sl@0: d = dt; sl@0: e = et; sl@0: f = ft; sl@0: g = gt; sl@0: h = ht; sl@0: sl@0: return(*this); sl@0: } sl@0: sl@0: sl@0: sl@0: octonion & operator -= (T const & rhs) sl@0: { sl@0: T at = a - rhs; // exception guard sl@0: sl@0: a = at; sl@0: sl@0: return(*this); sl@0: } sl@0: sl@0: sl@0: octonion & operator -= (::std::complex const & rhs) sl@0: { sl@0: T at = a - rhs.real(); // exception guard sl@0: T bt = b - rhs.imag(); // exception guard sl@0: sl@0: a = at; sl@0: b = bt; sl@0: sl@0: return(*this); sl@0: } sl@0: sl@0: sl@0: octonion & operator -= (::boost::math::quaternion const & rhs) sl@0: { sl@0: T at = a - rhs.R_component_1(); // exception guard sl@0: T bt = b - rhs.R_component_2(); // exception guard sl@0: T ct = c - rhs.R_component_3(); // exception guard sl@0: T dt = d - rhs.R_component_4(); // exception guard sl@0: sl@0: a = at; sl@0: b = bt; sl@0: c = ct; sl@0: d = dt; sl@0: sl@0: return(*this); sl@0: } sl@0: sl@0: sl@0: template sl@0: octonion & operator -= (octonion const & rhs) sl@0: { sl@0: T at = a - static_cast(rhs.R_component_1()); // exception guard sl@0: T bt = b - static_cast(rhs.R_component_2()); // exception guard sl@0: T ct = c - static_cast(rhs.R_component_3()); // exception guard sl@0: T dt = d - static_cast(rhs.R_component_4()); // exception guard sl@0: T et = e - static_cast(rhs.R_component_5()); // exception guard sl@0: T ft = f - static_cast(rhs.R_component_6()); // exception guard sl@0: T gt = g - static_cast(rhs.R_component_7()); // exception guard sl@0: T ht = h - static_cast(rhs.R_component_8()); // exception guard sl@0: sl@0: a = at; sl@0: b = bt; sl@0: c = ct; sl@0: d = dt; sl@0: e = et; sl@0: f = ft; sl@0: g = gt; sl@0: h = ht; sl@0: sl@0: return(*this); sl@0: } sl@0: sl@0: sl@0: octonion & operator *= (T const & rhs) sl@0: { sl@0: T at = a * rhs; // exception guard sl@0: T bt = b * rhs; // exception guard sl@0: T ct = c * rhs; // exception guard sl@0: T dt = d * rhs; // exception guard sl@0: T et = e * rhs; // exception guard sl@0: T ft = f * rhs; // exception guard sl@0: T gt = g * rhs; // exception guard sl@0: T ht = h * rhs; // exception guard sl@0: sl@0: a = at; sl@0: b = bt; sl@0: c = ct; sl@0: d = dt; sl@0: e = et; sl@0: f = ft; sl@0: g = gt; sl@0: h = ht; sl@0: sl@0: return(*this); sl@0: } sl@0: sl@0: sl@0: octonion & operator *= (::std::complex const & rhs) sl@0: { sl@0: T ar = rhs.real(); sl@0: T br = rhs.imag(); sl@0: sl@0: T at = +a*ar-b*br; sl@0: T bt = +a*br+b*ar; sl@0: T ct = +c*ar+d*br; sl@0: T dt = -c*br+d*ar; sl@0: T et = +e*ar+f*br; sl@0: T ft = -e*br+f*ar; sl@0: T gt = +g*ar-h*br; sl@0: T ht = +g*br+h*ar; sl@0: sl@0: a = at; sl@0: b = bt; sl@0: c = ct; sl@0: d = dt; sl@0: e = et; sl@0: f = ft; sl@0: g = gt; sl@0: h = ht; sl@0: sl@0: return(*this); sl@0: } sl@0: sl@0: sl@0: octonion & operator *= (::boost::math::quaternion const & rhs) sl@0: { sl@0: T ar = rhs.R_component_1(); sl@0: T br = rhs.R_component_2(); sl@0: T cr = rhs.R_component_2(); sl@0: T dr = rhs.R_component_2(); sl@0: sl@0: T at = +a*ar-b*br-c*cr-d*dr; sl@0: T bt = +a*br+b*ar+c*dr-d*cr; sl@0: T ct = +a*cr-b*dr+c*ar+d*br; sl@0: T dt = +a*dr+b*cr-c*br+d*ar; sl@0: T et = +e*ar+f*br+g*cr+h*dr; sl@0: T ft = -e*br+f*ar-g*dr+h*cr; sl@0: T gt = -e*cr+f*dr+g*ar-h*br; sl@0: T ht = -e*dr-f*cr+g*br+h*ar; sl@0: sl@0: a = at; sl@0: b = bt; sl@0: c = ct; sl@0: d = dt; sl@0: e = et; sl@0: f = ft; sl@0: g = gt; sl@0: h = ht; sl@0: sl@0: return(*this); sl@0: } sl@0: sl@0: sl@0: template sl@0: octonion & operator *= (octonion const & rhs) sl@0: { sl@0: T ar = static_cast(rhs.R_component_1()); sl@0: T br = static_cast(rhs.R_component_2()); sl@0: T cr = static_cast(rhs.R_component_3()); sl@0: T dr = static_cast(rhs.R_component_4()); sl@0: T er = static_cast(rhs.R_component_5()); sl@0: T fr = static_cast(rhs.R_component_6()); sl@0: T gr = static_cast(rhs.R_component_7()); sl@0: T hr = static_cast(rhs.R_component_8()); sl@0: sl@0: T at = +a*ar-b*br-c*cr-d*dr-e*er-f*fr-g*gr-h*hr; sl@0: T bt = +a*br+b*ar+c*dr-d*cr+e*fr-f*er-g*hr+h*gr; sl@0: T ct = +a*cr-b*dr+c*ar+d*br+e*gr+f*hr-g*er-h*fr; sl@0: T dt = +a*dr+b*cr-c*br+d*ar+e*hr-f*gr+g*fr-h*er; sl@0: T et = +a*er-b*fr-c*gr-d*hr+e*ar+f*br+g*cr+h*dr; sl@0: T ft = +a*fr+b*er-c*hr+d*gr-e*br+f*ar-g*dr+h*cr; sl@0: T gt = +a*gr+b*hr+c*er-d*fr-e*cr+f*dr+g*ar-h*br; sl@0: T ht = +a*hr-b*gr+c*fr+d*er-e*dr-f*cr+g*br+h*ar; sl@0: sl@0: a = at; sl@0: b = bt; sl@0: c = ct; sl@0: d = dt; sl@0: e = et; sl@0: f = ft; sl@0: g = gt; sl@0: h = ht; sl@0: sl@0: return(*this); sl@0: } sl@0: sl@0: sl@0: octonion & operator /= (T const & rhs) sl@0: { sl@0: T at = a / rhs; // exception guard sl@0: T bt = b / rhs; // exception guard sl@0: T ct = c / rhs; // exception guard sl@0: T dt = d / rhs; // exception guard sl@0: T et = e / rhs; // exception guard sl@0: T ft = f / rhs; // exception guard sl@0: T gt = g / rhs; // exception guard sl@0: T ht = h / rhs; // exception guard sl@0: sl@0: a = at; sl@0: b = bt; sl@0: c = ct; sl@0: d = dt; sl@0: e = et; sl@0: f = ft; sl@0: g = gt; sl@0: h = ht; sl@0: sl@0: return(*this); sl@0: } sl@0: sl@0: sl@0: octonion & operator /= (::std::complex const & rhs) sl@0: { sl@0: T ar = rhs.real(); sl@0: T br = rhs.imag(); sl@0: sl@0: T denominator = ar*ar+br*br; sl@0: sl@0: T at = (+a*ar-b*br)/denominator; sl@0: T bt = (-a*br+b*ar)/denominator; sl@0: T ct = (+c*ar-d*br)/denominator; sl@0: T dt = (+c*br+d*ar)/denominator; sl@0: T et = (+e*ar-f*br)/denominator; sl@0: T ft = (+e*br+f*ar)/denominator; sl@0: T gt = (+g*ar+h*br)/denominator; sl@0: T ht = (+g*br+h*ar)/denominator; sl@0: sl@0: a = at; sl@0: b = bt; sl@0: c = ct; sl@0: d = dt; sl@0: e = et; sl@0: f = ft; sl@0: g = gt; sl@0: h = ht; sl@0: sl@0: return(*this); sl@0: } sl@0: sl@0: sl@0: octonion & operator /= (::boost::math::quaternion const & rhs) sl@0: { sl@0: T ar = rhs.R_component_1(); sl@0: T br = rhs.R_component_2(); sl@0: T cr = rhs.R_component_2(); sl@0: T dr = rhs.R_component_2(); sl@0: sl@0: T denominator = ar*ar+br*br+cr*cr+dr*dr; sl@0: sl@0: T at = (+a*ar+b*br+c*cr+d*dr)/denominator; sl@0: T bt = (-a*br+b*ar-c*dr+d*cr)/denominator; sl@0: T ct = (-a*cr+b*dr+c*ar-d*br)/denominator; sl@0: T dt = (-a*dr-b*cr+c*br+d*ar)/denominator; sl@0: T et = (+e*ar-f*br-g*cr-h*dr)/denominator; sl@0: T ft = (+e*br+f*ar+g*dr-h*cr)/denominator; sl@0: T gt = (+e*cr-f*dr+g*ar+h*br)/denominator; sl@0: T ht = (+e*dr+f*cr-g*br+h*ar)/denominator; sl@0: sl@0: a = at; sl@0: b = bt; sl@0: c = ct; sl@0: d = dt; sl@0: e = et; sl@0: f = ft; sl@0: g = gt; sl@0: h = ht; sl@0: sl@0: return(*this); sl@0: } sl@0: sl@0: sl@0: template sl@0: octonion & operator /= (octonion const & rhs) sl@0: { sl@0: T ar = static_cast(rhs.R_component_1()); sl@0: T br = static_cast(rhs.R_component_2()); sl@0: T cr = static_cast(rhs.R_component_3()); sl@0: T dr = static_cast(rhs.R_component_4()); sl@0: T er = static_cast(rhs.R_component_5()); sl@0: T fr = static_cast(rhs.R_component_6()); sl@0: T gr = static_cast(rhs.R_component_7()); sl@0: T hr = static_cast(rhs.R_component_8()); sl@0: sl@0: T denominator = ar*ar+br*br+cr*cr+dr*dr+er*er+fr*fr+gr*gr+hr*hr; sl@0: sl@0: T at = (+a*ar+b*br+c*cr+d*dr+e*er+f*fr+g*gr+h*hr)/denominator; sl@0: T bt = (-a*br+b*ar-c*dr+d*cr-e*fr+f*er+g*hr-h*gr)/denominator; sl@0: T ct = (-a*cr+b*dr+c*ar-d*br-e*gr-f*hr+g*er+h*fr)/denominator; sl@0: T dt = (-a*dr-b*cr+c*br+d*ar-e*hr+f*gr-g*fr+h*er)/denominator; sl@0: T et = (-a*er+b*fr+c*gr+d*hr+e*ar-f*br-g*cr-h*dr)/denominator; sl@0: T ft = (-a*fr-b*er+c*hr-d*gr+e*br+f*ar+g*dr-h*cr)/denominator; sl@0: T gt = (-a*gr-b*hr-c*er+d*fr+e*cr-f*dr+g*ar+h*br)/denominator; sl@0: T ht = (-a*hr+b*gr-c*fr-d*er+e*dr+f*cr-g*br+h*ar)/denominator; sl@0: sl@0: a = at; sl@0: b = bt; sl@0: c = ct; sl@0: d = dt; sl@0: e = et; sl@0: f = ft; sl@0: g = gt; sl@0: h = ht; sl@0: sl@0: return(*this); sl@0: } sl@0: sl@0: sl@0: protected: sl@0: sl@0: BOOST_OCTONION_MEMBER_DATA_GENERATOR(T) sl@0: sl@0: sl@0: private: sl@0: sl@0: }; sl@0: sl@0: sl@0: // declaration of octonion specialization sl@0: sl@0: template<> class octonion; sl@0: template<> class octonion; sl@0: template<> class octonion; sl@0: sl@0: sl@0: // helper templates for converting copy constructors (declaration) sl@0: sl@0: namespace detail sl@0: { sl@0: sl@0: template< typename T, sl@0: typename U sl@0: > sl@0: octonion octonion_type_converter(octonion const & rhs); sl@0: } sl@0: sl@0: sl@0: // implementation of octonion specialization sl@0: sl@0: sl@0: #define BOOST_OCTONION_CONSTRUCTOR_GENERATOR(type) \ sl@0: explicit octonion( type const & requested_a = static_cast(0), \ sl@0: type const & requested_b = static_cast(0), \ sl@0: type const & requested_c = static_cast(0), \ sl@0: type const & requested_d = static_cast(0), \ sl@0: type const & requested_e = static_cast(0), \ sl@0: type const & requested_f = static_cast(0), \ sl@0: type const & requested_g = static_cast(0), \ sl@0: type const & requested_h = static_cast(0)) \ sl@0: : a(requested_a), \ sl@0: b(requested_b), \ sl@0: c(requested_c), \ sl@0: d(requested_d), \ sl@0: e(requested_e), \ sl@0: f(requested_f), \ sl@0: g(requested_g), \ sl@0: h(requested_h) \ sl@0: { \ sl@0: } \ sl@0: \ sl@0: explicit octonion( ::std::complex const & z0, \ sl@0: ::std::complex const & z1 = ::std::complex(), \ sl@0: ::std::complex const & z2 = ::std::complex(), \ sl@0: ::std::complex const & z3 = ::std::complex()) \ sl@0: : a(z0.real()), \ sl@0: b(z0.imag()), \ sl@0: c(z1.real()), \ sl@0: d(z1.imag()), \ sl@0: e(z2.real()), \ sl@0: f(z2.imag()), \ sl@0: g(z3.real()), \ sl@0: h(z3.imag()) \ sl@0: { \ sl@0: } \ sl@0: \ sl@0: explicit octonion( ::boost::math::quaternion const & q0, \ sl@0: ::boost::math::quaternion const & q1 = ::boost::math::quaternion()) \ sl@0: : a(q0.R_component_1()), \ sl@0: b(q0.R_component_2()), \ sl@0: c(q0.R_component_3()), \ sl@0: d(q0.R_component_4()), \ sl@0: e(q1.R_component_1()), \ sl@0: f(q1.R_component_2()), \ sl@0: g(q1.R_component_3()), \ sl@0: h(q1.R_component_4()) \ sl@0: { \ sl@0: } sl@0: sl@0: sl@0: #define BOOST_OCTONION_MEMBER_ADD_GENERATOR_1(type) \ sl@0: octonion & operator += (type const & rhs) \ sl@0: { \ sl@0: a += rhs; \ sl@0: \ sl@0: return(*this); \ sl@0: } sl@0: sl@0: #define BOOST_OCTONION_MEMBER_ADD_GENERATOR_2(type) \ sl@0: octonion & operator += (::std::complex const & rhs) \ sl@0: { \ sl@0: a += rhs.real(); \ sl@0: b += rhs.imag(); \ sl@0: \ sl@0: return(*this); \ sl@0: } sl@0: sl@0: #define BOOST_OCTONION_MEMBER_ADD_GENERATOR_3(type) \ sl@0: octonion & operator += (::boost::math::quaternion const & rhs) \ sl@0: { \ sl@0: a += rhs.R_component_1(); \ sl@0: b += rhs.R_component_2(); \ sl@0: c += rhs.R_component_3(); \ sl@0: d += rhs.R_component_4(); \ sl@0: \ sl@0: return(*this); \ sl@0: } sl@0: sl@0: #define BOOST_OCTONION_MEMBER_ADD_GENERATOR_4(type) \ sl@0: template \ sl@0: octonion & operator += (octonion const & rhs) \ sl@0: { \ sl@0: a += static_cast(rhs.R_component_1()); \ sl@0: b += static_cast(rhs.R_component_2()); \ sl@0: c += static_cast(rhs.R_component_3()); \ sl@0: d += static_cast(rhs.R_component_4()); \ sl@0: e += static_cast(rhs.R_component_5()); \ sl@0: f += static_cast(rhs.R_component_6()); \ sl@0: g += static_cast(rhs.R_component_7()); \ sl@0: h += static_cast(rhs.R_component_8()); \ sl@0: \ sl@0: return(*this); \ sl@0: } sl@0: sl@0: #define BOOST_OCTONION_MEMBER_SUB_GENERATOR_1(type) \ sl@0: octonion & operator -= (type const & rhs) \ sl@0: { \ sl@0: a -= rhs; \ sl@0: \ sl@0: return(*this); \ sl@0: } sl@0: sl@0: #define BOOST_OCTONION_MEMBER_SUB_GENERATOR_2(type) \ sl@0: octonion & operator -= (::std::complex const & rhs) \ sl@0: { \ sl@0: a -= rhs.real(); \ sl@0: b -= rhs.imag(); \ sl@0: \ sl@0: return(*this); \ sl@0: } sl@0: sl@0: #define BOOST_OCTONION_MEMBER_SUB_GENERATOR_3(type) \ sl@0: octonion & operator -= (::boost::math::quaternion const & rhs) \ sl@0: { \ sl@0: a -= rhs.R_component_1(); \ sl@0: b -= rhs.R_component_2(); \ sl@0: c -= rhs.R_component_3(); \ sl@0: d -= rhs.R_component_4(); \ sl@0: \ sl@0: return(*this); \ sl@0: } sl@0: sl@0: #define BOOST_OCTONION_MEMBER_SUB_GENERATOR_4(type) \ sl@0: template \ sl@0: octonion & operator -= (octonion const & rhs) \ sl@0: { \ sl@0: a -= static_cast(rhs.R_component_1()); \ sl@0: b -= static_cast(rhs.R_component_2()); \ sl@0: c -= static_cast(rhs.R_component_3()); \ sl@0: d -= static_cast(rhs.R_component_4()); \ sl@0: e -= static_cast(rhs.R_component_5()); \ sl@0: f -= static_cast(rhs.R_component_6()); \ sl@0: g -= static_cast(rhs.R_component_7()); \ sl@0: h -= static_cast(rhs.R_component_8()); \ sl@0: \ sl@0: return(*this); \ sl@0: } sl@0: sl@0: #define BOOST_OCTONION_MEMBER_MUL_GENERATOR_1(type) \ sl@0: octonion & operator *= (type const & rhs) \ sl@0: { \ sl@0: a *= rhs; \ sl@0: b *= rhs; \ sl@0: c *= rhs; \ sl@0: d *= rhs; \ sl@0: e *= rhs; \ sl@0: f *= rhs; \ sl@0: g *= rhs; \ sl@0: h *= rhs; \ sl@0: \ sl@0: return(*this); \ sl@0: } sl@0: sl@0: #define BOOST_OCTONION_MEMBER_MUL_GENERATOR_2(type) \ sl@0: octonion & operator *= (::std::complex const & rhs) \ sl@0: { \ sl@0: type ar = rhs.real(); \ sl@0: type br = rhs.imag(); \ sl@0: \ sl@0: type at = +a*ar-b*br; \ sl@0: type bt = +a*br+b*ar; \ sl@0: type ct = +c*ar+d*br; \ sl@0: type dt = -c*br+d*ar; \ sl@0: type et = +e*ar+f*br; \ sl@0: type ft = -e*br+f*ar; \ sl@0: type gt = +g*ar-h*br; \ sl@0: type ht = +g*br+h*ar; \ sl@0: \ sl@0: a = at; \ sl@0: b = bt; \ sl@0: c = ct; \ sl@0: d = dt; \ sl@0: e = et; \ sl@0: f = ft; \ sl@0: g = gt; \ sl@0: h = ht; \ sl@0: \ sl@0: return(*this); \ sl@0: } sl@0: sl@0: #define BOOST_OCTONION_MEMBER_MUL_GENERATOR_3(type) \ sl@0: octonion & operator *= (::boost::math::quaternion const & rhs) \ sl@0: { \ sl@0: type ar = rhs.R_component_1(); \ sl@0: type br = rhs.R_component_2(); \ sl@0: type cr = rhs.R_component_2(); \ sl@0: type dr = rhs.R_component_2(); \ sl@0: \ sl@0: type at = +a*ar-b*br-c*cr-d*dr; \ sl@0: type bt = +a*br+b*ar+c*dr-d*cr; \ sl@0: type ct = +a*cr-b*dr+c*ar+d*br; \ sl@0: type dt = +a*dr+b*cr-c*br+d*ar; \ sl@0: type et = +e*ar+f*br+g*cr+h*dr; \ sl@0: type ft = -e*br+f*ar-g*dr+h*cr; \ sl@0: type gt = -e*cr+f*dr+g*ar-h*br; \ sl@0: type ht = -e*dr-f*cr+g*br+h*ar; \ sl@0: \ sl@0: a = at; \ sl@0: b = bt; \ sl@0: c = ct; \ sl@0: d = dt; \ sl@0: e = et; \ sl@0: f = ft; \ sl@0: g = gt; \ sl@0: h = ht; \ sl@0: \ sl@0: return(*this); \ sl@0: } sl@0: sl@0: #define BOOST_OCTONION_MEMBER_MUL_GENERATOR_4(type) \ sl@0: template \ sl@0: octonion & operator *= (octonion const & rhs) \ sl@0: { \ sl@0: type ar = static_cast(rhs.R_component_1()); \ sl@0: type br = static_cast(rhs.R_component_2()); \ sl@0: type cr = static_cast(rhs.R_component_3()); \ sl@0: type dr = static_cast(rhs.R_component_4()); \ sl@0: type er = static_cast(rhs.R_component_5()); \ sl@0: type fr = static_cast(rhs.R_component_6()); \ sl@0: type gr = static_cast(rhs.R_component_7()); \ sl@0: type hr = static_cast(rhs.R_component_8()); \ sl@0: \ sl@0: type at = +a*ar-b*br-c*cr-d*dr-e*er-f*fr-g*gr-h*hr; \ sl@0: type bt = +a*br+b*ar+c*dr-d*cr+e*fr-f*er-g*hr+h*gr; \ sl@0: type ct = +a*cr-b*dr+c*ar+d*br+e*gr+f*hr-g*er-h*fr; \ sl@0: type dt = +a*dr+b*cr-c*br+d*ar+e*hr-f*gr+g*fr-h*er; \ sl@0: type et = +a*er-b*fr-c*gr-d*hr+e*ar+f*br+g*cr+h*dr; \ sl@0: type ft = +a*fr+b*er-c*hr+d*gr-e*br+f*ar-g*dr+h*cr; \ sl@0: type gt = +a*gr+b*hr+c*er-d*fr-e*cr+f*dr+g*ar-h*br; \ sl@0: type ht = +a*hr-b*gr+c*fr+d*er-e*dr-f*cr+g*br+h*ar; \ sl@0: \ sl@0: a = at; \ sl@0: b = bt; \ sl@0: c = ct; \ sl@0: d = dt; \ sl@0: e = et; \ sl@0: f = ft; \ sl@0: g = gt; \ sl@0: h = ht; \ sl@0: \ sl@0: return(*this); \ sl@0: } sl@0: sl@0: // There is quite a lot of repetition in the code below. This is intentional. sl@0: // The last conditional block is the normal form, and the others merely sl@0: // consist of workarounds for various compiler deficiencies. Hopefuly, when sl@0: // more compilers are conformant and we can retire support for those that are sl@0: // not, we will be able to remove the clutter. This is makes the situation sl@0: // (painfully) explicit. sl@0: sl@0: #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_1(type) \ sl@0: octonion & operator /= (type const & rhs) \ sl@0: { \ sl@0: a /= rhs; \ sl@0: b /= rhs; \ sl@0: c /= rhs; \ sl@0: d /= rhs; \ sl@0: \ sl@0: return(*this); \ sl@0: } sl@0: sl@0: #if defined(__GNUC__) && (__GNUC__ < 3) sl@0: #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_2(type) \ sl@0: octonion & operator /= (::std::complex const & rhs) \ sl@0: { \ sl@0: using ::std::valarray; \ sl@0: \ sl@0: valarray tr(2); \ sl@0: \ sl@0: tr[0] = rhs.real(); \ sl@0: tr[1] = rhs.imag(); \ sl@0: \ sl@0: type mixam = (BOOST_GET_VALARRAY(type,static_cast(1)/abs(tr)).max)(); \ sl@0: \ sl@0: tr *= mixam; \ sl@0: \ sl@0: valarray tt(8); \ sl@0: \ sl@0: tt[0] = +a*tr[0]-b*tr[1]; \ sl@0: tt[1] = -a*tr[1]+b*tr[0]; \ sl@0: tt[2] = +c*tr[0]-d*tr[1]; \ sl@0: tt[3] = +c*tr[1]+d*tr[0]; \ sl@0: tt[4] = +e*tr[0]-f*tr[1]; \ sl@0: tt[5] = +e*tr[1]+f*tr[0]; \ sl@0: tt[6] = +g*tr[0]+h*tr[1]; \ sl@0: tt[7] = +g*tr[1]+h*tr[0]; \ sl@0: \ sl@0: tr *= tr; \ sl@0: \ sl@0: tt *= (mixam/tr.sum()); \ sl@0: \ sl@0: a = tt[0]; \ sl@0: b = tt[1]; \ sl@0: c = tt[2]; \ sl@0: d = tt[3]; \ sl@0: e = tt[4]; \ sl@0: f = tt[5]; \ sl@0: g = tt[6]; \ sl@0: h = tt[7]; \ sl@0: \ sl@0: return(*this); \ sl@0: } sl@0: #elif defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) sl@0: #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_2(type) \ sl@0: octonion & operator /= (::std::complex const & rhs) \ sl@0: { \ sl@0: using ::std::valarray; \ sl@0: using ::std::abs; \ sl@0: \ sl@0: valarray tr(2); \ sl@0: \ sl@0: tr[0] = rhs.real(); \ sl@0: tr[1] = rhs.imag(); \ sl@0: \ sl@0: type mixam = static_cast(1)/(abs(tr).max)(); \ sl@0: \ sl@0: tr *= mixam; \ sl@0: \ sl@0: valarray tt(8); \ sl@0: \ sl@0: tt[0] = +a*tr[0]-b*tr[1]; \ sl@0: tt[1] = -a*tr[1]+b*tr[0]; \ sl@0: tt[2] = +c*tr[0]-d*tr[1]; \ sl@0: tt[3] = +c*tr[1]+d*tr[0]; \ sl@0: tt[4] = +e*tr[0]-f*tr[1]; \ sl@0: tt[5] = +e*tr[1]+f*tr[0]; \ sl@0: tt[6] = +g*tr[0]+h*tr[1]; \ sl@0: tt[7] = +g*tr[1]+h*tr[0]; \ sl@0: \ sl@0: tr *= tr; \ sl@0: \ sl@0: tt *= (mixam/tr.sum()); \ sl@0: \ sl@0: a = tt[0]; \ sl@0: b = tt[1]; \ sl@0: c = tt[2]; \ sl@0: d = tt[3]; \ sl@0: e = tt[4]; \ sl@0: f = tt[5]; \ sl@0: g = tt[6]; \ sl@0: h = tt[7]; \ sl@0: \ sl@0: return(*this); \ sl@0: } sl@0: #else sl@0: #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_2(type) \ sl@0: octonion & operator /= (::std::complex const & rhs) \ sl@0: { \ sl@0: using ::std::valarray; \ sl@0: \ sl@0: valarray tr(2); \ sl@0: \ sl@0: tr[0] = rhs.real(); \ sl@0: tr[1] = rhs.imag(); \ sl@0: \ sl@0: type mixam = static_cast(1)/(abs(tr).max)(); \ sl@0: \ sl@0: tr *= mixam; \ sl@0: \ sl@0: valarray tt(8); \ sl@0: \ sl@0: tt[0] = +a*tr[0]-b*tr[1]; \ sl@0: tt[1] = -a*tr[1]+b*tr[0]; \ sl@0: tt[2] = +c*tr[0]-d*tr[1]; \ sl@0: tt[3] = +c*tr[1]+d*tr[0]; \ sl@0: tt[4] = +e*tr[0]-f*tr[1]; \ sl@0: tt[5] = +e*tr[1]+f*tr[0]; \ sl@0: tt[6] = +g*tr[0]+h*tr[1]; \ sl@0: tt[7] = +g*tr[1]+h*tr[0]; \ sl@0: \ sl@0: tr *= tr; \ sl@0: \ sl@0: tt *= (mixam/tr.sum()); \ sl@0: \ sl@0: a = tt[0]; \ sl@0: b = tt[1]; \ sl@0: c = tt[2]; \ sl@0: d = tt[3]; \ sl@0: e = tt[4]; \ sl@0: f = tt[5]; \ sl@0: g = tt[6]; \ sl@0: h = tt[7]; \ sl@0: \ sl@0: return(*this); \ sl@0: } sl@0: #endif /* defined(__GNUC__) && (__GNUC__ < 3) */ /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ sl@0: sl@0: #if defined(__GNUC__) && (__GNUC__ < 3) sl@0: #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_3(type) \ sl@0: octonion & operator /= (::boost::math::quaternion const & rhs) \ sl@0: { \ sl@0: using ::std::valarray; \ sl@0: \ sl@0: valarray tr(4); \ sl@0: \ sl@0: tr[0] = static_cast(rhs.R_component_1()); \ sl@0: tr[1] = static_cast(rhs.R_component_2()); \ sl@0: tr[2] = static_cast(rhs.R_component_3()); \ sl@0: tr[3] = static_cast(rhs.R_component_4()); \ sl@0: \ sl@0: type mixam = (BOOST_GET_VALARRAY(type,static_cast(1)/abs(tr)).max)();\ sl@0: \ sl@0: tr *= mixam; \ sl@0: \ sl@0: valarray tt(8); \ sl@0: \ sl@0: tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]; \ sl@0: tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]; \ sl@0: tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]; \ sl@0: tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]; \ sl@0: tt[4] = +e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \ sl@0: tt[5] = +e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \ sl@0: tt[6] = +e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \ sl@0: tt[7] = +e*tr[3]+f*tr[2]-g*tr[1]+h*tr[0]; \ sl@0: \ sl@0: tr *= tr; \ sl@0: \ sl@0: tt *= (mixam/tr.sum()); \ sl@0: \ sl@0: a = tt[0]; \ sl@0: b = tt[1]; \ sl@0: c = tt[2]; \ sl@0: d = tt[3]; \ sl@0: e = tt[4]; \ sl@0: f = tt[5]; \ sl@0: g = tt[6]; \ sl@0: h = tt[7]; \ sl@0: \ sl@0: return(*this); \ sl@0: } sl@0: #elif defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) sl@0: #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_3(type) \ sl@0: octonion & operator /= (::boost::math::quaternion const & rhs) \ sl@0: { \ sl@0: using ::std::valarray; \ sl@0: using ::std::abs; \ sl@0: \ sl@0: valarray tr(4); \ sl@0: \ sl@0: tr[0] = static_cast(rhs.R_component_1()); \ sl@0: tr[1] = static_cast(rhs.R_component_2()); \ sl@0: tr[2] = static_cast(rhs.R_component_3()); \ sl@0: tr[3] = static_cast(rhs.R_component_4()); \ sl@0: \ sl@0: type mixam = static_cast(1)/(abs(tr).max)(); \ sl@0: \ sl@0: tr *= mixam; \ sl@0: \ sl@0: valarray tt(8); \ sl@0: \ sl@0: tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]; \ sl@0: tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]; \ sl@0: tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]; \ sl@0: tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]; \ sl@0: tt[4] = +e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \ sl@0: tt[5] = +e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \ sl@0: tt[6] = +e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \ sl@0: tt[7] = +e*tr[3]+f*tr[2]-g*tr[1]+h*tr[0]; \ sl@0: \ sl@0: tr *= tr; \ sl@0: \ sl@0: tt *= (mixam/tr.sum()); \ sl@0: \ sl@0: a = tt[0]; \ sl@0: b = tt[1]; \ sl@0: c = tt[2]; \ sl@0: d = tt[3]; \ sl@0: e = tt[4]; \ sl@0: f = tt[5]; \ sl@0: g = tt[6]; \ sl@0: h = tt[7]; \ sl@0: \ sl@0: return(*this); \ sl@0: } sl@0: #else sl@0: #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_3(type) \ sl@0: octonion & operator /= (::boost::math::quaternion const & rhs) \ sl@0: { \ sl@0: using ::std::valarray; \ sl@0: \ sl@0: valarray tr(4); \ sl@0: \ sl@0: tr[0] = static_cast(rhs.R_component_1()); \ sl@0: tr[1] = static_cast(rhs.R_component_2()); \ sl@0: tr[2] = static_cast(rhs.R_component_3()); \ sl@0: tr[3] = static_cast(rhs.R_component_4()); \ sl@0: \ sl@0: type mixam = static_cast(1)/(abs(tr).max)(); \ sl@0: \ sl@0: tr *= mixam; \ sl@0: \ sl@0: valarray tt(8); \ sl@0: \ sl@0: tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]; \ sl@0: tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]; \ sl@0: tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]; \ sl@0: tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]; \ sl@0: tt[4] = +e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \ sl@0: tt[5] = +e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \ sl@0: tt[6] = +e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \ sl@0: tt[7] = +e*tr[3]+f*tr[2]-g*tr[1]+h*tr[0]; \ sl@0: \ sl@0: tr *= tr; \ sl@0: \ sl@0: tt *= (mixam/tr.sum()); \ sl@0: \ sl@0: a = tt[0]; \ sl@0: b = tt[1]; \ sl@0: c = tt[2]; \ sl@0: d = tt[3]; \ sl@0: e = tt[4]; \ sl@0: f = tt[5]; \ sl@0: g = tt[6]; \ sl@0: h = tt[7]; \ sl@0: \ sl@0: return(*this); \ sl@0: } sl@0: #endif /* defined(__GNUC__) && (__GNUC__ < 3) */ /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ sl@0: sl@0: #if defined(__GNUC__) && (__GNUC__ < 3) sl@0: #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_4(type) \ sl@0: template \ sl@0: octonion & operator /= (octonion const & rhs) \ sl@0: { \ sl@0: using ::std::valarray; \ sl@0: \ sl@0: valarray tr(8); \ sl@0: \ sl@0: tr[0] = static_cast(rhs.R_component_1()); \ sl@0: tr[1] = static_cast(rhs.R_component_2()); \ sl@0: tr[2] = static_cast(rhs.R_component_3()); \ sl@0: tr[3] = static_cast(rhs.R_component_4()); \ sl@0: tr[4] = static_cast(rhs.R_component_5()); \ sl@0: tr[5] = static_cast(rhs.R_component_6()); \ sl@0: tr[6] = static_cast(rhs.R_component_7()); \ sl@0: tr[7] = static_cast(rhs.R_component_8()); \ sl@0: \ sl@0: type mixam = (BOOST_GET_VALARRAY(type,static_cast(1)/abs(tr)).max)();\ sl@0: \ sl@0: tr *= mixam; \ sl@0: \ sl@0: valarray tt(8); \ sl@0: \ sl@0: tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]+e*tr[4]+f*tr[5]+g*tr[6]+h*tr[7]; \ sl@0: tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]-e*tr[5]+f*tr[4]+g*tr[7]-h*tr[6]; \ sl@0: tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]-e*tr[6]-f*tr[7]+g*tr[4]+h*tr[5]; \ sl@0: tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]-e*tr[7]+f*tr[6]-g*tr[5]+h*tr[4]; \ sl@0: tt[4] = -a*tr[4]+b*tr[5]+c*tr[6]+d*tr[7]+e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \ sl@0: tt[5] = -a*tr[5]-b*tr[4]+c*tr[7]-d*tr[6]+e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \ sl@0: tt[6] = -a*tr[6]-b*tr[7]-c*tr[4]+d*tr[5]+e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \ sl@0: tt[7] = -a*tr[7]+b*tr[6]-c*tr[5]-d*tr[4]+e*tr[3]+f*tr[2]-g*tr[1]+h*tr[0]; \ sl@0: \ sl@0: tr *= tr; \ sl@0: \ sl@0: tt *= (mixam/tr.sum()); \ sl@0: \ sl@0: a = tt[0]; \ sl@0: b = tt[1]; \ sl@0: c = tt[2]; \ sl@0: d = tt[3]; \ sl@0: e = tt[4]; \ sl@0: f = tt[5]; \ sl@0: g = tt[6]; \ sl@0: h = tt[7]; \ sl@0: \ sl@0: return(*this); \ sl@0: } sl@0: #elif defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) sl@0: #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_4(type) \ sl@0: template \ sl@0: octonion & operator /= (octonion const & rhs) \ sl@0: { \ sl@0: using ::std::valarray; \ sl@0: using ::std::abs; \ sl@0: \ sl@0: valarray tr(8); \ sl@0: \ sl@0: tr[0] = static_cast(rhs.R_component_1()); \ sl@0: tr[1] = static_cast(rhs.R_component_2()); \ sl@0: tr[2] = static_cast(rhs.R_component_3()); \ sl@0: tr[3] = static_cast(rhs.R_component_4()); \ sl@0: tr[4] = static_cast(rhs.R_component_5()); \ sl@0: tr[5] = static_cast(rhs.R_component_6()); \ sl@0: tr[6] = static_cast(rhs.R_component_7()); \ sl@0: tr[7] = static_cast(rhs.R_component_8()); \ sl@0: \ sl@0: type mixam = static_cast(1)/(abs(tr).max)(); \ sl@0: \ sl@0: tr *= mixam; \ sl@0: \ sl@0: valarray tt(8); \ sl@0: \ sl@0: tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]+e*tr[4]+f*tr[5]+g*tr[6]+h*tr[7]; \ sl@0: tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]-e*tr[5]+f*tr[4]+g*tr[7]-h*tr[6]; \ sl@0: tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]-e*tr[6]-f*tr[7]+g*tr[4]+h*tr[5]; \ sl@0: tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]-e*tr[7]+f*tr[6]-g*tr[5]+h*tr[4]; \ sl@0: tt[4] = -a*tr[4]+b*tr[5]+c*tr[6]+d*tr[7]+e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \ sl@0: tt[5] = -a*tr[5]-b*tr[4]+c*tr[7]-d*tr[6]+e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \ sl@0: tt[6] = -a*tr[6]-b*tr[7]-c*tr[4]+d*tr[5]+e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \ sl@0: tt[7] = -a*tr[7]+b*tr[6]-c*tr[5]-d*tr[4]+e*tr[3]+f*tr[2]-g*tr[1]+h*tr[0]; \ sl@0: \ sl@0: tr *= tr; \ sl@0: \ sl@0: tt *= (mixam/tr.sum()); \ sl@0: \ sl@0: a = tt[0]; \ sl@0: b = tt[1]; \ sl@0: c = tt[2]; \ sl@0: d = tt[3]; \ sl@0: e = tt[4]; \ sl@0: f = tt[5]; \ sl@0: g = tt[6]; \ sl@0: h = tt[7]; \ sl@0: \ sl@0: return(*this); \ sl@0: } sl@0: #else sl@0: #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_4(type) \ sl@0: template \ sl@0: octonion & operator /= (octonion const & rhs) \ sl@0: { \ sl@0: using ::std::valarray; \ sl@0: \ sl@0: valarray tr(8); \ sl@0: \ sl@0: tr[0] = static_cast(rhs.R_component_1()); \ sl@0: tr[1] = static_cast(rhs.R_component_2()); \ sl@0: tr[2] = static_cast(rhs.R_component_3()); \ sl@0: tr[3] = static_cast(rhs.R_component_4()); \ sl@0: tr[4] = static_cast(rhs.R_component_5()); \ sl@0: tr[5] = static_cast(rhs.R_component_6()); \ sl@0: tr[6] = static_cast(rhs.R_component_7()); \ sl@0: tr[7] = static_cast(rhs.R_component_8()); \ sl@0: \ sl@0: type mixam = static_cast(1)/(abs(tr).max)(); \ sl@0: \ sl@0: tr *= mixam; \ sl@0: \ sl@0: valarray tt(8); \ sl@0: \ sl@0: tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]+e*tr[4]+f*tr[5]+g*tr[6]+h*tr[7]; \ sl@0: tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]-e*tr[5]+f*tr[4]+g*tr[7]-h*tr[6]; \ sl@0: tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]-e*tr[6]-f*tr[7]+g*tr[4]+h*tr[5]; \ sl@0: tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]-e*tr[7]+f*tr[6]-g*tr[5]+h*tr[4]; \ sl@0: tt[4] = -a*tr[4]+b*tr[5]+c*tr[6]+d*tr[7]+e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \ sl@0: tt[5] = -a*tr[5]-b*tr[4]+c*tr[7]-d*tr[6]+e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \ sl@0: tt[6] = -a*tr[6]-b*tr[7]-c*tr[4]+d*tr[5]+e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \ sl@0: tt[7] = -a*tr[7]+b*tr[6]-c*tr[5]-d*tr[4]+e*tr[3]+f*tr[2]-g*tr[1]+h*tr[0]; \ sl@0: \ sl@0: tr *= tr; \ sl@0: \ sl@0: tt *= (mixam/tr.sum()); \ sl@0: \ sl@0: a = tt[0]; \ sl@0: b = tt[1]; \ sl@0: c = tt[2]; \ sl@0: d = tt[3]; \ sl@0: e = tt[4]; \ sl@0: f = tt[5]; \ sl@0: g = tt[6]; \ sl@0: h = tt[7]; \ sl@0: \ sl@0: return(*this); \ sl@0: } sl@0: #endif /* defined(__GNUC__) && (__GNUC__ < 3) */ /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ sl@0: sl@0: sl@0: #define BOOST_OCTONION_MEMBER_ADD_GENERATOR(type) \ sl@0: BOOST_OCTONION_MEMBER_ADD_GENERATOR_1(type) \ sl@0: BOOST_OCTONION_MEMBER_ADD_GENERATOR_2(type) \ sl@0: BOOST_OCTONION_MEMBER_ADD_GENERATOR_3(type) \ sl@0: BOOST_OCTONION_MEMBER_ADD_GENERATOR_4(type) sl@0: sl@0: #define BOOST_OCTONION_MEMBER_SUB_GENERATOR(type) \ sl@0: BOOST_OCTONION_MEMBER_SUB_GENERATOR_1(type) \ sl@0: BOOST_OCTONION_MEMBER_SUB_GENERATOR_2(type) \ sl@0: BOOST_OCTONION_MEMBER_SUB_GENERATOR_3(type) \ sl@0: BOOST_OCTONION_MEMBER_SUB_GENERATOR_4(type) sl@0: sl@0: #define BOOST_OCTONION_MEMBER_MUL_GENERATOR(type) \ sl@0: BOOST_OCTONION_MEMBER_MUL_GENERATOR_1(type) \ sl@0: BOOST_OCTONION_MEMBER_MUL_GENERATOR_2(type) \ sl@0: BOOST_OCTONION_MEMBER_MUL_GENERATOR_3(type) \ sl@0: BOOST_OCTONION_MEMBER_MUL_GENERATOR_4(type) sl@0: sl@0: #define BOOST_OCTONION_MEMBER_DIV_GENERATOR(type) \ sl@0: BOOST_OCTONION_MEMBER_DIV_GENERATOR_1(type) \ sl@0: BOOST_OCTONION_MEMBER_DIV_GENERATOR_2(type) \ sl@0: BOOST_OCTONION_MEMBER_DIV_GENERATOR_3(type) \ sl@0: BOOST_OCTONION_MEMBER_DIV_GENERATOR_4(type) sl@0: sl@0: #define BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR(type) \ sl@0: BOOST_OCTONION_MEMBER_ADD_GENERATOR(type) \ sl@0: BOOST_OCTONION_MEMBER_SUB_GENERATOR(type) \ sl@0: BOOST_OCTONION_MEMBER_MUL_GENERATOR(type) \ sl@0: BOOST_OCTONION_MEMBER_DIV_GENERATOR(type) sl@0: sl@0: sl@0: template<> sl@0: class octonion sl@0: { sl@0: public: sl@0: sl@0: typedef float value_type; sl@0: sl@0: BOOST_OCTONION_CONSTRUCTOR_GENERATOR(float) sl@0: sl@0: // UNtemplated copy constructor sl@0: // (this is taken care of by the compiler itself) sl@0: sl@0: // explicit copy constructors (precision-loosing converters) sl@0: sl@0: explicit octonion(octonion const & a_recopier) sl@0: { sl@0: *this = detail::octonion_type_converter(a_recopier); sl@0: } sl@0: sl@0: explicit octonion(octonion const & a_recopier) sl@0: { sl@0: *this = detail::octonion_type_converter(a_recopier); sl@0: } sl@0: sl@0: // destructor sl@0: // (this is taken care of by the compiler itself) sl@0: sl@0: // accessors sl@0: // sl@0: // Note: Like complex number, octonions do have a meaningful notion of "real part", sl@0: // but unlike them there is no meaningful notion of "imaginary part". sl@0: // Instead there is an "unreal part" which itself is an octonion, and usually sl@0: // nothing simpler (as opposed to the complex number case). sl@0: // However, for practicallity, there are accessors for the other components sl@0: // (these are necessary for the templated copy constructor, for instance). sl@0: sl@0: BOOST_OCTONION_ACCESSOR_GENERATOR(float) sl@0: sl@0: // assignment operators sl@0: sl@0: BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(float) sl@0: sl@0: // other assignment-related operators sl@0: // sl@0: // NOTE: Octonion multiplication is *NOT* commutative; sl@0: // symbolically, "q *= rhs;" means "q = q * rhs;" sl@0: // and "q /= rhs;" means "q = q * inverse_of(rhs);"; sl@0: // octonion multiplication is also *NOT* associative sl@0: sl@0: BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR(float) sl@0: sl@0: sl@0: protected: sl@0: sl@0: BOOST_OCTONION_MEMBER_DATA_GENERATOR(float) sl@0: sl@0: sl@0: private: sl@0: sl@0: }; sl@0: sl@0: sl@0: template<> sl@0: class octonion sl@0: { sl@0: public: sl@0: sl@0: typedef double value_type; sl@0: sl@0: BOOST_OCTONION_CONSTRUCTOR_GENERATOR(double) sl@0: sl@0: // UNtemplated copy constructor sl@0: // (this is taken care of by the compiler itself) sl@0: sl@0: // converting copy constructor sl@0: sl@0: explicit octonion(octonion const & a_recopier) sl@0: { sl@0: *this = detail::octonion_type_converter(a_recopier); sl@0: } sl@0: sl@0: // explicit copy constructors (precision-loosing converters) sl@0: sl@0: explicit octonion(octonion const & a_recopier) sl@0: { sl@0: *this = detail::octonion_type_converter(a_recopier); sl@0: } sl@0: sl@0: // destructor sl@0: // (this is taken care of by the compiler itself) sl@0: sl@0: // accessors sl@0: // sl@0: // Note: Like complex number, octonions do have a meaningful notion of "real part", sl@0: // but unlike them there is no meaningful notion of "imaginary part". sl@0: // Instead there is an "unreal part" which itself is an octonion, and usually sl@0: // nothing simpler (as opposed to the complex number case). sl@0: // However, for practicallity, there are accessors for the other components sl@0: // (these are necessary for the templated copy constructor, for instance). sl@0: sl@0: BOOST_OCTONION_ACCESSOR_GENERATOR(double) sl@0: sl@0: // assignment operators sl@0: sl@0: BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(double) sl@0: sl@0: // other assignment-related operators sl@0: // sl@0: // NOTE: Octonion multiplication is *NOT* commutative; sl@0: // symbolically, "q *= rhs;" means "q = q * rhs;" sl@0: // and "q /= rhs;" means "q = q * inverse_of(rhs);"; sl@0: // octonion multiplication is also *NOT* associative sl@0: sl@0: BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR(double) sl@0: sl@0: sl@0: protected: sl@0: sl@0: BOOST_OCTONION_MEMBER_DATA_GENERATOR(double) sl@0: sl@0: sl@0: private: sl@0: sl@0: }; sl@0: sl@0: sl@0: template<> sl@0: class octonion sl@0: { sl@0: public: sl@0: sl@0: typedef long double value_type; sl@0: sl@0: BOOST_OCTONION_CONSTRUCTOR_GENERATOR(long double) sl@0: sl@0: // UNtemplated copy constructor sl@0: // (this is taken care of by the compiler itself) sl@0: sl@0: // converting copy constructor sl@0: sl@0: explicit octonion(octonion const & a_recopier) sl@0: { sl@0: *this = detail::octonion_type_converter(a_recopier); sl@0: } sl@0: sl@0: sl@0: explicit octonion(octonion const & a_recopier) sl@0: { sl@0: *this = detail::octonion_type_converter(a_recopier); sl@0: } sl@0: sl@0: sl@0: // destructor sl@0: // (this is taken care of by the compiler itself) sl@0: sl@0: // accessors sl@0: // sl@0: // Note: Like complex number, octonions do have a meaningful notion of "real part", sl@0: // but unlike them there is no meaningful notion of "imaginary part". sl@0: // Instead there is an "unreal part" which itself is an octonion, and usually sl@0: // nothing simpler (as opposed to the complex number case). sl@0: // However, for practicallity, there are accessors for the other components sl@0: // (these are necessary for the templated copy constructor, for instance). sl@0: sl@0: BOOST_OCTONION_ACCESSOR_GENERATOR(long double) sl@0: sl@0: // assignment operators sl@0: sl@0: BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(long double) sl@0: sl@0: // other assignment-related operators sl@0: // sl@0: // NOTE: Octonion multiplication is *NOT* commutative; sl@0: // symbolically, "q *= rhs;" means "q = q * rhs;" sl@0: // and "q /= rhs;" means "q = q * inverse_of(rhs);"; sl@0: // octonion multiplication is also *NOT* associative sl@0: sl@0: BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR(long double) sl@0: sl@0: sl@0: protected: sl@0: sl@0: BOOST_OCTONION_MEMBER_DATA_GENERATOR(long double) sl@0: sl@0: sl@0: private: sl@0: sl@0: }; sl@0: sl@0: sl@0: #undef BOOST_OCTONION_CONSTRUCTOR_GENERATOR sl@0: sl@0: #undef BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR sl@0: sl@0: #undef BOOST_OCTONION_MEMBER_ADD_GENERATOR sl@0: #undef BOOST_OCTONION_MEMBER_SUB_GENERATOR sl@0: #undef BOOST_OCTONION_MEMBER_MUL_GENERATOR sl@0: #undef BOOST_OCTONION_MEMBER_DIV_GENERATOR sl@0: sl@0: #undef BOOST_OCTONION_MEMBER_ADD_GENERATOR_1 sl@0: #undef BOOST_OCTONION_MEMBER_ADD_GENERATOR_2 sl@0: #undef BOOST_OCTONION_MEMBER_ADD_GENERATOR_3 sl@0: #undef BOOST_OCTONION_MEMBER_ADD_GENERATOR_4 sl@0: #undef BOOST_OCTONION_MEMBER_SUB_GENERATOR_1 sl@0: #undef BOOST_OCTONION_MEMBER_SUB_GENERATOR_2 sl@0: #undef BOOST_OCTONION_MEMBER_SUB_GENERATOR_3 sl@0: #undef BOOST_OCTONION_MEMBER_SUB_GENERATOR_4 sl@0: #undef BOOST_OCTONION_MEMBER_MUL_GENERATOR_1 sl@0: #undef BOOST_OCTONION_MEMBER_MUL_GENERATOR_2 sl@0: #undef BOOST_OCTONION_MEMBER_MUL_GENERATOR_3 sl@0: #undef BOOST_OCTONION_MEMBER_MUL_GENERATOR_4 sl@0: #undef BOOST_OCTONION_MEMBER_DIV_GENERATOR_1 sl@0: #undef BOOST_OCTONION_MEMBER_DIV_GENERATOR_2 sl@0: #undef BOOST_OCTONION_MEMBER_DIV_GENERATOR_3 sl@0: #undef BOOST_OCTONION_MEMBER_DIV_GENERATOR_4 sl@0: sl@0: sl@0: #undef BOOST_OCTONION_MEMBER_DATA_GENERATOR sl@0: sl@0: #undef BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR sl@0: sl@0: #undef BOOST_OCTONION_ACCESSOR_GENERATOR sl@0: sl@0: sl@0: // operators sl@0: sl@0: #define BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op) \ sl@0: { \ sl@0: octonion res(lhs); \ sl@0: res op##= rhs; \ sl@0: return(res); \ sl@0: } sl@0: sl@0: #define BOOST_OCTONION_OPERATOR_GENERATOR_1_L(op) \ sl@0: template \ sl@0: inline octonion operator op (T const & lhs, octonion const & rhs) \ sl@0: BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op) sl@0: sl@0: #define BOOST_OCTONION_OPERATOR_GENERATOR_1_R(op) \ sl@0: template \ sl@0: inline octonion operator op (octonion const & lhs, T const & rhs) \ sl@0: BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op) sl@0: sl@0: #define BOOST_OCTONION_OPERATOR_GENERATOR_2_L(op) \ sl@0: template \ sl@0: inline octonion operator op (::std::complex const & lhs, octonion const & rhs) \ sl@0: BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op) sl@0: sl@0: #define BOOST_OCTONION_OPERATOR_GENERATOR_2_R(op) \ sl@0: template \ sl@0: inline octonion operator op (octonion const & lhs, ::std::complex const & rhs) \ sl@0: BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op) sl@0: sl@0: #define BOOST_OCTONION_OPERATOR_GENERATOR_3_L(op) \ sl@0: template \ sl@0: inline octonion operator op (::boost::math::quaternion const & lhs, octonion const & rhs) \ sl@0: BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op) sl@0: sl@0: #define BOOST_OCTONION_OPERATOR_GENERATOR_3_R(op) \ sl@0: template \ sl@0: inline octonion operator op (octonion const & lhs, ::boost::math::quaternion const & rhs) \ sl@0: BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op) sl@0: sl@0: #define BOOST_OCTONION_OPERATOR_GENERATOR_4(op) \ sl@0: template \ sl@0: inline octonion operator op (octonion const & lhs, octonion const & rhs) \ sl@0: BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op) sl@0: sl@0: #define BOOST_OCTONION_OPERATOR_GENERATOR(op) \ sl@0: BOOST_OCTONION_OPERATOR_GENERATOR_1_L(op) \ sl@0: BOOST_OCTONION_OPERATOR_GENERATOR_1_R(op) \ sl@0: BOOST_OCTONION_OPERATOR_GENERATOR_2_L(op) \ sl@0: BOOST_OCTONION_OPERATOR_GENERATOR_2_R(op) \ sl@0: BOOST_OCTONION_OPERATOR_GENERATOR_3_L(op) \ sl@0: BOOST_OCTONION_OPERATOR_GENERATOR_3_R(op) \ sl@0: BOOST_OCTONION_OPERATOR_GENERATOR_4(op) sl@0: sl@0: sl@0: BOOST_OCTONION_OPERATOR_GENERATOR(+) sl@0: BOOST_OCTONION_OPERATOR_GENERATOR(-) sl@0: BOOST_OCTONION_OPERATOR_GENERATOR(*) sl@0: BOOST_OCTONION_OPERATOR_GENERATOR(/) sl@0: sl@0: sl@0: #undef BOOST_OCTONION_OPERATOR_GENERATOR sl@0: sl@0: #undef BOOST_OCTONION_OPERATOR_GENERATOR_1_L sl@0: #undef BOOST_OCTONION_OPERATOR_GENERATOR_1_R sl@0: #undef BOOST_OCTONION_OPERATOR_GENERATOR_2_L sl@0: #undef BOOST_OCTONION_OPERATOR_GENERATOR_2_R sl@0: #undef BOOST_OCTONION_OPERATOR_GENERATOR_3_L sl@0: #undef BOOST_OCTONION_OPERATOR_GENERATOR_3_R sl@0: #undef BOOST_OCTONION_OPERATOR_GENERATOR_4 sl@0: sl@0: #undef BOOST_OCTONION_OPERATOR_GENERATOR_BODY sl@0: sl@0: sl@0: template sl@0: inline octonion operator + (octonion const & o) sl@0: { sl@0: return(o); sl@0: } sl@0: sl@0: sl@0: template sl@0: inline octonion operator - (octonion const & o) sl@0: { sl@0: return(octonion(-o.R_component_1(),-o.R_component_2(),-o.R_component_3(),-o.R_component_4(),-o.R_component_5(),-o.R_component_6(),-o.R_component_7(),-o.R_component_8())); sl@0: } sl@0: sl@0: sl@0: template sl@0: inline bool operator == (T const & lhs, octonion const & rhs) sl@0: { sl@0: return( sl@0: (rhs.R_component_1() == lhs)&& sl@0: (rhs.R_component_2() == static_cast(0))&& sl@0: (rhs.R_component_3() == static_cast(0))&& sl@0: (rhs.R_component_4() == static_cast(0))&& sl@0: (rhs.R_component_5() == static_cast(0))&& sl@0: (rhs.R_component_6() == static_cast(0))&& sl@0: (rhs.R_component_7() == static_cast(0))&& sl@0: (rhs.R_component_8() == static_cast(0)) sl@0: ); sl@0: } sl@0: sl@0: sl@0: template sl@0: inline bool operator == (octonion const & lhs, T const & rhs) sl@0: { sl@0: return( sl@0: (lhs.R_component_1() == rhs)&& sl@0: (lhs.R_component_2() == static_cast(0))&& sl@0: (lhs.R_component_3() == static_cast(0))&& sl@0: (lhs.R_component_4() == static_cast(0))&& sl@0: (lhs.R_component_5() == static_cast(0))&& sl@0: (lhs.R_component_6() == static_cast(0))&& sl@0: (lhs.R_component_7() == static_cast(0))&& sl@0: (lhs.R_component_8() == static_cast(0)) sl@0: ); sl@0: } sl@0: sl@0: sl@0: template sl@0: inline bool operator == (::std::complex const & lhs, octonion const & rhs) sl@0: { sl@0: return( sl@0: (rhs.R_component_1() == lhs.real())&& sl@0: (rhs.R_component_2() == lhs.imag())&& sl@0: (rhs.R_component_3() == static_cast(0))&& sl@0: (rhs.R_component_4() == static_cast(0))&& sl@0: (rhs.R_component_5() == static_cast(0))&& sl@0: (rhs.R_component_6() == static_cast(0))&& sl@0: (rhs.R_component_7() == static_cast(0))&& sl@0: (rhs.R_component_8() == static_cast(0)) sl@0: ); sl@0: } sl@0: sl@0: sl@0: template sl@0: inline bool operator == (octonion const & lhs, ::std::complex const & rhs) sl@0: { sl@0: return( sl@0: (lhs.R_component_1() == rhs.real())&& sl@0: (lhs.R_component_2() == rhs.imag())&& sl@0: (lhs.R_component_3() == static_cast(0))&& sl@0: (lhs.R_component_4() == static_cast(0))&& sl@0: (lhs.R_component_5() == static_cast(0))&& sl@0: (lhs.R_component_6() == static_cast(0))&& sl@0: (lhs.R_component_7() == static_cast(0))&& sl@0: (lhs.R_component_8() == static_cast(0)) sl@0: ); sl@0: } sl@0: sl@0: sl@0: template sl@0: inline bool operator == (::boost::math::quaternion const & lhs, octonion const & rhs) sl@0: { sl@0: return( sl@0: (rhs.R_component_1() == lhs.R_component_1())&& sl@0: (rhs.R_component_2() == lhs.R_component_2())&& sl@0: (rhs.R_component_3() == lhs.R_component_3())&& sl@0: (rhs.R_component_4() == lhs.R_component_4())&& sl@0: (rhs.R_component_5() == static_cast(0))&& sl@0: (rhs.R_component_6() == static_cast(0))&& sl@0: (rhs.R_component_7() == static_cast(0))&& sl@0: (rhs.R_component_8() == static_cast(0)) sl@0: ); sl@0: } sl@0: sl@0: sl@0: template sl@0: inline bool operator == (octonion const & lhs, ::boost::math::quaternion const & rhs) sl@0: { sl@0: return( sl@0: (lhs.R_component_1() == rhs.R_component_1())&& sl@0: (lhs.R_component_2() == rhs.R_component_2())&& sl@0: (lhs.R_component_3() == rhs.R_component_3())&& sl@0: (lhs.R_component_4() == rhs.R_component_4())&& sl@0: (lhs.R_component_5() == static_cast(0))&& sl@0: (lhs.R_component_6() == static_cast(0))&& sl@0: (lhs.R_component_7() == static_cast(0))&& sl@0: (lhs.R_component_8() == static_cast(0)) sl@0: ); sl@0: } sl@0: sl@0: sl@0: template sl@0: inline bool operator == (octonion const & lhs, octonion const & rhs) sl@0: { sl@0: return( sl@0: (rhs.R_component_1() == lhs.R_component_1())&& sl@0: (rhs.R_component_2() == lhs.R_component_2())&& sl@0: (rhs.R_component_3() == lhs.R_component_3())&& sl@0: (rhs.R_component_4() == lhs.R_component_4())&& sl@0: (rhs.R_component_5() == lhs.R_component_5())&& sl@0: (rhs.R_component_6() == lhs.R_component_6())&& sl@0: (rhs.R_component_7() == lhs.R_component_7())&& sl@0: (rhs.R_component_8() == lhs.R_component_8()) sl@0: ); sl@0: } sl@0: sl@0: sl@0: #define BOOST_OCTONION_NOT_EQUAL_GENERATOR \ sl@0: { \ sl@0: return(!(lhs == rhs)); \ sl@0: } sl@0: sl@0: template sl@0: inline bool operator != (T const & lhs, octonion const & rhs) sl@0: BOOST_OCTONION_NOT_EQUAL_GENERATOR sl@0: sl@0: template sl@0: inline bool operator != (octonion const & lhs, T const & rhs) sl@0: BOOST_OCTONION_NOT_EQUAL_GENERATOR sl@0: sl@0: template sl@0: inline bool operator != (::std::complex const & lhs, octonion const & rhs) sl@0: BOOST_OCTONION_NOT_EQUAL_GENERATOR sl@0: sl@0: template sl@0: inline bool operator != (octonion const & lhs, ::std::complex const & rhs) sl@0: BOOST_OCTONION_NOT_EQUAL_GENERATOR sl@0: sl@0: template sl@0: inline bool operator != (::boost::math::quaternion const & lhs, octonion const & rhs) sl@0: BOOST_OCTONION_NOT_EQUAL_GENERATOR sl@0: sl@0: template sl@0: inline bool operator != (octonion const & lhs, ::boost::math::quaternion const & rhs) sl@0: BOOST_OCTONION_NOT_EQUAL_GENERATOR sl@0: sl@0: template sl@0: inline bool operator != (octonion const & lhs, octonion const & rhs) sl@0: BOOST_OCTONION_NOT_EQUAL_GENERATOR sl@0: sl@0: #undef BOOST_OCTONION_NOT_EQUAL_GENERATOR sl@0: sl@0: sl@0: // Note: the default values in the constructors of the complex and quaternions make for sl@0: // a very complex and ambiguous situation; we have made choices to disambiguate. sl@0: sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: template sl@0: ::std::istream & operator >> ( ::std::istream & is, sl@0: octonion& o) sl@0: #else sl@0: template sl@0: ::std::basic_istream & operator >> ( ::std::basic_istream & is, sl@0: octonion & o) sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: typedef char charT; sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: #else sl@0: const ::std::ctype & ct = ::std::use_facet< ::std::ctype >(is.getloc()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: T a = T(); sl@0: T b = T(); sl@0: T c = T(); sl@0: T d = T(); sl@0: T e = T(); sl@0: T f = T(); sl@0: T g = T(); sl@0: T h = T(); sl@0: sl@0: ::std::complex u = ::std::complex(); sl@0: ::std::complex v = ::std::complex(); sl@0: ::std::complex x = ::std::complex(); sl@0: ::std::complex y = ::std::complex(); sl@0: sl@0: ::boost::math::quaternion p = ::boost::math::quaternion(); sl@0: ::boost::math::quaternion q = ::boost::math::quaternion(); sl@0: sl@0: charT ch = charT(); sl@0: char cc; sl@0: sl@0: is >> ch; // get the first lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == '(') // read "(" sl@0: { sl@0: is >> ch; // get the second lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == '(') // read "((" sl@0: { sl@0: is >> ch; // get the third lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == '(') // read "(((" sl@0: { sl@0: is.putback(ch); sl@0: sl@0: is >> u; // read "((u" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((u)" sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // format: (((a))), (((a,b))) sl@0: { sl@0: o = octonion(u); sl@0: } sl@0: else if (cc == ',') // read "((u)," sl@0: { sl@0: p = ::boost::math::quaternion(u); sl@0: sl@0: is >> q; // read "((u),q" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // format: (((a)),q), (((a,b)),q) sl@0: { sl@0: o = octonion(p,q); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else if (cc ==',') // read "((u," sl@0: { sl@0: is >> v; // read "((u,v" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((u,v)" sl@0: { sl@0: p = ::boost::math::quaternion(u,v); sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // format: (((a),v)), (((a,b),v)) sl@0: { sl@0: o = octonion(p); sl@0: } sl@0: else if (cc == ',') // read "((u,v)," sl@0: { sl@0: is >> q; // read "(p,q" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // format: (((a),v),q), (((a,b),v),q) sl@0: { sl@0: o = octonion(p,q); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // read "((a" sl@0: { sl@0: is.putback(ch); sl@0: sl@0: is >> a; // we extract the first component sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a)" sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a))" sl@0: { sl@0: o = octonion(a); sl@0: } sl@0: else if (cc == ',') // read "((a)," sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == '(') // read "((a),(" sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == '(') // read "((a),((" sl@0: { sl@0: is.putback(ch); sl@0: sl@0: is.putback(ch); // we backtrack twice, with the same value! sl@0: sl@0: is >> q; // read "((a),q" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a),q)" sl@0: { sl@0: p = ::boost::math::quaternion(a); sl@0: sl@0: o = octonion(p,q); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // read "((a),(c" or "((a),(e" sl@0: { sl@0: is.putback(ch); sl@0: sl@0: is >> c; sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a),(c)" (ambiguity resolution) sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a),(c))" sl@0: { sl@0: o = octonion(a,b,c); sl@0: } sl@0: else if (cc == ',') // read "((a),(c)," sl@0: { sl@0: u = ::std::complex(a); sl@0: sl@0: v = ::std::complex(c); sl@0: sl@0: is >> x; // read "((a),(c),x" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a),(c),x)" sl@0: { sl@0: o = octonion(u,v,x); sl@0: } sl@0: else if (cc == ',') // read "((a),(c),x," sl@0: { sl@0: is >> y; // read "((a),(c),x,y" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a),(c),x,y)" sl@0: { sl@0: o = octonion(u,v,x,y); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else if (cc == ',') // read "((a),(c," or "((a),(e," sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == '(') // read "((a),(e,(" (ambiguity resolution) sl@0: { sl@0: p = ::boost::math::quaternion(a); sl@0: sl@0: x = ::std::complex(c); // "c" was actually "e" sl@0: sl@0: is.putback(ch); // we can only backtrace once sl@0: sl@0: is >> y; // read "((a),(e,y" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a),(e,y)" sl@0: { sl@0: q = ::boost::math::quaternion(x,y); sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a),(e,y))" sl@0: { sl@0: o = octonion(p,q); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // read "((a),(c,d" or "((a),(e,f" sl@0: { sl@0: is.putback(ch); sl@0: sl@0: is >> d; sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a),(c,d)" (ambiguity resolution) sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a),(c,d))" sl@0: { sl@0: o = octonion(a,b,c,d); sl@0: } sl@0: else if (cc == ',') // read "((a),(c,d)," sl@0: { sl@0: u = ::std::complex(a); sl@0: sl@0: v = ::std::complex(c,d); sl@0: sl@0: is >> x; // read "((a),(c,d),x" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a),(c,d),x)" sl@0: { sl@0: o = octonion(u,v,x); sl@0: } sl@0: else if (cc == ',') // read "((a),(c,d),x," sl@0: { sl@0: is >> y; // read "((a),(c,d),x,y" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a),(c,d),x,y)" sl@0: { sl@0: o = octonion(u,v,x,y); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else if (cc == ',') // read "((a),(e,f," (ambiguity resolution) sl@0: { sl@0: p = ::boost::math::quaternion(a); sl@0: sl@0: is >> g; // read "((a),(e,f,g" (too late to backtrack) sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a),(e,f,g)" sl@0: { sl@0: q = ::boost::math::quaternion(c,d,g); // "c" was actually "e", and "d" was actually "f" sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a),(e,f,g))" sl@0: { sl@0: o = octonion(p,q); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else if (cc == ',') // read "((a),(e,f,g," sl@0: { sl@0: is >> h; // read "((a),(e,f,g,h" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a),(e,f,g,h)" sl@0: { sl@0: q = ::boost::math::quaternion(c,d,g,h); // "c" was actually "e", and "d" was actually "f" sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a),(e,f,g,h))" sl@0: { sl@0: o = octonion(p,q); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: } sl@0: else // read "((a),c" (ambiguity resolution) sl@0: { sl@0: is.putback(ch); sl@0: sl@0: is >> c; // we extract the third component sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a),c)" sl@0: { sl@0: o = octonion(a,b,c); sl@0: } sl@0: else if (cc == ',') // read "((a),c," sl@0: { sl@0: is >> x; // read "((a),c,x" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a),c,x)" sl@0: { sl@0: o = octonion(a,b,c,d,x.real(),x.imag()); sl@0: } sl@0: else if (cc == ',') // read "((a),c,x," sl@0: { sl@0: is >> y;if (!is.good()) goto finish; // read "((a),c,x,y" sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a),c,x,y)" sl@0: { sl@0: o = octonion(a,b,c,d,x.real(),x.imag(),y.real(),y.imag()); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else if (cc ==',') // read "((a," sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == '(') // read "((a,(" sl@0: { sl@0: u = ::std::complex(a); sl@0: sl@0: is.putback(ch); // can only backtrack so much sl@0: sl@0: is >> v; // read "((a,v" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,v)" sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,v))" sl@0: { sl@0: o = octonion(u,v); sl@0: } sl@0: else if (cc == ',') // read "((a,v)," sl@0: { sl@0: p = ::boost::math::quaternion(u,v); sl@0: sl@0: is >> q; // read "((a,v),q" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,v),q)" sl@0: { sl@0: o = octonion(p,q); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else sl@0: { sl@0: is.putback(ch); sl@0: sl@0: is >> b; // read "((a,b" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,b)" sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,b))" sl@0: { sl@0: o = octonion(a,b); sl@0: } sl@0: else if (cc == ',') // read "((a,b)," sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == '(') // read "((a,b),(" sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == '(') // read "((a,b),((" sl@0: { sl@0: p = ::boost::math::quaternion(a,b); sl@0: sl@0: is.putback(ch); sl@0: sl@0: is.putback(ch); // we backtrack twice, with the same value sl@0: sl@0: is >> q; // read "((a,b),q" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,b),q)" sl@0: { sl@0: o = octonion(p,q); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // read "((a,b),(c" or "((a,b),(e" sl@0: { sl@0: is.putback(ch); sl@0: sl@0: is >> c; sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,b),(c)" (ambiguity resolution) sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,b),(c))" sl@0: { sl@0: o = octonion(a,b,c); sl@0: } sl@0: else if (cc == ',') // read "((a,b),(c)," sl@0: { sl@0: u = ::std::complex(a,b); sl@0: sl@0: v = ::std::complex(c); sl@0: sl@0: is >> x; // read "((a,b),(c),x" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,b),(c),x)" sl@0: { sl@0: o = octonion(u,v,x); sl@0: } sl@0: else if (cc == ',') // read "((a,b),(c),x," sl@0: { sl@0: is >> y; // read "((a,b),(c),x,y" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,b),(c),x,y)" sl@0: { sl@0: o = octonion(u,v,x,y); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else if (cc == ',') // read "((a,b),(c," or "((a,b),(e," sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == '(') // read "((a,b),(e,(" (ambiguity resolution) sl@0: { sl@0: u = ::std::complex(a,b); sl@0: sl@0: x = ::std::complex(c); // "c" is actually "e" sl@0: sl@0: is.putback(ch); sl@0: sl@0: is >> y; // read "((a,b),(e,y" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,b),(e,y)" sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,b),(e,y))" sl@0: { sl@0: o = octonion(u,v,x,y); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // read "((a,b),(c,d" or "((a,b),(e,f" sl@0: { sl@0: is.putback(ch); sl@0: sl@0: is >> d; sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,b),(c,d)" (ambiguity resolution) sl@0: { sl@0: u = ::std::complex(a,b); sl@0: sl@0: v = ::std::complex(c,d); sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,b),(c,d))" sl@0: { sl@0: o = octonion(u,v); sl@0: } sl@0: else if (cc == ',') // read "((a,b),(c,d)," sl@0: { sl@0: is >> x; // read "((a,b),(c,d),x sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,b),(c,d),x)" sl@0: { sl@0: o = octonion(u,v,x); sl@0: } sl@0: else if (cc == ',') // read "((a,b),(c,d),x," sl@0: { sl@0: is >> y; // read "((a,b),(c,d),x,y" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,b),(c,d),x,y)" sl@0: { sl@0: o = octonion(u,v,x,y); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else if (cc == ',') // read "((a,b),(e,f," (ambiguity resolution) sl@0: { sl@0: p = ::boost::math::quaternion(a,b); // too late to backtrack sl@0: sl@0: is >> g; // read "((a,b),(e,f,g" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,b),(e,f,g)" sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,b),(e,f,g))" sl@0: { sl@0: q = ::boost::math::quaternion(c,d,g); // "c" is actually "e" and "d" is actually "f" sl@0: sl@0: o = octonion(p,q); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else if (cc == ',') // read "((a,b),(e,f,g," sl@0: { sl@0: is >> h; // read "((a,b),(e,f,g,h" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,b),(e,f,g,h)" sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read ((a,b),(e,f,g,h))" sl@0: { sl@0: q = ::boost::math::quaternion(c,d,g,h); // "c" is actually "e" and "d" is actually "f" sl@0: sl@0: o = octonion(p,q); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else if (cc == ',') // read "((a,b," sl@0: { sl@0: is >> c; // read "((a,b,c" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,b,c)" sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,b,c))" sl@0: { sl@0: o = octonion(a,b,c); sl@0: } sl@0: else if (cc == ',') // read "((a,b,c)," sl@0: { sl@0: p = ::boost::math::quaternion(a,b,c); sl@0: sl@0: is >> q; // read "((a,b,c),q" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,b,c),q)" sl@0: { sl@0: o = octonion(p,q); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else if (cc == ',') // read "((a,b,c," sl@0: { sl@0: is >> d; // read "((a,b,c,d" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,b,c,d)" sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,b,c,d))" sl@0: { sl@0: o = octonion(a,b,c,d); sl@0: } sl@0: else if (cc == ',') // read "((a,b,c,d)," sl@0: { sl@0: p = ::boost::math::quaternion(a,b,c,d); sl@0: sl@0: is >> q; // read "((a,b,c,d),q" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "((a,b,c,d),q)" sl@0: { sl@0: o = octonion(p,q); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: } sl@0: else // read "(a" sl@0: { sl@0: is.putback(ch); sl@0: sl@0: is >> a; // we extract the first component sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a)" sl@0: { sl@0: o = octonion(a); sl@0: } sl@0: else if (cc == ',') // read "(a," sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == '(') // read "(a,(" sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == '(') // read "(a,((" sl@0: { sl@0: p = ::boost::math::quaternion(a); sl@0: sl@0: is.putback(ch); sl@0: sl@0: is.putback(ch); // we backtrack twice, with the same value sl@0: sl@0: is >> q; // read "(a,q" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,q)" sl@0: { sl@0: o = octonion(p,q); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // read "(a,(c" or "(a,(e" sl@0: { sl@0: is.putback(ch); sl@0: sl@0: is >> c; sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,(c)" (ambiguity resolution) sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,(c))" sl@0: { sl@0: o = octonion(a,b,c); sl@0: } sl@0: else if (cc == ',') // read "(a,(c)," sl@0: { sl@0: u = ::std::complex(a); sl@0: sl@0: v = ::std::complex(c); sl@0: sl@0: is >> x; // read "(a,(c),x" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,(c),x)" sl@0: { sl@0: o = octonion(u,v,x); sl@0: } sl@0: else if (cc == ',') // read "(a,(c),x," sl@0: { sl@0: is >> y; // read "(a,(c),x,y" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,(c),x,y)" sl@0: { sl@0: o = octonion(u,v,x,y); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else if (cc == ',') // read "(a,(c," or "(a,(e," sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == '(') // read "(a,(e,(" (ambiguity resolution) sl@0: { sl@0: u = ::std::complex(a); sl@0: sl@0: x = ::std::complex(c); // "c" is actually "e" sl@0: sl@0: is.putback(ch); // we backtrack sl@0: sl@0: is >> y; // read "(a,(e,y" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,(e,y)" sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,(e,y))" sl@0: { sl@0: o = octonion(u,v,x,y); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // read "(a,(c,d" or "(a,(e,f" sl@0: { sl@0: is.putback(ch); sl@0: sl@0: is >> d; sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,(c,d)" (ambiguity resolution) sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,(c,d))" sl@0: { sl@0: o = octonion(a,b,c,d); sl@0: } sl@0: else if (cc == ',') // read "(a,(c,d)," sl@0: { sl@0: u = ::std::complex(a); sl@0: sl@0: v = ::std::complex(c,d); sl@0: sl@0: is >> x; // read "(a,(c,d),x" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,(c,d),x)" sl@0: { sl@0: o = octonion(u,v,x); sl@0: } sl@0: else if (cc == ',') // read "(a,(c,d),x," sl@0: { sl@0: is >> y; // read "(a,(c,d),x,y" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,(c,d),x,y)" sl@0: { sl@0: o = octonion(u,v,x,y); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else if (cc == ',') // read "(a,(e,f," (ambiguity resolution) sl@0: { sl@0: p = ::boost::math::quaternion(a); sl@0: sl@0: is >> g; // read "(a,(e,f,g" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,(e,f,g)" sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,(e,f,g))" sl@0: { sl@0: q = ::boost::math::quaternion(c,d,g); // "c" is actually "e" and "d" is actually "f" sl@0: sl@0: o = octonion(p,q); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else if (cc == ',') // read "(a,(e,f,g," sl@0: { sl@0: is >> h; // read "(a,(e,f,g,h" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,(e,f,g,h)" sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,(e,f,g,h))" sl@0: { sl@0: q = ::boost::math::quaternion(c,d,g,h); // "c" is actually "e" and "d" is actually "f" sl@0: sl@0: o = octonion(p,q); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: } sl@0: else // read "(a,b" or "(a,c" (ambiguity resolution) sl@0: { sl@0: is.putback(ch); sl@0: sl@0: is >> b; sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,b)" (ambiguity resolution) sl@0: { sl@0: o = octonion(a,b); sl@0: } sl@0: else if (cc == ',') // read "(a,b," or "(a,c," sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == '(') // read "(a,c,(" (ambiguity resolution) sl@0: { sl@0: u = ::std::complex(a); sl@0: sl@0: v = ::std::complex(b); // "b" is actually "c" sl@0: sl@0: is.putback(ch); // we backtrack sl@0: sl@0: is >> x; // read "(a,c,x" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,c,x)" sl@0: { sl@0: o = octonion(u,v,x); sl@0: } sl@0: else if (cc == ',') // read "(a,c,x," sl@0: { sl@0: is >> y; // read "(a,c,x,y" // read "(a,c,x" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,c,x,y)" sl@0: { sl@0: o = octonion(u,v,x,y); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // read "(a,b,c" or "(a,c,e" sl@0: { sl@0: is.putback(ch); sl@0: sl@0: is >> c; sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,b,c)" (ambiguity resolution) sl@0: { sl@0: o = octonion(a,b,c); sl@0: } sl@0: else if (cc == ',') // read "(a,b,c," or "(a,c,e," sl@0: { sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == '(') // read "(a,c,e,(") (ambiguity resolution) sl@0: { sl@0: u = ::std::complex(a); sl@0: sl@0: v = ::std::complex(b); // "b" is actually "c" sl@0: sl@0: x = ::std::complex(c); // "c" is actually "e" sl@0: sl@0: is.putback(ch); // we backtrack sl@0: sl@0: is >> y; // read "(a,c,e,y" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,c,e,y)" sl@0: { sl@0: o = octonion(u,v,x,y); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // read "(a,b,c,d" (ambiguity resolution) sl@0: { sl@0: is.putback(ch); // we backtrack sl@0: sl@0: is >> d; sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,b,c,d)" sl@0: { sl@0: o = octonion(a,b,c,d); sl@0: } sl@0: else if (cc == ',') // read "(a,b,c,d," sl@0: { sl@0: is >> e; // read "(a,b,c,d,e" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,b,c,d,e)" sl@0: { sl@0: o = octonion(a,b,c,d,e); sl@0: } sl@0: else if (cc == ',') // read "(a,b,c,d,e," sl@0: { sl@0: is >> f; // read "(a,b,c,d,e,f" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,b,c,d,e,f)" sl@0: { sl@0: o = octonion(a,b,c,d,e,f); sl@0: } sl@0: else if (cc == ',') // read "(a,b,c,d,e,f," sl@0: { sl@0: is >> g; // read "(a,b,c,d,e,f,g" // read "(a,b,c,d,e,f" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,b,c,d,e,f,g)" sl@0: { sl@0: o = octonion(a,b,c,d,e,f,g); sl@0: } sl@0: else if (cc == ',') // read "(a,b,c,d,e,f,g," sl@0: { sl@0: is >> h; // read "(a,b,c,d,e,f,g,h" // read "(a,b,c,d,e,f,g" // read "(a,b,c,d,e,f" sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: is >> ch; // get the next lexeme sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: cc = ch; sl@0: #else sl@0: cc = ct.narrow(ch, char()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: sl@0: if (cc == ')') // read "(a,b,c,d,e,f,g,h)" sl@0: { sl@0: o = octonion(a,b,c,d,e,f,g,h); sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: } sl@0: else // error sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: is.setstate(::std::ios::failbit); sl@0: #else sl@0: is.setstate(::std::ios_base::failbit); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: } sl@0: } sl@0: else // format: a sl@0: { sl@0: is.putback(ch); sl@0: sl@0: is >> a; // we extract the first component sl@0: sl@0: if (!is.good()) goto finish; sl@0: sl@0: o = octonion(a); sl@0: } sl@0: sl@0: finish: sl@0: return(is); sl@0: } sl@0: sl@0: sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: template sl@0: ::std::ostream & operator << ( ::std::ostream & os, sl@0: octonion const & o) sl@0: #else sl@0: template sl@0: ::std::basic_ostream & operator << ( ::std::basic_ostream & os, sl@0: octonion const & o) sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: { sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: ::std::ostringstream s; sl@0: #else sl@0: ::std::basic_ostringstream s; sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: sl@0: s.flags(os.flags()); sl@0: #ifdef BOOST_NO_STD_LOCALE sl@0: #else sl@0: s.imbue(os.getloc()); sl@0: #endif /* BOOST_NO_STD_LOCALE */ sl@0: s.precision(os.precision()); sl@0: sl@0: s << '(' << o.R_component_1() << ',' sl@0: << o.R_component_2() << ',' sl@0: << o.R_component_3() << ',' sl@0: << o.R_component_4() << ',' sl@0: << o.R_component_5() << ',' sl@0: << o.R_component_6() << ',' sl@0: << o.R_component_7() << ',' sl@0: << o.R_component_8() << ')'; sl@0: sl@0: return os << s.str(); sl@0: } sl@0: sl@0: sl@0: // values sl@0: sl@0: template sl@0: inline T real(octonion const & o) sl@0: { sl@0: return(o.real()); sl@0: } sl@0: sl@0: sl@0: template sl@0: inline octonion unreal(octonion const & o) sl@0: { sl@0: return(o.unreal()); sl@0: } sl@0: sl@0: sl@0: #define BOOST_OCTONION_VALARRAY_LOADER \ sl@0: using ::std::valarray; \ sl@0: \ sl@0: valarray temp(8); \ sl@0: \ sl@0: temp[0] = o.R_component_1(); \ sl@0: temp[1] = o.R_component_2(); \ sl@0: temp[2] = o.R_component_3(); \ sl@0: temp[3] = o.R_component_4(); \ sl@0: temp[4] = o.R_component_5(); \ sl@0: temp[5] = o.R_component_6(); \ sl@0: temp[6] = o.R_component_7(); \ sl@0: temp[7] = o.R_component_8(); sl@0: sl@0: sl@0: template sl@0: inline T sup(octonion const & o) sl@0: { sl@0: #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP sl@0: using ::std::abs; sl@0: #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ sl@0: sl@0: BOOST_OCTONION_VALARRAY_LOADER sl@0: sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: return((BOOST_GET_VALARRAY(T, abs(temp)).max)()); sl@0: #else sl@0: return((abs(temp).max)()); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: sl@0: sl@0: template sl@0: inline T l1(octonion const & o) sl@0: { sl@0: #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP sl@0: using ::std::abs; sl@0: #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ sl@0: sl@0: BOOST_OCTONION_VALARRAY_LOADER sl@0: sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: return(BOOST_GET_VALARRAY(T, abs(temp)).sum()); sl@0: #else sl@0: return(abs(temp).sum()); sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: } sl@0: sl@0: sl@0: template sl@0: inline T abs(const octonion & o) sl@0: { sl@0: #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP sl@0: using ::std::abs; sl@0: #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ sl@0: sl@0: using ::std::sqrt; sl@0: sl@0: BOOST_OCTONION_VALARRAY_LOADER sl@0: sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: T maxim = (BOOST_GET_VALARRAY(T,abs(temp)).max)(); // overflow protection sl@0: #else sl@0: T maxim = (abs(temp).max)(); // overflow protection sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: sl@0: if (maxim == static_cast(0)) sl@0: { sl@0: return(maxim); sl@0: } sl@0: else sl@0: { sl@0: T mixam = static_cast(1)/maxim; // prefer multiplications over divisions sl@0: sl@0: temp *= mixam; sl@0: sl@0: temp *= temp; sl@0: sl@0: return(maxim*sqrt(temp.sum())); sl@0: } sl@0: sl@0: //return(::std::sqrt(norm(o))); sl@0: } sl@0: sl@0: sl@0: #undef BOOST_OCTONION_VALARRAY_LOADER sl@0: sl@0: sl@0: // Note: This is the Cayley norm, not the Euclidian norm... sl@0: sl@0: template sl@0: inline T norm(octonion const & o) sl@0: { sl@0: return(real(o*conj(o))); sl@0: } sl@0: sl@0: sl@0: template sl@0: inline octonion conj(octonion const & o) sl@0: { sl@0: return(octonion( +o.R_component_1(), sl@0: -o.R_component_2(), sl@0: -o.R_component_3(), sl@0: -o.R_component_4(), sl@0: -o.R_component_5(), sl@0: -o.R_component_6(), sl@0: -o.R_component_7(), sl@0: -o.R_component_8())); sl@0: } sl@0: sl@0: sl@0: // Note: There is little point, for the octonions, to introduce the equivalents sl@0: // to the complex "arg" and the quaternionic "cylindropolar". sl@0: sl@0: sl@0: template sl@0: inline octonion spherical(T const & rho, sl@0: T const & theta, sl@0: T const & phi1, sl@0: T const & phi2, sl@0: T const & phi3, sl@0: T const & phi4, sl@0: T const & phi5, sl@0: T const & phi6) sl@0: { sl@0: using ::std::cos; sl@0: using ::std::sin; sl@0: sl@0: //T a = cos(theta)*cos(phi1)*cos(phi2)*cos(phi3)*cos(phi4)*cos(phi5)*cos(phi6); sl@0: //T b = sin(theta)*cos(phi1)*cos(phi2)*cos(phi3)*cos(phi4)*cos(phi5)*cos(phi6); sl@0: //T c = sin(phi1)*cos(phi2)*cos(phi3)*cos(phi4)*cos(phi5)*cos(phi6); sl@0: //T d = sin(phi2)*cos(phi3)*cos(phi4)*cos(phi5)*cos(phi6); sl@0: //T e = sin(phi3)*cos(phi4)*cos(phi5)*cos(phi6); sl@0: //T f = sin(phi4)*cos(phi5)*cos(phi6); sl@0: //T g = sin(phi5)*cos(phi6); sl@0: //T h = sin(phi6); sl@0: sl@0: T courrant = static_cast(1); sl@0: sl@0: T h = sin(phi6); sl@0: sl@0: courrant *= cos(phi6); sl@0: sl@0: T g = sin(phi5)*courrant; sl@0: sl@0: courrant *= cos(phi5); sl@0: sl@0: T f = sin(phi4)*courrant; sl@0: sl@0: courrant *= cos(phi4); sl@0: sl@0: T e = sin(phi3)*courrant; sl@0: sl@0: courrant *= cos(phi3); sl@0: sl@0: T d = sin(phi2)*courrant; sl@0: sl@0: courrant *= cos(phi2); sl@0: sl@0: T c = sin(phi1)*courrant; sl@0: sl@0: courrant *= cos(phi1); sl@0: sl@0: T b = sin(theta)*courrant; sl@0: T a = cos(theta)*courrant; sl@0: sl@0: return(rho*octonion(a,b,c,d,e,f,g,h)); sl@0: } sl@0: sl@0: sl@0: template sl@0: inline octonion multipolar(T const & rho1, sl@0: T const & theta1, sl@0: T const & rho2, sl@0: T const & theta2, sl@0: T const & rho3, sl@0: T const & theta3, sl@0: T const & rho4, sl@0: T const & theta4) sl@0: { sl@0: using ::std::cos; sl@0: using ::std::sin; sl@0: sl@0: T a = rho1*cos(theta1); sl@0: T b = rho1*sin(theta1); sl@0: T c = rho2*cos(theta2); sl@0: T d = rho2*sin(theta2); sl@0: T e = rho3*cos(theta3); sl@0: T f = rho3*sin(theta3); sl@0: T g = rho4*cos(theta4); sl@0: T h = rho4*sin(theta4); sl@0: sl@0: return(octonion(a,b,c,d,e,f,g,h)); sl@0: } sl@0: sl@0: sl@0: template sl@0: inline octonion cylindrical(T const & r, sl@0: T const & angle, sl@0: T const & h1, sl@0: T const & h2, sl@0: T const & h3, sl@0: T const & h4, sl@0: T const & h5, sl@0: T const & h6) sl@0: { sl@0: using ::std::cos; sl@0: using ::std::sin; sl@0: sl@0: T a = r*cos(angle); sl@0: T b = r*sin(angle); sl@0: sl@0: return(octonion(a,b,h1,h2,h3,h4,h5,h6)); sl@0: } sl@0: sl@0: sl@0: template sl@0: inline octonion exp(octonion const & o) sl@0: { sl@0: using ::std::exp; sl@0: using ::std::cos; sl@0: sl@0: using ::boost::math::sinc_pi; sl@0: sl@0: T u = exp(real(o)); sl@0: sl@0: T z = abs(unreal(o)); sl@0: sl@0: T w = sinc_pi(z); sl@0: sl@0: return(u*octonion(cos(z), sl@0: w*o.R_component_2(), w*o.R_component_3(), sl@0: w*o.R_component_4(), w*o.R_component_5(), sl@0: w*o.R_component_6(), w*o.R_component_7(), sl@0: w*o.R_component_8())); sl@0: } sl@0: sl@0: sl@0: template sl@0: inline octonion cos(octonion const & o) sl@0: { sl@0: using ::std::sin; sl@0: using ::std::cos; sl@0: using ::std::cosh; sl@0: sl@0: using ::boost::math::sinhc_pi; sl@0: sl@0: T z = abs(unreal(o)); sl@0: sl@0: T w = -sin(o.real())*sinhc_pi(z); sl@0: sl@0: return(octonion(cos(o.real())*cosh(z), sl@0: w*o.R_component_2(), w*o.R_component_3(), sl@0: w*o.R_component_4(), w*o.R_component_5(), sl@0: w*o.R_component_6(), w*o.R_component_7(), sl@0: w*o.R_component_8())); sl@0: } sl@0: sl@0: sl@0: template sl@0: inline octonion sin(octonion const & o) sl@0: { sl@0: using ::std::sin; sl@0: using ::std::cos; sl@0: using ::std::cosh; sl@0: sl@0: using ::boost::math::sinhc_pi; sl@0: sl@0: T z = abs(unreal(o)); sl@0: sl@0: T w = +cos(o.real())*sinhc_pi(z); sl@0: sl@0: return(octonion(sin(o.real())*cosh(z), sl@0: w*o.R_component_2(), w*o.R_component_3(), sl@0: w*o.R_component_4(), w*o.R_component_5(), sl@0: w*o.R_component_6(), w*o.R_component_7(), sl@0: w*o.R_component_8())); sl@0: } sl@0: sl@0: sl@0: template sl@0: inline octonion tan(octonion const & o) sl@0: { sl@0: return(sin(o)/cos(o)); sl@0: } sl@0: sl@0: sl@0: template sl@0: inline octonion cosh(octonion const & o) sl@0: { sl@0: return((exp(+o)+exp(-o))/static_cast(2)); sl@0: } sl@0: sl@0: sl@0: template sl@0: inline octonion sinh(octonion const & o) sl@0: { sl@0: return((exp(+o)-exp(-o))/static_cast(2)); sl@0: } sl@0: sl@0: sl@0: template sl@0: inline octonion tanh(octonion const & o) sl@0: { sl@0: return(sinh(o)/cosh(o)); sl@0: } sl@0: sl@0: sl@0: template sl@0: octonion pow(octonion const & o, sl@0: int n) sl@0: { sl@0: if (n > 1) sl@0: { sl@0: int m = n>>1; sl@0: sl@0: octonion result = pow(o, m); sl@0: sl@0: result *= result; sl@0: sl@0: if (n != (m<<1)) sl@0: { sl@0: result *= o; // n odd sl@0: } sl@0: sl@0: return(result); sl@0: } sl@0: else if (n == 1) sl@0: { sl@0: return(o); sl@0: } sl@0: else if (n == 0) sl@0: { sl@0: return(octonion(1)); sl@0: } sl@0: else /* n < 0 */ sl@0: { sl@0: return(pow(octonion(1)/o,-n)); sl@0: } sl@0: } sl@0: sl@0: sl@0: // helper templates for converting copy constructors (definition) sl@0: sl@0: namespace detail sl@0: { sl@0: sl@0: template< typename T, sl@0: typename U sl@0: > sl@0: octonion octonion_type_converter(octonion const & rhs) sl@0: { sl@0: return(octonion( static_cast(rhs.R_component_1()), sl@0: static_cast(rhs.R_component_2()), sl@0: static_cast(rhs.R_component_3()), sl@0: static_cast(rhs.R_component_4()), sl@0: static_cast(rhs.R_component_5()), sl@0: static_cast(rhs.R_component_6()), sl@0: static_cast(rhs.R_component_7()), sl@0: static_cast(rhs.R_component_8()))); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: #if BOOST_WORKAROUND(__GNUC__, < 3) sl@0: #undef BOOST_GET_VALARRAY sl@0: #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ sl@0: sl@0: sl@0: #endif /* BOOST_OCTONION_HPP */