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