1 // boost octonion.hpp header file
3 // (C) Copyright Hubert Holin 2001.
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // See http://www.boost.org for updates, documentation, and revision history.
11 #ifndef BOOST_OCTONION_HPP
12 #define BOOST_OCTONION_HPP
14 #include <boost/math/quaternion.hpp>
22 #define BOOST_OCTONION_ACCESSOR_GENERATOR(type) \
28 octonion<type> unreal() const \
30 return( octonion<type>(static_cast<type>(0),b,c,d,e,f,g,h)); \
33 type R_component_1() const \
38 type R_component_2() const \
43 type R_component_3() const \
48 type R_component_4() const \
53 type R_component_5() const \
58 type R_component_6() const \
63 type R_component_7() const \
68 type R_component_8() const \
73 ::std::complex<type> C_component_1() const \
75 return(::std::complex<type>(a,b)); \
78 ::std::complex<type> C_component_2() const \
80 return(::std::complex<type>(c,d)); \
83 ::std::complex<type> C_component_3() const \
85 return(::std::complex<type>(e,f)); \
88 ::std::complex<type> C_component_4() const \
90 return(::std::complex<type>(g,h)); \
93 ::boost::math::quaternion<type> H_component_1() const \
95 return(::boost::math::quaternion<type>(a,b,c,d)); \
98 ::boost::math::quaternion<type> H_component_2() const \
100 return(::boost::math::quaternion<type>(e,f,g,h)); \
104 #define BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(type) \
105 template<typename X> \
106 octonion<type> & operator = (octonion<X> const & a_affecter) \
108 a = static_cast<type>(a_affecter.R_component_1()); \
109 b = static_cast<type>(a_affecter.R_component_2()); \
110 c = static_cast<type>(a_affecter.R_component_3()); \
111 d = static_cast<type>(a_affecter.R_component_4()); \
112 e = static_cast<type>(a_affecter.R_component_5()); \
113 f = static_cast<type>(a_affecter.R_component_6()); \
114 g = static_cast<type>(a_affecter.R_component_7()); \
115 h = static_cast<type>(a_affecter.R_component_8()); \
120 octonion<type> & operator = (octonion<type> const & a_affecter) \
134 octonion<type> & operator = (type const & a_affecter) \
138 b = c = d = e = f= g = h = static_cast<type>(0); \
143 octonion<type> & operator = (::std::complex<type> const & a_affecter) \
145 a = a_affecter.real(); \
146 b = a_affecter.imag(); \
148 c = d = e = f = g = h = static_cast<type>(0); \
153 octonion<type> & operator = (::boost::math::quaternion<type> const & a_affecter) \
155 a = a_affecter.R_component_1(); \
156 b = a_affecter.R_component_2(); \
157 c = a_affecter.R_component_3(); \
158 d = a_affecter.R_component_4(); \
160 e = f = g = h = static_cast<type>(0); \
166 #define BOOST_OCTONION_MEMBER_DATA_GENERATOR(type) \
182 typedef T value_type;
184 // constructor for O seen as R^8
185 // (also default constructor)
187 explicit octonion( T const & requested_a = T(),
188 T const & requested_b = T(),
189 T const & requested_c = T(),
190 T const & requested_d = T(),
191 T const & requested_e = T(),
192 T const & requested_f = T(),
193 T const & requested_g = T(),
194 T const & requested_h = T())
208 // constructor for H seen as C^4
210 explicit octonion( ::std::complex<T> const & z0,
211 ::std::complex<T> const & z1 = ::std::complex<T>(),
212 ::std::complex<T> const & z2 = ::std::complex<T>(),
213 ::std::complex<T> const & z3 = ::std::complex<T>())
227 // constructor for O seen as H^2
229 explicit octonion( ::boost::math::quaternion<T> const & q0,
230 ::boost::math::quaternion<T> const & q1 = ::boost::math::quaternion<T>())
231 : a(q0.R_component_1()),
232 b(q0.R_component_2()),
233 c(q0.R_component_3()),
234 d(q0.R_component_4()),
235 e(q1.R_component_1()),
236 f(q1.R_component_2()),
237 g(q1.R_component_3()),
238 h(q1.R_component_4())
244 // UNtemplated copy constructor
245 // (this is taken care of by the compiler itself)
248 // templated copy constructor
251 explicit octonion(octonion<X> const & a_recopier)
252 : a(static_cast<T>(a_recopier.R_component_1())),
253 b(static_cast<T>(a_recopier.R_component_2())),
254 c(static_cast<T>(a_recopier.R_component_3())),
255 d(static_cast<T>(a_recopier.R_component_4())),
256 e(static_cast<T>(a_recopier.R_component_5())),
257 f(static_cast<T>(a_recopier.R_component_6())),
258 g(static_cast<T>(a_recopier.R_component_7())),
259 h(static_cast<T>(a_recopier.R_component_8()))
266 // (this is taken care of by the compiler itself)
271 // Note: Like complex number, octonions do have a meaningful notion of "real part",
272 // but unlike them there is no meaningful notion of "imaginary part".
273 // Instead there is an "unreal part" which itself is an octonion, and usually
274 // nothing simpler (as opposed to the complex number case).
275 // However, for practicallity, there are accessors for the other components
276 // (these are necessary for the templated copy constructor, for instance).
278 BOOST_OCTONION_ACCESSOR_GENERATOR(T)
280 // assignment operators
282 BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(T)
284 // other assignment-related operators
286 // NOTE: Octonion multiplication is *NOT* commutative;
287 // symbolically, "q *= rhs;" means "q = q * rhs;"
288 // and "q /= rhs;" means "q = q * inverse_of(rhs);";
289 // octonion multiplication is also *NOT* associative
291 octonion<T> & operator += (T const & rhs)
293 T at = a + rhs; // exception guard
301 octonion<T> & operator += (::std::complex<T> const & rhs)
303 T at = a + rhs.real(); // exception guard
304 T bt = b + rhs.imag(); // exception guard
313 octonion<T> & operator += (::boost::math::quaternion<T> const & rhs)
315 T at = a + rhs.R_component_1(); // exception guard
316 T bt = b + rhs.R_component_2(); // exception guard
317 T ct = c + rhs.R_component_3(); // exception guard
318 T dt = d + rhs.R_component_4(); // exception guard
330 octonion<T> & operator += (octonion<X> const & rhs)
332 T at = a + static_cast<T>(rhs.R_component_1()); // exception guard
333 T bt = b + static_cast<T>(rhs.R_component_2()); // exception guard
334 T ct = c + static_cast<T>(rhs.R_component_3()); // exception guard
335 T dt = d + static_cast<T>(rhs.R_component_4()); // exception guard
336 T et = e + static_cast<T>(rhs.R_component_5()); // exception guard
337 T ft = f + static_cast<T>(rhs.R_component_6()); // exception guard
338 T gt = g + static_cast<T>(rhs.R_component_7()); // exception guard
339 T ht = h + static_cast<T>(rhs.R_component_8()); // exception guard
355 octonion<T> & operator -= (T const & rhs)
357 T at = a - rhs; // exception guard
365 octonion<T> & operator -= (::std::complex<T> const & rhs)
367 T at = a - rhs.real(); // exception guard
368 T bt = b - rhs.imag(); // exception guard
377 octonion<T> & operator -= (::boost::math::quaternion<T> const & rhs)
379 T at = a - rhs.R_component_1(); // exception guard
380 T bt = b - rhs.R_component_2(); // exception guard
381 T ct = c - rhs.R_component_3(); // exception guard
382 T dt = d - rhs.R_component_4(); // exception guard
394 octonion<T> & operator -= (octonion<X> const & rhs)
396 T at = a - static_cast<T>(rhs.R_component_1()); // exception guard
397 T bt = b - static_cast<T>(rhs.R_component_2()); // exception guard
398 T ct = c - static_cast<T>(rhs.R_component_3()); // exception guard
399 T dt = d - static_cast<T>(rhs.R_component_4()); // exception guard
400 T et = e - static_cast<T>(rhs.R_component_5()); // exception guard
401 T ft = f - static_cast<T>(rhs.R_component_6()); // exception guard
402 T gt = g - static_cast<T>(rhs.R_component_7()); // exception guard
403 T ht = h - static_cast<T>(rhs.R_component_8()); // exception guard
418 octonion<T> & operator *= (T const & rhs)
420 T at = a * rhs; // exception guard
421 T bt = b * rhs; // exception guard
422 T ct = c * rhs; // exception guard
423 T dt = d * rhs; // exception guard
424 T et = e * rhs; // exception guard
425 T ft = f * rhs; // exception guard
426 T gt = g * rhs; // exception guard
427 T ht = h * rhs; // exception guard
442 octonion<T> & operator *= (::std::complex<T> const & rhs)
469 octonion<T> & operator *= (::boost::math::quaternion<T> const & rhs)
471 T ar = rhs.R_component_1();
472 T br = rhs.R_component_2();
473 T cr = rhs.R_component_2();
474 T dr = rhs.R_component_2();
476 T at = +a*ar-b*br-c*cr-d*dr;
477 T bt = +a*br+b*ar+c*dr-d*cr;
478 T ct = +a*cr-b*dr+c*ar+d*br;
479 T dt = +a*dr+b*cr-c*br+d*ar;
480 T et = +e*ar+f*br+g*cr+h*dr;
481 T ft = -e*br+f*ar-g*dr+h*cr;
482 T gt = -e*cr+f*dr+g*ar-h*br;
483 T ht = -e*dr-f*cr+g*br+h*ar;
499 octonion<T> & operator *= (octonion<X> const & rhs)
501 T ar = static_cast<T>(rhs.R_component_1());
502 T br = static_cast<T>(rhs.R_component_2());
503 T cr = static_cast<T>(rhs.R_component_3());
504 T dr = static_cast<T>(rhs.R_component_4());
505 T er = static_cast<T>(rhs.R_component_5());
506 T fr = static_cast<T>(rhs.R_component_6());
507 T gr = static_cast<T>(rhs.R_component_7());
508 T hr = static_cast<T>(rhs.R_component_8());
510 T at = +a*ar-b*br-c*cr-d*dr-e*er-f*fr-g*gr-h*hr;
511 T bt = +a*br+b*ar+c*dr-d*cr+e*fr-f*er-g*hr+h*gr;
512 T ct = +a*cr-b*dr+c*ar+d*br+e*gr+f*hr-g*er-h*fr;
513 T dt = +a*dr+b*cr-c*br+d*ar+e*hr-f*gr+g*fr-h*er;
514 T et = +a*er-b*fr-c*gr-d*hr+e*ar+f*br+g*cr+h*dr;
515 T ft = +a*fr+b*er-c*hr+d*gr-e*br+f*ar-g*dr+h*cr;
516 T gt = +a*gr+b*hr+c*er-d*fr-e*cr+f*dr+g*ar-h*br;
517 T ht = +a*hr-b*gr+c*fr+d*er-e*dr-f*cr+g*br+h*ar;
532 octonion<T> & operator /= (T const & rhs)
534 T at = a / rhs; // exception guard
535 T bt = b / rhs; // exception guard
536 T ct = c / rhs; // exception guard
537 T dt = d / rhs; // exception guard
538 T et = e / rhs; // exception guard
539 T ft = f / rhs; // exception guard
540 T gt = g / rhs; // exception guard
541 T ht = h / rhs; // exception guard
556 octonion<T> & operator /= (::std::complex<T> const & rhs)
561 T denominator = ar*ar+br*br;
563 T at = (+a*ar-b*br)/denominator;
564 T bt = (-a*br+b*ar)/denominator;
565 T ct = (+c*ar-d*br)/denominator;
566 T dt = (+c*br+d*ar)/denominator;
567 T et = (+e*ar-f*br)/denominator;
568 T ft = (+e*br+f*ar)/denominator;
569 T gt = (+g*ar+h*br)/denominator;
570 T ht = (+g*br+h*ar)/denominator;
585 octonion<T> & operator /= (::boost::math::quaternion<T> const & rhs)
587 T ar = rhs.R_component_1();
588 T br = rhs.R_component_2();
589 T cr = rhs.R_component_2();
590 T dr = rhs.R_component_2();
592 T denominator = ar*ar+br*br+cr*cr+dr*dr;
594 T at = (+a*ar+b*br+c*cr+d*dr)/denominator;
595 T bt = (-a*br+b*ar-c*dr+d*cr)/denominator;
596 T ct = (-a*cr+b*dr+c*ar-d*br)/denominator;
597 T dt = (-a*dr-b*cr+c*br+d*ar)/denominator;
598 T et = (+e*ar-f*br-g*cr-h*dr)/denominator;
599 T ft = (+e*br+f*ar+g*dr-h*cr)/denominator;
600 T gt = (+e*cr-f*dr+g*ar+h*br)/denominator;
601 T ht = (+e*dr+f*cr-g*br+h*ar)/denominator;
617 octonion<T> & operator /= (octonion<X> const & rhs)
619 T ar = static_cast<T>(rhs.R_component_1());
620 T br = static_cast<T>(rhs.R_component_2());
621 T cr = static_cast<T>(rhs.R_component_3());
622 T dr = static_cast<T>(rhs.R_component_4());
623 T er = static_cast<T>(rhs.R_component_5());
624 T fr = static_cast<T>(rhs.R_component_6());
625 T gr = static_cast<T>(rhs.R_component_7());
626 T hr = static_cast<T>(rhs.R_component_8());
628 T denominator = ar*ar+br*br+cr*cr+dr*dr+er*er+fr*fr+gr*gr+hr*hr;
630 T at = (+a*ar+b*br+c*cr+d*dr+e*er+f*fr+g*gr+h*hr)/denominator;
631 T bt = (-a*br+b*ar-c*dr+d*cr-e*fr+f*er+g*hr-h*gr)/denominator;
632 T ct = (-a*cr+b*dr+c*ar-d*br-e*gr-f*hr+g*er+h*fr)/denominator;
633 T dt = (-a*dr-b*cr+c*br+d*ar-e*hr+f*gr-g*fr+h*er)/denominator;
634 T et = (-a*er+b*fr+c*gr+d*hr+e*ar-f*br-g*cr-h*dr)/denominator;
635 T ft = (-a*fr-b*er+c*hr-d*gr+e*br+f*ar+g*dr-h*cr)/denominator;
636 T gt = (-a*gr-b*hr-c*er+d*fr+e*cr-f*dr+g*ar+h*br)/denominator;
637 T ht = (-a*hr+b*gr-c*fr-d*er+e*dr+f*cr-g*br+h*ar)/denominator;
654 BOOST_OCTONION_MEMBER_DATA_GENERATOR(T)
662 // declaration of octonion specialization
664 template<> class octonion<float>;
665 template<> class octonion<double>;
666 template<> class octonion<long double>;
669 // helper templates for converting copy constructors (declaration)
674 template< typename T,
677 octonion<T> octonion_type_converter(octonion<U> const & rhs);
681 // implementation of octonion specialization
684 #define BOOST_OCTONION_CONSTRUCTOR_GENERATOR(type) \
685 explicit octonion( type const & requested_a = static_cast<type>(0), \
686 type const & requested_b = static_cast<type>(0), \
687 type const & requested_c = static_cast<type>(0), \
688 type const & requested_d = static_cast<type>(0), \
689 type const & requested_e = static_cast<type>(0), \
690 type const & requested_f = static_cast<type>(0), \
691 type const & requested_g = static_cast<type>(0), \
692 type const & requested_h = static_cast<type>(0)) \
704 explicit octonion( ::std::complex<type> const & z0, \
705 ::std::complex<type> const & z1 = ::std::complex<type>(), \
706 ::std::complex<type> const & z2 = ::std::complex<type>(), \
707 ::std::complex<type> const & z3 = ::std::complex<type>()) \
719 explicit octonion( ::boost::math::quaternion<type> const & q0, \
720 ::boost::math::quaternion<type> const & q1 = ::boost::math::quaternion<type>()) \
721 : a(q0.R_component_1()), \
722 b(q0.R_component_2()), \
723 c(q0.R_component_3()), \
724 d(q0.R_component_4()), \
725 e(q1.R_component_1()), \
726 f(q1.R_component_2()), \
727 g(q1.R_component_3()), \
728 h(q1.R_component_4()) \
733 #define BOOST_OCTONION_MEMBER_ADD_GENERATOR_1(type) \
734 octonion<type> & operator += (type const & rhs) \
741 #define BOOST_OCTONION_MEMBER_ADD_GENERATOR_2(type) \
742 octonion<type> & operator += (::std::complex<type> const & rhs) \
750 #define BOOST_OCTONION_MEMBER_ADD_GENERATOR_3(type) \
751 octonion<type> & operator += (::boost::math::quaternion<type> const & rhs) \
753 a += rhs.R_component_1(); \
754 b += rhs.R_component_2(); \
755 c += rhs.R_component_3(); \
756 d += rhs.R_component_4(); \
761 #define BOOST_OCTONION_MEMBER_ADD_GENERATOR_4(type) \
762 template<typename X> \
763 octonion<type> & operator += (octonion<X> const & rhs) \
765 a += static_cast<type>(rhs.R_component_1()); \
766 b += static_cast<type>(rhs.R_component_2()); \
767 c += static_cast<type>(rhs.R_component_3()); \
768 d += static_cast<type>(rhs.R_component_4()); \
769 e += static_cast<type>(rhs.R_component_5()); \
770 f += static_cast<type>(rhs.R_component_6()); \
771 g += static_cast<type>(rhs.R_component_7()); \
772 h += static_cast<type>(rhs.R_component_8()); \
777 #define BOOST_OCTONION_MEMBER_SUB_GENERATOR_1(type) \
778 octonion<type> & operator -= (type const & rhs) \
785 #define BOOST_OCTONION_MEMBER_SUB_GENERATOR_2(type) \
786 octonion<type> & operator -= (::std::complex<type> const & rhs) \
794 #define BOOST_OCTONION_MEMBER_SUB_GENERATOR_3(type) \
795 octonion<type> & operator -= (::boost::math::quaternion<type> const & rhs) \
797 a -= rhs.R_component_1(); \
798 b -= rhs.R_component_2(); \
799 c -= rhs.R_component_3(); \
800 d -= rhs.R_component_4(); \
805 #define BOOST_OCTONION_MEMBER_SUB_GENERATOR_4(type) \
806 template<typename X> \
807 octonion<type> & operator -= (octonion<X> const & rhs) \
809 a -= static_cast<type>(rhs.R_component_1()); \
810 b -= static_cast<type>(rhs.R_component_2()); \
811 c -= static_cast<type>(rhs.R_component_3()); \
812 d -= static_cast<type>(rhs.R_component_4()); \
813 e -= static_cast<type>(rhs.R_component_5()); \
814 f -= static_cast<type>(rhs.R_component_6()); \
815 g -= static_cast<type>(rhs.R_component_7()); \
816 h -= static_cast<type>(rhs.R_component_8()); \
821 #define BOOST_OCTONION_MEMBER_MUL_GENERATOR_1(type) \
822 octonion<type> & operator *= (type const & rhs) \
836 #define BOOST_OCTONION_MEMBER_MUL_GENERATOR_2(type) \
837 octonion<type> & operator *= (::std::complex<type> const & rhs) \
839 type ar = rhs.real(); \
840 type br = rhs.imag(); \
842 type at = +a*ar-b*br; \
843 type bt = +a*br+b*ar; \
844 type ct = +c*ar+d*br; \
845 type dt = -c*br+d*ar; \
846 type et = +e*ar+f*br; \
847 type ft = -e*br+f*ar; \
848 type gt = +g*ar-h*br; \
849 type ht = +g*br+h*ar; \
863 #define BOOST_OCTONION_MEMBER_MUL_GENERATOR_3(type) \
864 octonion<type> & operator *= (::boost::math::quaternion<type> const & rhs) \
866 type ar = rhs.R_component_1(); \
867 type br = rhs.R_component_2(); \
868 type cr = rhs.R_component_2(); \
869 type dr = rhs.R_component_2(); \
871 type at = +a*ar-b*br-c*cr-d*dr; \
872 type bt = +a*br+b*ar+c*dr-d*cr; \
873 type ct = +a*cr-b*dr+c*ar+d*br; \
874 type dt = +a*dr+b*cr-c*br+d*ar; \
875 type et = +e*ar+f*br+g*cr+h*dr; \
876 type ft = -e*br+f*ar-g*dr+h*cr; \
877 type gt = -e*cr+f*dr+g*ar-h*br; \
878 type ht = -e*dr-f*cr+g*br+h*ar; \
892 #define BOOST_OCTONION_MEMBER_MUL_GENERATOR_4(type) \
893 template<typename X> \
894 octonion<type> & operator *= (octonion<X> const & rhs) \
896 type ar = static_cast<type>(rhs.R_component_1()); \
897 type br = static_cast<type>(rhs.R_component_2()); \
898 type cr = static_cast<type>(rhs.R_component_3()); \
899 type dr = static_cast<type>(rhs.R_component_4()); \
900 type er = static_cast<type>(rhs.R_component_5()); \
901 type fr = static_cast<type>(rhs.R_component_6()); \
902 type gr = static_cast<type>(rhs.R_component_7()); \
903 type hr = static_cast<type>(rhs.R_component_8()); \
905 type at = +a*ar-b*br-c*cr-d*dr-e*er-f*fr-g*gr-h*hr; \
906 type bt = +a*br+b*ar+c*dr-d*cr+e*fr-f*er-g*hr+h*gr; \
907 type ct = +a*cr-b*dr+c*ar+d*br+e*gr+f*hr-g*er-h*fr; \
908 type dt = +a*dr+b*cr-c*br+d*ar+e*hr-f*gr+g*fr-h*er; \
909 type et = +a*er-b*fr-c*gr-d*hr+e*ar+f*br+g*cr+h*dr; \
910 type ft = +a*fr+b*er-c*hr+d*gr-e*br+f*ar-g*dr+h*cr; \
911 type gt = +a*gr+b*hr+c*er-d*fr-e*cr+f*dr+g*ar-h*br; \
912 type ht = +a*hr-b*gr+c*fr+d*er-e*dr-f*cr+g*br+h*ar; \
926 // There is quite a lot of repetition in the code below. This is intentional.
927 // The last conditional block is the normal form, and the others merely
928 // consist of workarounds for various compiler deficiencies. Hopefuly, when
929 // more compilers are conformant and we can retire support for those that are
930 // not, we will be able to remove the clutter. This is makes the situation
931 // (painfully) explicit.
933 #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_1(type) \
934 octonion<type> & operator /= (type const & rhs) \
944 #if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
945 #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_2(type) \
946 octonion<type> & operator /= (::std::complex<type> const & rhs) \
948 using ::std::valarray; \
951 valarray<type> tr(2); \
953 tr[0] = rhs.real(); \
954 tr[1] = rhs.imag(); \
956 type mixam = static_cast<type>(1)/(abs(tr).max)(); \
960 valarray<type> tt(8); \
962 tt[0] = +a*tr[0]-b*tr[1]; \
963 tt[1] = -a*tr[1]+b*tr[0]; \
964 tt[2] = +c*tr[0]-d*tr[1]; \
965 tt[3] = +c*tr[1]+d*tr[0]; \
966 tt[4] = +e*tr[0]-f*tr[1]; \
967 tt[5] = +e*tr[1]+f*tr[0]; \
968 tt[6] = +g*tr[0]+h*tr[1]; \
969 tt[7] = +g*tr[1]+h*tr[0]; \
973 tt *= (mixam/tr.sum()); \
987 #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_2(type) \
988 octonion<type> & operator /= (::std::complex<type> const & rhs) \
990 using ::std::valarray; \
992 valarray<type> tr(2); \
994 tr[0] = rhs.real(); \
995 tr[1] = rhs.imag(); \
997 type mixam = static_cast<type>(1)/(abs(tr).max)(); \
1001 valarray<type> tt(8); \
1003 tt[0] = +a*tr[0]-b*tr[1]; \
1004 tt[1] = -a*tr[1]+b*tr[0]; \
1005 tt[2] = +c*tr[0]-d*tr[1]; \
1006 tt[3] = +c*tr[1]+d*tr[0]; \
1007 tt[4] = +e*tr[0]-f*tr[1]; \
1008 tt[5] = +e*tr[1]+f*tr[0]; \
1009 tt[6] = +g*tr[0]+h*tr[1]; \
1010 tt[7] = +g*tr[1]+h*tr[0]; \
1014 tt *= (mixam/tr.sum()); \
1027 #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */
1029 #if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
1030 #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_3(type) \
1031 octonion<type> & operator /= (::boost::math::quaternion<type> const & rhs) \
1033 using ::std::valarray; \
1036 valarray<type> tr(4); \
1038 tr[0] = static_cast<type>(rhs.R_component_1()); \
1039 tr[1] = static_cast<type>(rhs.R_component_2()); \
1040 tr[2] = static_cast<type>(rhs.R_component_3()); \
1041 tr[3] = static_cast<type>(rhs.R_component_4()); \
1043 type mixam = static_cast<type>(1)/(abs(tr).max)(); \
1047 valarray<type> tt(8); \
1049 tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]; \
1050 tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]; \
1051 tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]; \
1052 tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]; \
1053 tt[4] = +e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \
1054 tt[5] = +e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \
1055 tt[6] = +e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \
1056 tt[7] = +e*tr[3]+f*tr[2]-g*tr[1]+h*tr[0]; \
1060 tt *= (mixam/tr.sum()); \
1074 #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_3(type) \
1075 octonion<type> & operator /= (::boost::math::quaternion<type> const & rhs) \
1077 using ::std::valarray; \
1079 valarray<type> tr(4); \
1081 tr[0] = static_cast<type>(rhs.R_component_1()); \
1082 tr[1] = static_cast<type>(rhs.R_component_2()); \
1083 tr[2] = static_cast<type>(rhs.R_component_3()); \
1084 tr[3] = static_cast<type>(rhs.R_component_4()); \
1086 type mixam = static_cast<type>(1)/(abs(tr).max)(); \
1090 valarray<type> tt(8); \
1092 tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]; \
1093 tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]; \
1094 tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]; \
1095 tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]; \
1096 tt[4] = +e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \
1097 tt[5] = +e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \
1098 tt[6] = +e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \
1099 tt[7] = +e*tr[3]+f*tr[2]-g*tr[1]+h*tr[0]; \
1103 tt *= (mixam/tr.sum()); \
1116 #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */
1118 #if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
1119 #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_4(type) \
1120 template<typename X> \
1121 octonion<type> & operator /= (octonion<X> const & rhs) \
1123 using ::std::valarray; \
1126 valarray<type> tr(8); \
1128 tr[0] = static_cast<type>(rhs.R_component_1()); \
1129 tr[1] = static_cast<type>(rhs.R_component_2()); \
1130 tr[2] = static_cast<type>(rhs.R_component_3()); \
1131 tr[3] = static_cast<type>(rhs.R_component_4()); \
1132 tr[4] = static_cast<type>(rhs.R_component_5()); \
1133 tr[5] = static_cast<type>(rhs.R_component_6()); \
1134 tr[6] = static_cast<type>(rhs.R_component_7()); \
1135 tr[7] = static_cast<type>(rhs.R_component_8()); \
1137 type mixam = static_cast<type>(1)/(abs(tr).max)(); \
1141 valarray<type> tt(8); \
1143 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]; \
1144 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]; \
1145 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]; \
1146 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]; \
1147 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]; \
1148 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]; \
1149 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]; \
1150 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]; \
1154 tt *= (mixam/tr.sum()); \
1168 #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_4(type) \
1169 template<typename X> \
1170 octonion<type> & operator /= (octonion<X> const & rhs) \
1172 using ::std::valarray; \
1174 valarray<type> tr(8); \
1176 tr[0] = static_cast<type>(rhs.R_component_1()); \
1177 tr[1] = static_cast<type>(rhs.R_component_2()); \
1178 tr[2] = static_cast<type>(rhs.R_component_3()); \
1179 tr[3] = static_cast<type>(rhs.R_component_4()); \
1180 tr[4] = static_cast<type>(rhs.R_component_5()); \
1181 tr[5] = static_cast<type>(rhs.R_component_6()); \
1182 tr[6] = static_cast<type>(rhs.R_component_7()); \
1183 tr[7] = static_cast<type>(rhs.R_component_8()); \
1185 type mixam = static_cast<type>(1)/(abs(tr).max)(); \
1189 valarray<type> tt(8); \
1191 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]; \
1192 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]; \
1193 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]; \
1194 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]; \
1195 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]; \
1196 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]; \
1197 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]; \
1198 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]; \
1202 tt *= (mixam/tr.sum()); \
1215 #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */
1218 #define BOOST_OCTONION_MEMBER_ADD_GENERATOR(type) \
1219 BOOST_OCTONION_MEMBER_ADD_GENERATOR_1(type) \
1220 BOOST_OCTONION_MEMBER_ADD_GENERATOR_2(type) \
1221 BOOST_OCTONION_MEMBER_ADD_GENERATOR_3(type) \
1222 BOOST_OCTONION_MEMBER_ADD_GENERATOR_4(type)
1224 #define BOOST_OCTONION_MEMBER_SUB_GENERATOR(type) \
1225 BOOST_OCTONION_MEMBER_SUB_GENERATOR_1(type) \
1226 BOOST_OCTONION_MEMBER_SUB_GENERATOR_2(type) \
1227 BOOST_OCTONION_MEMBER_SUB_GENERATOR_3(type) \
1228 BOOST_OCTONION_MEMBER_SUB_GENERATOR_4(type)
1230 #define BOOST_OCTONION_MEMBER_MUL_GENERATOR(type) \
1231 BOOST_OCTONION_MEMBER_MUL_GENERATOR_1(type) \
1232 BOOST_OCTONION_MEMBER_MUL_GENERATOR_2(type) \
1233 BOOST_OCTONION_MEMBER_MUL_GENERATOR_3(type) \
1234 BOOST_OCTONION_MEMBER_MUL_GENERATOR_4(type)
1236 #define BOOST_OCTONION_MEMBER_DIV_GENERATOR(type) \
1237 BOOST_OCTONION_MEMBER_DIV_GENERATOR_1(type) \
1238 BOOST_OCTONION_MEMBER_DIV_GENERATOR_2(type) \
1239 BOOST_OCTONION_MEMBER_DIV_GENERATOR_3(type) \
1240 BOOST_OCTONION_MEMBER_DIV_GENERATOR_4(type)
1242 #define BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR(type) \
1243 BOOST_OCTONION_MEMBER_ADD_GENERATOR(type) \
1244 BOOST_OCTONION_MEMBER_SUB_GENERATOR(type) \
1245 BOOST_OCTONION_MEMBER_MUL_GENERATOR(type) \
1246 BOOST_OCTONION_MEMBER_DIV_GENERATOR(type)
1250 class octonion<float>
1254 typedef float value_type;
1256 BOOST_OCTONION_CONSTRUCTOR_GENERATOR(float)
1258 // UNtemplated copy constructor
1259 // (this is taken care of by the compiler itself)
1261 // explicit copy constructors (precision-loosing converters)
1263 explicit octonion(octonion<double> const & a_recopier)
1265 *this = detail::octonion_type_converter<float, double>(a_recopier);
1268 explicit octonion(octonion<long double> const & a_recopier)
1270 *this = detail::octonion_type_converter<float, long double>(a_recopier);
1274 // (this is taken care of by the compiler itself)
1278 // Note: Like complex number, octonions do have a meaningful notion of "real part",
1279 // but unlike them there is no meaningful notion of "imaginary part".
1280 // Instead there is an "unreal part" which itself is an octonion, and usually
1281 // nothing simpler (as opposed to the complex number case).
1282 // However, for practicallity, there are accessors for the other components
1283 // (these are necessary for the templated copy constructor, for instance).
1285 BOOST_OCTONION_ACCESSOR_GENERATOR(float)
1287 // assignment operators
1289 BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(float)
1291 // other assignment-related operators
1293 // NOTE: Octonion multiplication is *NOT* commutative;
1294 // symbolically, "q *= rhs;" means "q = q * rhs;"
1295 // and "q /= rhs;" means "q = q * inverse_of(rhs);";
1296 // octonion multiplication is also *NOT* associative
1298 BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR(float)
1303 BOOST_OCTONION_MEMBER_DATA_GENERATOR(float)
1312 class octonion<double>
1316 typedef double value_type;
1318 BOOST_OCTONION_CONSTRUCTOR_GENERATOR(double)
1320 // UNtemplated copy constructor
1321 // (this is taken care of by the compiler itself)
1323 // converting copy constructor
1325 explicit octonion(octonion<float> const & a_recopier)
1327 *this = detail::octonion_type_converter<double, float>(a_recopier);
1330 // explicit copy constructors (precision-loosing converters)
1332 explicit octonion(octonion<long double> const & a_recopier)
1334 *this = detail::octonion_type_converter<double, long double>(a_recopier);
1338 // (this is taken care of by the compiler itself)
1342 // Note: Like complex number, octonions do have a meaningful notion of "real part",
1343 // but unlike them there is no meaningful notion of "imaginary part".
1344 // Instead there is an "unreal part" which itself is an octonion, and usually
1345 // nothing simpler (as opposed to the complex number case).
1346 // However, for practicallity, there are accessors for the other components
1347 // (these are necessary for the templated copy constructor, for instance).
1349 BOOST_OCTONION_ACCESSOR_GENERATOR(double)
1351 // assignment operators
1353 BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(double)
1355 // other assignment-related operators
1357 // NOTE: Octonion multiplication is *NOT* commutative;
1358 // symbolically, "q *= rhs;" means "q = q * rhs;"
1359 // and "q /= rhs;" means "q = q * inverse_of(rhs);";
1360 // octonion multiplication is also *NOT* associative
1362 BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR(double)
1367 BOOST_OCTONION_MEMBER_DATA_GENERATOR(double)
1376 class octonion<long double>
1380 typedef long double value_type;
1382 BOOST_OCTONION_CONSTRUCTOR_GENERATOR(long double)
1384 // UNtemplated copy constructor
1385 // (this is taken care of by the compiler itself)
1387 // converting copy constructor
1389 explicit octonion(octonion<float> const & a_recopier)
1391 *this = detail::octonion_type_converter<long double, float>(a_recopier);
1395 explicit octonion(octonion<double> const & a_recopier)
1397 *this = detail::octonion_type_converter<long double, double>(a_recopier);
1402 // (this is taken care of by the compiler itself)
1406 // Note: Like complex number, octonions do have a meaningful notion of "real part",
1407 // but unlike them there is no meaningful notion of "imaginary part".
1408 // Instead there is an "unreal part" which itself is an octonion, and usually
1409 // nothing simpler (as opposed to the complex number case).
1410 // However, for practicallity, there are accessors for the other components
1411 // (these are necessary for the templated copy constructor, for instance).
1413 BOOST_OCTONION_ACCESSOR_GENERATOR(long double)
1415 // assignment operators
1417 BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(long double)
1419 // other assignment-related operators
1421 // NOTE: Octonion multiplication is *NOT* commutative;
1422 // symbolically, "q *= rhs;" means "q = q * rhs;"
1423 // and "q /= rhs;" means "q = q * inverse_of(rhs);";
1424 // octonion multiplication is also *NOT* associative
1426 BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR(long double)
1431 BOOST_OCTONION_MEMBER_DATA_GENERATOR(long double)
1439 #undef BOOST_OCTONION_CONSTRUCTOR_GENERATOR
1441 #undef BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR
1443 #undef BOOST_OCTONION_MEMBER_ADD_GENERATOR
1444 #undef BOOST_OCTONION_MEMBER_SUB_GENERATOR
1445 #undef BOOST_OCTONION_MEMBER_MUL_GENERATOR
1446 #undef BOOST_OCTONION_MEMBER_DIV_GENERATOR
1448 #undef BOOST_OCTONION_MEMBER_ADD_GENERATOR_1
1449 #undef BOOST_OCTONION_MEMBER_ADD_GENERATOR_2
1450 #undef BOOST_OCTONION_MEMBER_ADD_GENERATOR_3
1451 #undef BOOST_OCTONION_MEMBER_ADD_GENERATOR_4
1452 #undef BOOST_OCTONION_MEMBER_SUB_GENERATOR_1
1453 #undef BOOST_OCTONION_MEMBER_SUB_GENERATOR_2
1454 #undef BOOST_OCTONION_MEMBER_SUB_GENERATOR_3
1455 #undef BOOST_OCTONION_MEMBER_SUB_GENERATOR_4
1456 #undef BOOST_OCTONION_MEMBER_MUL_GENERATOR_1
1457 #undef BOOST_OCTONION_MEMBER_MUL_GENERATOR_2
1458 #undef BOOST_OCTONION_MEMBER_MUL_GENERATOR_3
1459 #undef BOOST_OCTONION_MEMBER_MUL_GENERATOR_4
1460 #undef BOOST_OCTONION_MEMBER_DIV_GENERATOR_1
1461 #undef BOOST_OCTONION_MEMBER_DIV_GENERATOR_2
1462 #undef BOOST_OCTONION_MEMBER_DIV_GENERATOR_3
1463 #undef BOOST_OCTONION_MEMBER_DIV_GENERATOR_4
1466 #undef BOOST_OCTONION_MEMBER_DATA_GENERATOR
1468 #undef BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR
1470 #undef BOOST_OCTONION_ACCESSOR_GENERATOR
1475 #define BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op) \
1477 octonion<T> res(lhs); \
1482 #define BOOST_OCTONION_OPERATOR_GENERATOR_1_L(op) \
1483 template<typename T> \
1484 inline octonion<T> operator op (T const & lhs, octonion<T> const & rhs) \
1485 BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op)
1487 #define BOOST_OCTONION_OPERATOR_GENERATOR_1_R(op) \
1488 template<typename T> \
1489 inline octonion<T> operator op (octonion<T> const & lhs, T const & rhs) \
1490 BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op)
1492 #define BOOST_OCTONION_OPERATOR_GENERATOR_2_L(op) \
1493 template<typename T> \
1494 inline octonion<T> operator op (::std::complex<T> const & lhs, octonion<T> const & rhs) \
1495 BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op)
1497 #define BOOST_OCTONION_OPERATOR_GENERATOR_2_R(op) \
1498 template<typename T> \
1499 inline octonion<T> operator op (octonion<T> const & lhs, ::std::complex<T> const & rhs) \
1500 BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op)
1502 #define BOOST_OCTONION_OPERATOR_GENERATOR_3_L(op) \
1503 template<typename T> \
1504 inline octonion<T> operator op (::boost::math::quaternion<T> const & lhs, octonion<T> const & rhs) \
1505 BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op)
1507 #define BOOST_OCTONION_OPERATOR_GENERATOR_3_R(op) \
1508 template<typename T> \
1509 inline octonion<T> operator op (octonion<T> const & lhs, ::boost::math::quaternion<T> const & rhs) \
1510 BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op)
1512 #define BOOST_OCTONION_OPERATOR_GENERATOR_4(op) \
1513 template<typename T> \
1514 inline octonion<T> operator op (octonion<T> const & lhs, octonion<T> const & rhs) \
1515 BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op)
1517 #define BOOST_OCTONION_OPERATOR_GENERATOR(op) \
1518 BOOST_OCTONION_OPERATOR_GENERATOR_1_L(op) \
1519 BOOST_OCTONION_OPERATOR_GENERATOR_1_R(op) \
1520 BOOST_OCTONION_OPERATOR_GENERATOR_2_L(op) \
1521 BOOST_OCTONION_OPERATOR_GENERATOR_2_R(op) \
1522 BOOST_OCTONION_OPERATOR_GENERATOR_3_L(op) \
1523 BOOST_OCTONION_OPERATOR_GENERATOR_3_R(op) \
1524 BOOST_OCTONION_OPERATOR_GENERATOR_4(op)
1527 BOOST_OCTONION_OPERATOR_GENERATOR(+)
1528 BOOST_OCTONION_OPERATOR_GENERATOR(-)
1529 BOOST_OCTONION_OPERATOR_GENERATOR(*)
1530 BOOST_OCTONION_OPERATOR_GENERATOR(/)
1533 #undef BOOST_OCTONION_OPERATOR_GENERATOR
1535 #undef BOOST_OCTONION_OPERATOR_GENERATOR_1_L
1536 #undef BOOST_OCTONION_OPERATOR_GENERATOR_1_R
1537 #undef BOOST_OCTONION_OPERATOR_GENERATOR_2_L
1538 #undef BOOST_OCTONION_OPERATOR_GENERATOR_2_R
1539 #undef BOOST_OCTONION_OPERATOR_GENERATOR_3_L
1540 #undef BOOST_OCTONION_OPERATOR_GENERATOR_3_R
1541 #undef BOOST_OCTONION_OPERATOR_GENERATOR_4
1543 #undef BOOST_OCTONION_OPERATOR_GENERATOR_BODY
1546 template<typename T>
1547 inline octonion<T> operator + (octonion<T> const & o)
1553 template<typename T>
1554 inline octonion<T> operator - (octonion<T> const & o)
1556 return(octonion<T>(-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()));
1560 template<typename T>
1561 inline bool operator == (T const & lhs, octonion<T> const & rhs)
1564 (rhs.R_component_1() == lhs)&&
1565 (rhs.R_component_2() == static_cast<T>(0))&&
1566 (rhs.R_component_3() == static_cast<T>(0))&&
1567 (rhs.R_component_4() == static_cast<T>(0))&&
1568 (rhs.R_component_5() == static_cast<T>(0))&&
1569 (rhs.R_component_6() == static_cast<T>(0))&&
1570 (rhs.R_component_7() == static_cast<T>(0))&&
1571 (rhs.R_component_8() == static_cast<T>(0))
1576 template<typename T>
1577 inline bool operator == (octonion<T> const & lhs, T const & rhs)
1580 (lhs.R_component_1() == rhs)&&
1581 (lhs.R_component_2() == static_cast<T>(0))&&
1582 (lhs.R_component_3() == static_cast<T>(0))&&
1583 (lhs.R_component_4() == static_cast<T>(0))&&
1584 (lhs.R_component_5() == static_cast<T>(0))&&
1585 (lhs.R_component_6() == static_cast<T>(0))&&
1586 (lhs.R_component_7() == static_cast<T>(0))&&
1587 (lhs.R_component_8() == static_cast<T>(0))
1592 template<typename T>
1593 inline bool operator == (::std::complex<T> const & lhs, octonion<T> const & rhs)
1596 (rhs.R_component_1() == lhs.real())&&
1597 (rhs.R_component_2() == lhs.imag())&&
1598 (rhs.R_component_3() == static_cast<T>(0))&&
1599 (rhs.R_component_4() == static_cast<T>(0))&&
1600 (rhs.R_component_5() == static_cast<T>(0))&&
1601 (rhs.R_component_6() == static_cast<T>(0))&&
1602 (rhs.R_component_7() == static_cast<T>(0))&&
1603 (rhs.R_component_8() == static_cast<T>(0))
1608 template<typename T>
1609 inline bool operator == (octonion<T> const & lhs, ::std::complex<T> const & rhs)
1612 (lhs.R_component_1() == rhs.real())&&
1613 (lhs.R_component_2() == rhs.imag())&&
1614 (lhs.R_component_3() == static_cast<T>(0))&&
1615 (lhs.R_component_4() == static_cast<T>(0))&&
1616 (lhs.R_component_5() == static_cast<T>(0))&&
1617 (lhs.R_component_6() == static_cast<T>(0))&&
1618 (lhs.R_component_7() == static_cast<T>(0))&&
1619 (lhs.R_component_8() == static_cast<T>(0))
1624 template<typename T>
1625 inline bool operator == (::boost::math::quaternion<T> const & lhs, octonion<T> const & rhs)
1628 (rhs.R_component_1() == lhs.R_component_1())&&
1629 (rhs.R_component_2() == lhs.R_component_2())&&
1630 (rhs.R_component_3() == lhs.R_component_3())&&
1631 (rhs.R_component_4() == lhs.R_component_4())&&
1632 (rhs.R_component_5() == static_cast<T>(0))&&
1633 (rhs.R_component_6() == static_cast<T>(0))&&
1634 (rhs.R_component_7() == static_cast<T>(0))&&
1635 (rhs.R_component_8() == static_cast<T>(0))
1640 template<typename T>
1641 inline bool operator == (octonion<T> const & lhs, ::boost::math::quaternion<T> const & rhs)
1644 (lhs.R_component_1() == rhs.R_component_1())&&
1645 (lhs.R_component_2() == rhs.R_component_2())&&
1646 (lhs.R_component_3() == rhs.R_component_3())&&
1647 (lhs.R_component_4() == rhs.R_component_4())&&
1648 (lhs.R_component_5() == static_cast<T>(0))&&
1649 (lhs.R_component_6() == static_cast<T>(0))&&
1650 (lhs.R_component_7() == static_cast<T>(0))&&
1651 (lhs.R_component_8() == static_cast<T>(0))
1656 template<typename T>
1657 inline bool operator == (octonion<T> const & lhs, octonion<T> const & rhs)
1660 (rhs.R_component_1() == lhs.R_component_1())&&
1661 (rhs.R_component_2() == lhs.R_component_2())&&
1662 (rhs.R_component_3() == lhs.R_component_3())&&
1663 (rhs.R_component_4() == lhs.R_component_4())&&
1664 (rhs.R_component_5() == lhs.R_component_5())&&
1665 (rhs.R_component_6() == lhs.R_component_6())&&
1666 (rhs.R_component_7() == lhs.R_component_7())&&
1667 (rhs.R_component_8() == lhs.R_component_8())
1672 #define BOOST_OCTONION_NOT_EQUAL_GENERATOR \
1674 return(!(lhs == rhs)); \
1677 template<typename T>
1678 inline bool operator != (T const & lhs, octonion<T> const & rhs)
1679 BOOST_OCTONION_NOT_EQUAL_GENERATOR
1681 template<typename T>
1682 inline bool operator != (octonion<T> const & lhs, T const & rhs)
1683 BOOST_OCTONION_NOT_EQUAL_GENERATOR
1685 template<typename T>
1686 inline bool operator != (::std::complex<T> const & lhs, octonion<T> const & rhs)
1687 BOOST_OCTONION_NOT_EQUAL_GENERATOR
1689 template<typename T>
1690 inline bool operator != (octonion<T> const & lhs, ::std::complex<T> const & rhs)
1691 BOOST_OCTONION_NOT_EQUAL_GENERATOR
1693 template<typename T>
1694 inline bool operator != (::boost::math::quaternion<T> const & lhs, octonion<T> const & rhs)
1695 BOOST_OCTONION_NOT_EQUAL_GENERATOR
1697 template<typename T>
1698 inline bool operator != (octonion<T> const & lhs, ::boost::math::quaternion<T> const & rhs)
1699 BOOST_OCTONION_NOT_EQUAL_GENERATOR
1701 template<typename T>
1702 inline bool operator != (octonion<T> const & lhs, octonion<T> const & rhs)
1703 BOOST_OCTONION_NOT_EQUAL_GENERATOR
1705 #undef BOOST_OCTONION_NOT_EQUAL_GENERATOR
1708 // Note: the default values in the constructors of the complex and quaternions make for
1709 // a very complex and ambiguous situation; we have made choices to disambiguate.
1710 template<typename T, typename charT, class traits>
1711 ::std::basic_istream<charT,traits> & operator >> ( ::std::basic_istream<charT,traits> & is,
1714 #ifdef BOOST_NO_STD_LOCALE
1716 const ::std::ctype<charT> & ct = ::std::use_facet< ::std::ctype<charT> >(is.getloc());
1717 #endif /* BOOST_NO_STD_LOCALE */
1728 ::std::complex<T> u = ::std::complex<T>();
1729 ::std::complex<T> v = ::std::complex<T>();
1730 ::std::complex<T> x = ::std::complex<T>();
1731 ::std::complex<T> y = ::std::complex<T>();
1733 ::boost::math::quaternion<T> p = ::boost::math::quaternion<T>();
1734 ::boost::math::quaternion<T> q = ::boost::math::quaternion<T>();
1739 is >> ch; // get the first lexeme
1741 if (!is.good()) goto finish;
1743 #ifdef BOOST_NO_STD_LOCALE
1746 cc = ct.narrow(ch, char());
1747 #endif /* BOOST_NO_STD_LOCALE */
1749 if (cc == '(') // read "("
1751 is >> ch; // get the second lexeme
1753 if (!is.good()) goto finish;
1755 #ifdef BOOST_NO_STD_LOCALE
1758 cc = ct.narrow(ch, char());
1759 #endif /* BOOST_NO_STD_LOCALE */
1761 if (cc == '(') // read "(("
1763 is >> ch; // get the third lexeme
1765 if (!is.good()) goto finish;
1767 #ifdef BOOST_NO_STD_LOCALE
1770 cc = ct.narrow(ch, char());
1771 #endif /* BOOST_NO_STD_LOCALE */
1773 if (cc == '(') // read "((("
1777 is >> u; // read "((u"
1779 if (!is.good()) goto finish;
1781 is >> ch; // get the next lexeme
1783 if (!is.good()) goto finish;
1785 #ifdef BOOST_NO_STD_LOCALE
1788 cc = ct.narrow(ch, char());
1789 #endif /* BOOST_NO_STD_LOCALE */
1791 if (cc == ')') // read "((u)"
1793 is >> ch; // get the next lexeme
1795 if (!is.good()) goto finish;
1797 #ifdef BOOST_NO_STD_LOCALE
1800 cc = ct.narrow(ch, char());
1801 #endif /* BOOST_NO_STD_LOCALE */
1803 if (cc == ')') // format: (((a))), (((a,b)))
1807 else if (cc == ',') // read "((u),"
1809 p = ::boost::math::quaternion<T>(u);
1811 is >> q; // read "((u),q"
1813 if (!is.good()) goto finish;
1815 is >> ch; // get the next lexeme
1817 if (!is.good()) goto finish;
1819 #ifdef BOOST_NO_STD_LOCALE
1822 cc = ct.narrow(ch, char());
1823 #endif /* BOOST_NO_STD_LOCALE */
1825 if (cc == ')') // format: (((a)),q), (((a,b)),q)
1827 o = octonion<T>(p,q);
1831 is.setstate(::std::ios_base::failbit);
1836 is.setstate(::std::ios_base::failbit);
1839 else if (cc ==',') // read "((u,"
1841 is >> v; // read "((u,v"
1843 if (!is.good()) goto finish;
1845 is >> ch; // get the next lexeme
1847 if (!is.good()) goto finish;
1849 #ifdef BOOST_NO_STD_LOCALE
1852 cc = ct.narrow(ch, char());
1853 #endif /* BOOST_NO_STD_LOCALE */
1855 if (cc == ')') // read "((u,v)"
1857 p = ::boost::math::quaternion<T>(u,v);
1859 is >> ch; // get the next lexeme
1861 if (!is.good()) goto finish;
1863 #ifdef BOOST_NO_STD_LOCALE
1866 cc = ct.narrow(ch, char());
1867 #endif /* BOOST_NO_STD_LOCALE */
1869 if (cc == ')') // format: (((a),v)), (((a,b),v))
1873 else if (cc == ',') // read "((u,v),"
1875 is >> q; // read "(p,q"
1877 if (!is.good()) goto finish;
1879 is >> ch; // get the next lexeme
1881 if (!is.good()) goto finish;
1883 #ifdef BOOST_NO_STD_LOCALE
1886 cc = ct.narrow(ch, char());
1887 #endif /* BOOST_NO_STD_LOCALE */
1889 if (cc == ')') // format: (((a),v),q), (((a,b),v),q)
1891 o = octonion<T>(p,q);
1895 is.setstate(::std::ios_base::failbit);
1900 is.setstate(::std::ios_base::failbit);
1905 is.setstate(::std::ios_base::failbit);
1910 is.setstate(::std::ios_base::failbit);
1917 is >> a; // we extract the first component
1919 if (!is.good()) goto finish;
1921 is >> ch; // get the next lexeme
1923 if (!is.good()) goto finish;
1925 #ifdef BOOST_NO_STD_LOCALE
1928 cc = ct.narrow(ch, char());
1929 #endif /* BOOST_NO_STD_LOCALE */
1931 if (cc == ')') // read "((a)"
1933 is >> ch; // get the next lexeme
1935 if (!is.good()) goto finish;
1937 #ifdef BOOST_NO_STD_LOCALE
1940 cc = ct.narrow(ch, char());
1941 #endif /* BOOST_NO_STD_LOCALE */
1943 if (cc == ')') // read "((a))"
1947 else if (cc == ',') // read "((a),"
1949 is >> ch; // get the next lexeme
1951 if (!is.good()) goto finish;
1953 #ifdef BOOST_NO_STD_LOCALE
1956 cc = ct.narrow(ch, char());
1957 #endif /* BOOST_NO_STD_LOCALE */
1959 if (cc == '(') // read "((a),("
1961 is >> ch; // get the next lexeme
1963 if (!is.good()) goto finish;
1965 #ifdef BOOST_NO_STD_LOCALE
1968 cc = ct.narrow(ch, char());
1969 #endif /* BOOST_NO_STD_LOCALE */
1971 if (cc == '(') // read "((a),(("
1975 is.putback(ch); // we backtrack twice, with the same value!
1977 is >> q; // read "((a),q"
1979 if (!is.good()) goto finish;
1981 is >> ch; // get the next lexeme
1983 if (!is.good()) goto finish;
1985 #ifdef BOOST_NO_STD_LOCALE
1988 cc = ct.narrow(ch, char());
1989 #endif /* BOOST_NO_STD_LOCALE */
1991 if (cc == ')') // read "((a),q)"
1993 p = ::boost::math::quaternion<T>(a);
1995 o = octonion<T>(p,q);
1999 is.setstate(::std::ios_base::failbit);
2002 else // read "((a),(c" or "((a),(e"
2008 if (!is.good()) goto finish;
2010 is >> ch; // get the next lexeme
2012 if (!is.good()) goto finish;
2014 #ifdef BOOST_NO_STD_LOCALE
2017 cc = ct.narrow(ch, char());
2018 #endif /* BOOST_NO_STD_LOCALE */
2020 if (cc == ')') // read "((a),(c)" (ambiguity resolution)
2022 is >> ch; // get the next lexeme
2024 if (!is.good()) goto finish;
2026 #ifdef BOOST_NO_STD_LOCALE
2029 cc = ct.narrow(ch, char());
2030 #endif /* BOOST_NO_STD_LOCALE */
2032 if (cc == ')') // read "((a),(c))"
2034 o = octonion<T>(a,b,c);
2036 else if (cc == ',') // read "((a),(c),"
2038 u = ::std::complex<T>(a);
2040 v = ::std::complex<T>(c);
2042 is >> x; // read "((a),(c),x"
2044 if (!is.good()) goto finish;
2046 is >> ch; // get the next lexeme
2048 if (!is.good()) goto finish;
2050 #ifdef BOOST_NO_STD_LOCALE
2053 cc = ct.narrow(ch, char());
2054 #endif /* BOOST_NO_STD_LOCALE */
2056 if (cc == ')') // read "((a),(c),x)"
2058 o = octonion<T>(u,v,x);
2060 else if (cc == ',') // read "((a),(c),x,"
2062 is >> y; // read "((a),(c),x,y"
2064 if (!is.good()) goto finish;
2066 is >> ch; // get the next lexeme
2068 if (!is.good()) goto finish;
2070 #ifdef BOOST_NO_STD_LOCALE
2073 cc = ct.narrow(ch, char());
2074 #endif /* BOOST_NO_STD_LOCALE */
2076 if (cc == ')') // read "((a),(c),x,y)"
2078 o = octonion<T>(u,v,x,y);
2082 is.setstate(::std::ios_base::failbit);
2087 is.setstate(::std::ios_base::failbit);
2092 is.setstate(::std::ios_base::failbit);
2095 else if (cc == ',') // read "((a),(c," or "((a),(e,"
2097 is >> ch; // get the next lexeme
2099 if (!is.good()) goto finish;
2101 #ifdef BOOST_NO_STD_LOCALE
2104 cc = ct.narrow(ch, char());
2105 #endif /* BOOST_NO_STD_LOCALE */
2107 if (cc == '(') // read "((a),(e,(" (ambiguity resolution)
2109 p = ::boost::math::quaternion<T>(a);
2111 x = ::std::complex<T>(c); // "c" was actually "e"
2113 is.putback(ch); // we can only backtrace once
2115 is >> y; // read "((a),(e,y"
2117 if (!is.good()) goto finish;
2119 is >> ch; // get the next lexeme
2121 #ifdef BOOST_NO_STD_LOCALE
2124 cc = ct.narrow(ch, char());
2125 #endif /* BOOST_NO_STD_LOCALE */
2127 if (cc == ')') // read "((a),(e,y)"
2129 q = ::boost::math::quaternion<T>(x,y);
2131 is >> ch; // get the next lexeme
2133 #ifdef BOOST_NO_STD_LOCALE
2136 cc = ct.narrow(ch, char());
2137 #endif /* BOOST_NO_STD_LOCALE */
2139 if (cc == ')') // read "((a),(e,y))"
2141 o = octonion<T>(p,q);
2145 is.setstate(::std::ios_base::failbit);
2150 is.setstate(::std::ios_base::failbit);
2153 else // read "((a),(c,d" or "((a),(e,f"
2159 if (!is.good()) goto finish;
2161 is >> ch; // get the next lexeme
2163 if (!is.good()) goto finish;
2165 #ifdef BOOST_NO_STD_LOCALE
2168 cc = ct.narrow(ch, char());
2169 #endif /* BOOST_NO_STD_LOCALE */
2171 if (cc == ')') // read "((a),(c,d)" (ambiguity resolution)
2173 is >> ch; // get the next lexeme
2175 if (!is.good()) goto finish;
2177 #ifdef BOOST_NO_STD_LOCALE
2180 cc = ct.narrow(ch, char());
2181 #endif /* BOOST_NO_STD_LOCALE */
2183 if (cc == ')') // read "((a),(c,d))"
2185 o = octonion<T>(a,b,c,d);
2187 else if (cc == ',') // read "((a),(c,d),"
2189 u = ::std::complex<T>(a);
2191 v = ::std::complex<T>(c,d);
2193 is >> x; // read "((a),(c,d),x"
2195 if (!is.good()) goto finish;
2197 is >> ch; // get the next lexeme
2199 if (!is.good()) goto finish;
2201 #ifdef BOOST_NO_STD_LOCALE
2204 cc = ct.narrow(ch, char());
2205 #endif /* BOOST_NO_STD_LOCALE */
2207 if (cc == ')') // read "((a),(c,d),x)"
2209 o = octonion<T>(u,v,x);
2211 else if (cc == ',') // read "((a),(c,d),x,"
2213 is >> y; // read "((a),(c,d),x,y"
2215 if (!is.good()) goto finish;
2217 is >> ch; // get the next lexeme
2219 if (!is.good()) goto finish;
2221 #ifdef BOOST_NO_STD_LOCALE
2224 cc = ct.narrow(ch, char());
2225 #endif /* BOOST_NO_STD_LOCALE */
2227 if (cc == ')') // read "((a),(c,d),x,y)"
2229 o = octonion<T>(u,v,x,y);
2233 is.setstate(::std::ios_base::failbit);
2238 is.setstate(::std::ios_base::failbit);
2243 is.setstate(::std::ios_base::failbit);
2246 else if (cc == ',') // read "((a),(e,f," (ambiguity resolution)
2248 p = ::boost::math::quaternion<T>(a);
2250 is >> g; // read "((a),(e,f,g" (too late to backtrack)
2252 if (!is.good()) goto finish;
2254 is >> ch; // get the next lexeme
2256 if (!is.good()) goto finish;
2258 #ifdef BOOST_NO_STD_LOCALE
2261 cc = ct.narrow(ch, char());
2262 #endif /* BOOST_NO_STD_LOCALE */
2264 if (cc == ')') // read "((a),(e,f,g)"
2266 q = ::boost::math::quaternion<T>(c,d,g); // "c" was actually "e", and "d" was actually "f"
2268 is >> ch; // get the next lexeme
2270 if (!is.good()) goto finish;
2272 #ifdef BOOST_NO_STD_LOCALE
2275 cc = ct.narrow(ch, char());
2276 #endif /* BOOST_NO_STD_LOCALE */
2278 if (cc == ')') // read "((a),(e,f,g))"
2280 o = octonion<T>(p,q);
2284 is.setstate(::std::ios_base::failbit);
2287 else if (cc == ',') // read "((a),(e,f,g,"
2289 is >> h; // read "((a),(e,f,g,h"
2291 if (!is.good()) goto finish;
2293 is >> ch; // get the next lexeme
2295 if (!is.good()) goto finish;
2297 #ifdef BOOST_NO_STD_LOCALE
2300 cc = ct.narrow(ch, char());
2301 #endif /* BOOST_NO_STD_LOCALE */
2303 if (cc == ')') // read "((a),(e,f,g,h)"
2305 q = ::boost::math::quaternion<T>(c,d,g,h); // "c" was actually "e", and "d" was actually "f"
2307 is >> ch; // get the next lexeme
2309 if (!is.good()) goto finish;
2311 #ifdef BOOST_NO_STD_LOCALE
2314 cc = ct.narrow(ch, char());
2315 #endif /* BOOST_NO_STD_LOCALE */
2317 if (cc == ')') // read "((a),(e,f,g,h))"
2319 o = octonion<T>(p,q);
2323 is.setstate(::std::ios_base::failbit);
2328 is.setstate(::std::ios_base::failbit);
2333 is.setstate(::std::ios_base::failbit);
2338 is.setstate(::std::ios_base::failbit);
2344 is.setstate(::std::ios_base::failbit);
2348 else // read "((a),c" (ambiguity resolution)
2352 is >> c; // we extract the third component
2354 if (!is.good()) goto finish;
2356 is >> ch; // get the next lexeme
2358 if (!is.good()) goto finish;
2360 #ifdef BOOST_NO_STD_LOCALE
2363 cc = ct.narrow(ch, char());
2364 #endif /* BOOST_NO_STD_LOCALE */
2366 if (cc == ')') // read "((a),c)"
2368 o = octonion<T>(a,b,c);
2370 else if (cc == ',') // read "((a),c,"
2372 is >> x; // read "((a),c,x"
2374 if (!is.good()) goto finish;
2376 is >> ch; // get the next lexeme
2378 if (!is.good()) goto finish;
2380 #ifdef BOOST_NO_STD_LOCALE
2383 cc = ct.narrow(ch, char());
2384 #endif /* BOOST_NO_STD_LOCALE */
2386 if (cc == ')') // read "((a),c,x)"
2388 o = octonion<T>(a,b,c,d,x.real(),x.imag());
2390 else if (cc == ',') // read "((a),c,x,"
2392 is >> y;if (!is.good()) goto finish; // read "((a),c,x,y"
2394 is >> ch; // get the next lexeme
2396 if (!is.good()) goto finish;
2398 #ifdef BOOST_NO_STD_LOCALE
2401 cc = ct.narrow(ch, char());
2402 #endif /* BOOST_NO_STD_LOCALE */
2404 if (cc == ')') // read "((a),c,x,y)"
2406 o = octonion<T>(a,b,c,d,x.real(),x.imag(),y.real(),y.imag());
2410 is.setstate(::std::ios_base::failbit);
2415 is.setstate(::std::ios_base::failbit);
2420 is.setstate(::std::ios_base::failbit);
2426 is.setstate(::std::ios_base::failbit);
2429 else if (cc ==',') // read "((a,"
2431 is >> ch; // get the next lexeme
2433 if (!is.good()) goto finish;
2435 #ifdef BOOST_NO_STD_LOCALE
2438 cc = ct.narrow(ch, char());
2439 #endif /* BOOST_NO_STD_LOCALE */
2441 if (cc == '(') // read "((a,("
2443 u = ::std::complex<T>(a);
2445 is.putback(ch); // can only backtrack so much
2447 is >> v; // read "((a,v"
2449 if (!is.good()) goto finish;
2451 is >> ch; // get the next lexeme
2453 if (!is.good()) goto finish;
2455 #ifdef BOOST_NO_STD_LOCALE
2458 cc = ct.narrow(ch, char());
2459 #endif /* BOOST_NO_STD_LOCALE */
2461 if (cc == ')') // read "((a,v)"
2463 is >> ch; // get the next lexeme
2465 if (!is.good()) goto finish;
2467 #ifdef BOOST_NO_STD_LOCALE
2470 cc = ct.narrow(ch, char());
2471 #endif /* BOOST_NO_STD_LOCALE */
2473 if (cc == ')') // read "((a,v))"
2475 o = octonion<T>(u,v);
2477 else if (cc == ',') // read "((a,v),"
2479 p = ::boost::math::quaternion<T>(u,v);
2481 is >> q; // read "((a,v),q"
2483 if (!is.good()) goto finish;
2485 is >> ch; // get the next lexeme
2487 if (!is.good()) goto finish;
2489 #ifdef BOOST_NO_STD_LOCALE
2492 cc = ct.narrow(ch, char());
2493 #endif /* BOOST_NO_STD_LOCALE */
2495 if (cc == ')') // read "((a,v),q)"
2497 o = octonion<T>(p,q);
2501 is.setstate(::std::ios_base::failbit);
2506 is.setstate(::std::ios_base::failbit);
2511 is.setstate(::std::ios_base::failbit);
2518 is >> b; // read "((a,b"
2520 if (!is.good()) goto finish;
2522 is >> ch; // get the next lexeme
2524 if (!is.good()) goto finish;
2526 #ifdef BOOST_NO_STD_LOCALE
2529 cc = ct.narrow(ch, char());
2530 #endif /* BOOST_NO_STD_LOCALE */
2532 if (cc == ')') // read "((a,b)"
2534 is >> ch; // get the next lexeme
2536 if (!is.good()) goto finish;
2538 #ifdef BOOST_NO_STD_LOCALE
2541 cc = ct.narrow(ch, char());
2542 #endif /* BOOST_NO_STD_LOCALE */
2544 if (cc == ')') // read "((a,b))"
2546 o = octonion<T>(a,b);
2548 else if (cc == ',') // read "((a,b),"
2550 is >> ch; // get the next lexeme
2552 if (!is.good()) goto finish;
2554 #ifdef BOOST_NO_STD_LOCALE
2557 cc = ct.narrow(ch, char());
2558 #endif /* BOOST_NO_STD_LOCALE */
2560 if (cc == '(') // read "((a,b),("
2562 is >> ch; // get the next lexeme
2564 if (!is.good()) goto finish;
2566 #ifdef BOOST_NO_STD_LOCALE
2569 cc = ct.narrow(ch, char());
2570 #endif /* BOOST_NO_STD_LOCALE */
2572 if (cc == '(') // read "((a,b),(("
2574 p = ::boost::math::quaternion<T>(a,b);
2578 is.putback(ch); // we backtrack twice, with the same value
2580 is >> q; // read "((a,b),q"
2582 if (!is.good()) goto finish;
2584 is >> ch; // get the next lexeme
2586 if (!is.good()) goto finish;
2588 #ifdef BOOST_NO_STD_LOCALE
2591 cc = ct.narrow(ch, char());
2592 #endif /* BOOST_NO_STD_LOCALE */
2594 if (cc == ')') // read "((a,b),q)"
2596 o = octonion<T>(p,q);
2600 is.setstate(::std::ios_base::failbit);
2603 else // read "((a,b),(c" or "((a,b),(e"
2609 if (!is.good()) goto finish;
2611 is >> ch; // get the next lexeme
2613 if (!is.good()) goto finish;
2615 #ifdef BOOST_NO_STD_LOCALE
2618 cc = ct.narrow(ch, char());
2619 #endif /* BOOST_NO_STD_LOCALE */
2621 if (cc == ')') // read "((a,b),(c)" (ambiguity resolution)
2623 is >> ch; // get the next lexeme
2625 if (!is.good()) goto finish;
2627 #ifdef BOOST_NO_STD_LOCALE
2630 cc = ct.narrow(ch, char());
2631 #endif /* BOOST_NO_STD_LOCALE */
2633 if (cc == ')') // read "((a,b),(c))"
2635 o = octonion<T>(a,b,c);
2637 else if (cc == ',') // read "((a,b),(c),"
2639 u = ::std::complex<T>(a,b);
2641 v = ::std::complex<T>(c);
2643 is >> x; // read "((a,b),(c),x"
2645 if (!is.good()) goto finish;
2647 is >> ch; // get the next lexeme
2649 if (!is.good()) goto finish;
2651 #ifdef BOOST_NO_STD_LOCALE
2654 cc = ct.narrow(ch, char());
2655 #endif /* BOOST_NO_STD_LOCALE */
2657 if (cc == ')') // read "((a,b),(c),x)"
2659 o = octonion<T>(u,v,x);
2661 else if (cc == ',') // read "((a,b),(c),x,"
2663 is >> y; // read "((a,b),(c),x,y"
2665 if (!is.good()) goto finish;
2667 is >> ch; // get the next lexeme
2669 if (!is.good()) goto finish;
2671 #ifdef BOOST_NO_STD_LOCALE
2674 cc = ct.narrow(ch, char());
2675 #endif /* BOOST_NO_STD_LOCALE */
2677 if (cc == ')') // read "((a,b),(c),x,y)"
2679 o = octonion<T>(u,v,x,y);
2683 is.setstate(::std::ios_base::failbit);
2688 is.setstate(::std::ios_base::failbit);
2693 is.setstate(::std::ios_base::failbit);
2696 else if (cc == ',') // read "((a,b),(c," or "((a,b),(e,"
2698 is >> ch; // get the next lexeme
2700 if (!is.good()) goto finish;
2702 #ifdef BOOST_NO_STD_LOCALE
2705 cc = ct.narrow(ch, char());
2706 #endif /* BOOST_NO_STD_LOCALE */
2708 if (cc == '(') // read "((a,b),(e,(" (ambiguity resolution)
2710 u = ::std::complex<T>(a,b);
2712 x = ::std::complex<T>(c); // "c" is actually "e"
2716 is >> y; // read "((a,b),(e,y"
2718 if (!is.good()) goto finish;
2720 is >> ch; // get the next lexeme
2722 if (!is.good()) goto finish;
2724 #ifdef BOOST_NO_STD_LOCALE
2727 cc = ct.narrow(ch, char());
2728 #endif /* BOOST_NO_STD_LOCALE */
2730 if (cc == ')') // read "((a,b),(e,y)"
2732 is >> ch; // get the next lexeme
2734 if (!is.good()) goto finish;
2736 #ifdef BOOST_NO_STD_LOCALE
2739 cc = ct.narrow(ch, char());
2740 #endif /* BOOST_NO_STD_LOCALE */
2742 if (cc == ')') // read "((a,b),(e,y))"
2744 o = octonion<T>(u,v,x,y);
2748 is.setstate(::std::ios_base::failbit);
2753 is.setstate(::std::ios_base::failbit);
2756 else // read "((a,b),(c,d" or "((a,b),(e,f"
2762 if (!is.good()) goto finish;
2764 is >> ch; // get the next lexeme
2766 if (!is.good()) goto finish;
2768 #ifdef BOOST_NO_STD_LOCALE
2771 cc = ct.narrow(ch, char());
2772 #endif /* BOOST_NO_STD_LOCALE */
2774 if (cc == ')') // read "((a,b),(c,d)" (ambiguity resolution)
2776 u = ::std::complex<T>(a,b);
2778 v = ::std::complex<T>(c,d);
2780 is >> ch; // get the next lexeme
2782 if (!is.good()) goto finish;
2784 #ifdef BOOST_NO_STD_LOCALE
2787 cc = ct.narrow(ch, char());
2788 #endif /* BOOST_NO_STD_LOCALE */
2790 if (cc == ')') // read "((a,b),(c,d))"
2792 o = octonion<T>(u,v);
2794 else if (cc == ',') // read "((a,b),(c,d),"
2796 is >> x; // read "((a,b),(c,d),x
2798 if (!is.good()) goto finish;
2800 is >> ch; // get the next lexeme
2802 if (!is.good()) goto finish;
2804 #ifdef BOOST_NO_STD_LOCALE
2807 cc = ct.narrow(ch, char());
2808 #endif /* BOOST_NO_STD_LOCALE */
2810 if (cc == ')') // read "((a,b),(c,d),x)"
2812 o = octonion<T>(u,v,x);
2814 else if (cc == ',') // read "((a,b),(c,d),x,"
2816 is >> y; // read "((a,b),(c,d),x,y"
2818 if (!is.good()) goto finish;
2820 is >> ch; // get the next lexeme
2822 if (!is.good()) goto finish;
2824 #ifdef BOOST_NO_STD_LOCALE
2827 cc = ct.narrow(ch, char());
2828 #endif /* BOOST_NO_STD_LOCALE */
2830 if (cc == ')') // read "((a,b),(c,d),x,y)"
2832 o = octonion<T>(u,v,x,y);
2836 is.setstate(::std::ios_base::failbit);
2841 is.setstate(::std::ios_base::failbit);
2846 is.setstate(::std::ios_base::failbit);
2849 else if (cc == ',') // read "((a,b),(e,f," (ambiguity resolution)
2851 p = ::boost::math::quaternion<T>(a,b); // too late to backtrack
2853 is >> g; // read "((a,b),(e,f,g"
2855 if (!is.good()) goto finish;
2857 is >> ch; // get the next lexeme
2859 if (!is.good()) goto finish;
2861 #ifdef BOOST_NO_STD_LOCALE
2864 cc = ct.narrow(ch, char());
2865 #endif /* BOOST_NO_STD_LOCALE */
2867 if (cc == ')') // read "((a,b),(e,f,g)"
2869 is >> ch; // get the next lexeme
2871 if (!is.good()) goto finish;
2873 #ifdef BOOST_NO_STD_LOCALE
2876 cc = ct.narrow(ch, char());
2877 #endif /* BOOST_NO_STD_LOCALE */
2879 if (cc == ')') // read "((a,b),(e,f,g))"
2881 q = ::boost::math::quaternion<T>(c,d,g); // "c" is actually "e" and "d" is actually "f"
2883 o = octonion<T>(p,q);
2887 is.setstate(::std::ios_base::failbit);
2890 else if (cc == ',') // read "((a,b),(e,f,g,"
2892 is >> h; // read "((a,b),(e,f,g,h"
2894 if (!is.good()) goto finish;
2896 is >> ch; // get the next lexeme
2898 if (!is.good()) goto finish;
2900 #ifdef BOOST_NO_STD_LOCALE
2903 cc = ct.narrow(ch, char());
2904 #endif /* BOOST_NO_STD_LOCALE */
2906 if (cc == ')') // read "((a,b),(e,f,g,h)"
2908 is >> ch; // get the next lexeme
2910 if (!is.good()) goto finish;
2912 #ifdef BOOST_NO_STD_LOCALE
2915 cc = ct.narrow(ch, char());
2916 #endif /* BOOST_NO_STD_LOCALE */
2918 if (cc == ')') // read ((a,b),(e,f,g,h))"
2920 q = ::boost::math::quaternion<T>(c,d,g,h); // "c" is actually "e" and "d" is actually "f"
2922 o = octonion<T>(p,q);
2926 is.setstate(::std::ios_base::failbit);
2931 is.setstate(::std::ios_base::failbit);
2936 is.setstate(::std::ios_base::failbit);
2941 is.setstate(::std::ios_base::failbit);
2947 is.setstate(::std::ios_base::failbit);
2953 is.setstate(::std::ios_base::failbit);
2958 is.setstate(::std::ios_base::failbit);
2961 else if (cc == ',') // read "((a,b,"
2963 is >> c; // read "((a,b,c"
2965 if (!is.good()) goto finish;
2967 is >> ch; // get the next lexeme
2969 if (!is.good()) goto finish;
2971 #ifdef BOOST_NO_STD_LOCALE
2974 cc = ct.narrow(ch, char());
2975 #endif /* BOOST_NO_STD_LOCALE */
2977 if (cc == ')') // read "((a,b,c)"
2979 is >> ch; // get the next lexeme
2981 if (!is.good()) goto finish;
2983 #ifdef BOOST_NO_STD_LOCALE
2986 cc = ct.narrow(ch, char());
2987 #endif /* BOOST_NO_STD_LOCALE */
2989 if (cc == ')') // read "((a,b,c))"
2991 o = octonion<T>(a,b,c);
2993 else if (cc == ',') // read "((a,b,c),"
2995 p = ::boost::math::quaternion<T>(a,b,c);
2997 is >> q; // read "((a,b,c),q"
2999 if (!is.good()) goto finish;
3001 is >> ch; // get the next lexeme
3003 if (!is.good()) goto finish;
3005 #ifdef BOOST_NO_STD_LOCALE
3008 cc = ct.narrow(ch, char());
3009 #endif /* BOOST_NO_STD_LOCALE */
3011 if (cc == ')') // read "((a,b,c),q)"
3013 o = octonion<T>(p,q);
3017 is.setstate(::std::ios_base::failbit);
3022 is.setstate(::std::ios_base::failbit);
3025 else if (cc == ',') // read "((a,b,c,"
3027 is >> d; // read "((a,b,c,d"
3029 if (!is.good()) goto finish;
3031 is >> ch; // get the next lexeme
3033 if (!is.good()) goto finish;
3035 #ifdef BOOST_NO_STD_LOCALE
3038 cc = ct.narrow(ch, char());
3039 #endif /* BOOST_NO_STD_LOCALE */
3041 if (cc == ')') // read "((a,b,c,d)"
3043 is >> ch; // get the next lexeme
3045 if (!is.good()) goto finish;
3047 #ifdef BOOST_NO_STD_LOCALE
3050 cc = ct.narrow(ch, char());
3051 #endif /* BOOST_NO_STD_LOCALE */
3053 if (cc == ')') // read "((a,b,c,d))"
3055 o = octonion<T>(a,b,c,d);
3057 else if (cc == ',') // read "((a,b,c,d),"
3059 p = ::boost::math::quaternion<T>(a,b,c,d);
3061 is >> q; // read "((a,b,c,d),q"
3063 if (!is.good()) goto finish;
3065 is >> ch; // get the next lexeme
3067 if (!is.good()) goto finish;
3069 #ifdef BOOST_NO_STD_LOCALE
3072 cc = ct.narrow(ch, char());
3073 #endif /* BOOST_NO_STD_LOCALE */
3075 if (cc == ')') // read "((a,b,c,d),q)"
3077 o = octonion<T>(p,q);
3081 is.setstate(::std::ios_base::failbit);
3086 is.setstate(::std::ios_base::failbit);
3091 is.setstate(::std::ios_base::failbit);
3096 is.setstate(::std::ios_base::failbit);
3101 is.setstate(::std::ios_base::failbit);
3107 is.setstate(::std::ios_base::failbit);
3115 is >> a; // we extract the first component
3117 if (!is.good()) goto finish;
3119 is >> ch; // get the next lexeme
3121 if (!is.good()) goto finish;
3123 #ifdef BOOST_NO_STD_LOCALE
3126 cc = ct.narrow(ch, char());
3127 #endif /* BOOST_NO_STD_LOCALE */
3129 if (cc == ')') // read "(a)"
3133 else if (cc == ',') // read "(a,"
3135 is >> ch; // get the next lexeme
3137 if (!is.good()) goto finish;
3139 #ifdef BOOST_NO_STD_LOCALE
3142 cc = ct.narrow(ch, char());
3143 #endif /* BOOST_NO_STD_LOCALE */
3145 if (cc == '(') // read "(a,("
3147 is >> ch; // get the next lexeme
3149 if (!is.good()) goto finish;
3151 #ifdef BOOST_NO_STD_LOCALE
3154 cc = ct.narrow(ch, char());
3155 #endif /* BOOST_NO_STD_LOCALE */
3157 if (cc == '(') // read "(a,(("
3159 p = ::boost::math::quaternion<T>(a);
3163 is.putback(ch); // we backtrack twice, with the same value
3165 is >> q; // read "(a,q"
3167 if (!is.good()) goto finish;
3169 is >> ch; // get the next lexeme
3171 if (!is.good()) goto finish;
3173 #ifdef BOOST_NO_STD_LOCALE
3176 cc = ct.narrow(ch, char());
3177 #endif /* BOOST_NO_STD_LOCALE */
3179 if (cc == ')') // read "(a,q)"
3181 o = octonion<T>(p,q);
3185 is.setstate(::std::ios_base::failbit);
3188 else // read "(a,(c" or "(a,(e"
3194 if (!is.good()) goto finish;
3196 is >> ch; // get the next lexeme
3198 if (!is.good()) goto finish;
3200 #ifdef BOOST_NO_STD_LOCALE
3203 cc = ct.narrow(ch, char());
3204 #endif /* BOOST_NO_STD_LOCALE */
3206 if (cc == ')') // read "(a,(c)" (ambiguity resolution)
3208 is >> ch; // get the next lexeme
3210 if (!is.good()) goto finish;
3212 #ifdef BOOST_NO_STD_LOCALE
3215 cc = ct.narrow(ch, char());
3216 #endif /* BOOST_NO_STD_LOCALE */
3218 if (cc == ')') // read "(a,(c))"
3220 o = octonion<T>(a,b,c);
3222 else if (cc == ',') // read "(a,(c),"
3224 u = ::std::complex<T>(a);
3226 v = ::std::complex<T>(c);
3228 is >> x; // read "(a,(c),x"
3230 if (!is.good()) goto finish;
3232 is >> ch; // get the next lexeme
3234 if (!is.good()) goto finish;
3236 #ifdef BOOST_NO_STD_LOCALE
3239 cc = ct.narrow(ch, char());
3240 #endif /* BOOST_NO_STD_LOCALE */
3242 if (cc == ')') // read "(a,(c),x)"
3244 o = octonion<T>(u,v,x);
3246 else if (cc == ',') // read "(a,(c),x,"
3248 is >> y; // read "(a,(c),x,y"
3250 if (!is.good()) goto finish;
3252 is >> ch; // get the next lexeme
3254 if (!is.good()) goto finish;
3256 #ifdef BOOST_NO_STD_LOCALE
3259 cc = ct.narrow(ch, char());
3260 #endif /* BOOST_NO_STD_LOCALE */
3262 if (cc == ')') // read "(a,(c),x,y)"
3264 o = octonion<T>(u,v,x,y);
3268 is.setstate(::std::ios_base::failbit);
3273 is.setstate(::std::ios_base::failbit);
3278 is.setstate(::std::ios_base::failbit);
3281 else if (cc == ',') // read "(a,(c," or "(a,(e,"
3283 is >> ch; // get the next lexeme
3285 if (!is.good()) goto finish;
3287 #ifdef BOOST_NO_STD_LOCALE
3290 cc = ct.narrow(ch, char());
3291 #endif /* BOOST_NO_STD_LOCALE */
3293 if (cc == '(') // read "(a,(e,(" (ambiguity resolution)
3295 u = ::std::complex<T>(a);
3297 x = ::std::complex<T>(c); // "c" is actually "e"
3299 is.putback(ch); // we backtrack
3301 is >> y; // read "(a,(e,y"
3303 if (!is.good()) goto finish;
3305 is >> ch; // get the next lexeme
3307 if (!is.good()) goto finish;
3309 #ifdef BOOST_NO_STD_LOCALE
3312 cc = ct.narrow(ch, char());
3313 #endif /* BOOST_NO_STD_LOCALE */
3315 if (cc == ')') // read "(a,(e,y)"
3317 is >> ch; // get the next lexeme
3319 if (!is.good()) goto finish;
3321 #ifdef BOOST_NO_STD_LOCALE
3324 cc = ct.narrow(ch, char());
3325 #endif /* BOOST_NO_STD_LOCALE */
3327 if (cc == ')') // read "(a,(e,y))"
3329 o = octonion<T>(u,v,x,y);
3333 is.setstate(::std::ios_base::failbit);
3338 is.setstate(::std::ios_base::failbit);
3341 else // read "(a,(c,d" or "(a,(e,f"
3347 if (!is.good()) goto finish;
3349 is >> ch; // get the next lexeme
3351 if (!is.good()) goto finish;
3353 #ifdef BOOST_NO_STD_LOCALE
3356 cc = ct.narrow(ch, char());
3357 #endif /* BOOST_NO_STD_LOCALE */
3359 if (cc == ')') // read "(a,(c,d)" (ambiguity resolution)
3361 is >> ch; // get the next lexeme
3363 if (!is.good()) goto finish;
3365 #ifdef BOOST_NO_STD_LOCALE
3368 cc = ct.narrow(ch, char());
3369 #endif /* BOOST_NO_STD_LOCALE */
3371 if (cc == ')') // read "(a,(c,d))"
3373 o = octonion<T>(a,b,c,d);
3375 else if (cc == ',') // read "(a,(c,d),"
3377 u = ::std::complex<T>(a);
3379 v = ::std::complex<T>(c,d);
3381 is >> x; // read "(a,(c,d),x"
3383 if (!is.good()) goto finish;
3385 is >> ch; // get the next lexeme
3387 if (!is.good()) goto finish;
3389 #ifdef BOOST_NO_STD_LOCALE
3392 cc = ct.narrow(ch, char());
3393 #endif /* BOOST_NO_STD_LOCALE */
3395 if (cc == ')') // read "(a,(c,d),x)"
3397 o = octonion<T>(u,v,x);
3399 else if (cc == ',') // read "(a,(c,d),x,"
3401 is >> y; // read "(a,(c,d),x,y"
3403 if (!is.good()) goto finish;
3405 is >> ch; // get the next lexeme
3407 if (!is.good()) goto finish;
3409 #ifdef BOOST_NO_STD_LOCALE
3412 cc = ct.narrow(ch, char());
3413 #endif /* BOOST_NO_STD_LOCALE */
3415 if (cc == ')') // read "(a,(c,d),x,y)"
3417 o = octonion<T>(u,v,x,y);
3421 is.setstate(::std::ios_base::failbit);
3426 is.setstate(::std::ios_base::failbit);
3431 is.setstate(::std::ios_base::failbit);
3434 else if (cc == ',') // read "(a,(e,f," (ambiguity resolution)
3436 p = ::boost::math::quaternion<T>(a);
3438 is >> g; // read "(a,(e,f,g"
3440 if (!is.good()) goto finish;
3442 is >> ch; // get the next lexeme
3444 if (!is.good()) goto finish;
3446 #ifdef BOOST_NO_STD_LOCALE
3449 cc = ct.narrow(ch, char());
3450 #endif /* BOOST_NO_STD_LOCALE */
3452 if (cc == ')') // read "(a,(e,f,g)"
3454 is >> ch; // get the next lexeme
3456 if (!is.good()) goto finish;
3458 #ifdef BOOST_NO_STD_LOCALE
3461 cc = ct.narrow(ch, char());
3462 #endif /* BOOST_NO_STD_LOCALE */
3464 if (cc == ')') // read "(a,(e,f,g))"
3466 q = ::boost::math::quaternion<T>(c,d,g); // "c" is actually "e" and "d" is actually "f"
3468 o = octonion<T>(p,q);
3472 is.setstate(::std::ios_base::failbit);
3475 else if (cc == ',') // read "(a,(e,f,g,"
3477 is >> h; // read "(a,(e,f,g,h"
3479 if (!is.good()) goto finish;
3481 is >> ch; // get the next lexeme
3483 if (!is.good()) goto finish;
3485 #ifdef BOOST_NO_STD_LOCALE
3488 cc = ct.narrow(ch, char());
3489 #endif /* BOOST_NO_STD_LOCALE */
3491 if (cc == ')') // read "(a,(e,f,g,h)"
3493 is >> ch; // get the next lexeme
3495 if (!is.good()) goto finish;
3497 #ifdef BOOST_NO_STD_LOCALE
3500 cc = ct.narrow(ch, char());
3501 #endif /* BOOST_NO_STD_LOCALE */
3503 if (cc == ')') // read "(a,(e,f,g,h))"
3505 q = ::boost::math::quaternion<T>(c,d,g,h); // "c" is actually "e" and "d" is actually "f"
3507 o = octonion<T>(p,q);
3511 is.setstate(::std::ios_base::failbit);
3516 is.setstate(::std::ios_base::failbit);
3521 is.setstate(::std::ios_base::failbit);
3526 is.setstate(::std::ios_base::failbit);
3532 is.setstate(::std::ios_base::failbit);
3536 else // read "(a,b" or "(a,c" (ambiguity resolution)
3542 if (!is.good()) goto finish;
3544 is >> ch; // get the next lexeme
3546 if (!is.good()) goto finish;
3548 #ifdef BOOST_NO_STD_LOCALE
3551 cc = ct.narrow(ch, char());
3552 #endif /* BOOST_NO_STD_LOCALE */
3554 if (cc == ')') // read "(a,b)" (ambiguity resolution)
3556 o = octonion<T>(a,b);
3558 else if (cc == ',') // read "(a,b," or "(a,c,"
3560 is >> ch; // get the next lexeme
3562 if (!is.good()) goto finish;
3564 #ifdef BOOST_NO_STD_LOCALE
3567 cc = ct.narrow(ch, char());
3568 #endif /* BOOST_NO_STD_LOCALE */
3570 if (cc == '(') // read "(a,c,(" (ambiguity resolution)
3572 u = ::std::complex<T>(a);
3574 v = ::std::complex<T>(b); // "b" is actually "c"
3576 is.putback(ch); // we backtrack
3578 is >> x; // read "(a,c,x"
3580 if (!is.good()) goto finish;
3582 is >> ch; // get the next lexeme
3584 if (!is.good()) goto finish;
3586 #ifdef BOOST_NO_STD_LOCALE
3589 cc = ct.narrow(ch, char());
3590 #endif /* BOOST_NO_STD_LOCALE */
3592 if (cc == ')') // read "(a,c,x)"
3594 o = octonion<T>(u,v,x);
3596 else if (cc == ',') // read "(a,c,x,"
3598 is >> y; // read "(a,c,x,y" // read "(a,c,x"
3600 if (!is.good()) goto finish;
3602 is >> ch; // get the next lexeme
3604 if (!is.good()) goto finish;
3606 #ifdef BOOST_NO_STD_LOCALE
3609 cc = ct.narrow(ch, char());
3610 #endif /* BOOST_NO_STD_LOCALE */
3612 if (cc == ')') // read "(a,c,x,y)"
3614 o = octonion<T>(u,v,x,y);
3618 is.setstate(::std::ios_base::failbit);
3623 is.setstate(::std::ios_base::failbit);
3626 else // read "(a,b,c" or "(a,c,e"
3632 if (!is.good()) goto finish;
3634 is >> ch; // get the next lexeme
3636 if (!is.good()) goto finish;
3638 #ifdef BOOST_NO_STD_LOCALE
3641 cc = ct.narrow(ch, char());
3642 #endif /* BOOST_NO_STD_LOCALE */
3644 if (cc == ')') // read "(a,b,c)" (ambiguity resolution)
3646 o = octonion<T>(a,b,c);
3648 else if (cc == ',') // read "(a,b,c," or "(a,c,e,"
3650 is >> ch; // get the next lexeme
3652 if (!is.good()) goto finish;
3654 #ifdef BOOST_NO_STD_LOCALE
3657 cc = ct.narrow(ch, char());
3658 #endif /* BOOST_NO_STD_LOCALE */
3660 if (cc == '(') // read "(a,c,e,(") (ambiguity resolution)
3662 u = ::std::complex<T>(a);
3664 v = ::std::complex<T>(b); // "b" is actually "c"
3666 x = ::std::complex<T>(c); // "c" is actually "e"
3668 is.putback(ch); // we backtrack
3670 is >> y; // read "(a,c,e,y"
3672 if (!is.good()) goto finish;
3674 is >> ch; // get the next lexeme
3676 if (!is.good()) goto finish;
3678 #ifdef BOOST_NO_STD_LOCALE
3681 cc = ct.narrow(ch, char());
3682 #endif /* BOOST_NO_STD_LOCALE */
3684 if (cc == ')') // read "(a,c,e,y)"
3686 o = octonion<T>(u,v,x,y);
3690 is.setstate(::std::ios_base::failbit);
3693 else // read "(a,b,c,d" (ambiguity resolution)
3695 is.putback(ch); // we backtrack
3699 if (!is.good()) goto finish;
3701 is >> ch; // get the next lexeme
3703 if (!is.good()) goto finish;
3705 #ifdef BOOST_NO_STD_LOCALE
3708 cc = ct.narrow(ch, char());
3709 #endif /* BOOST_NO_STD_LOCALE */
3711 if (cc == ')') // read "(a,b,c,d)"
3713 o = octonion<T>(a,b,c,d);
3715 else if (cc == ',') // read "(a,b,c,d,"
3717 is >> e; // read "(a,b,c,d,e"
3719 if (!is.good()) goto finish;
3721 is >> ch; // get the next lexeme
3723 if (!is.good()) goto finish;
3725 #ifdef BOOST_NO_STD_LOCALE
3728 cc = ct.narrow(ch, char());
3729 #endif /* BOOST_NO_STD_LOCALE */
3731 if (cc == ')') // read "(a,b,c,d,e)"
3733 o = octonion<T>(a,b,c,d,e);
3735 else if (cc == ',') // read "(a,b,c,d,e,"
3737 is >> f; // read "(a,b,c,d,e,f"
3739 if (!is.good()) goto finish;
3741 is >> ch; // get the next lexeme
3743 if (!is.good()) goto finish;
3745 #ifdef BOOST_NO_STD_LOCALE
3748 cc = ct.narrow(ch, char());
3749 #endif /* BOOST_NO_STD_LOCALE */
3751 if (cc == ')') // read "(a,b,c,d,e,f)"
3753 o = octonion<T>(a,b,c,d,e,f);
3755 else if (cc == ',') // read "(a,b,c,d,e,f,"
3757 is >> g; // read "(a,b,c,d,e,f,g" // read "(a,b,c,d,e,f"
3759 if (!is.good()) goto finish;
3761 is >> ch; // get the next lexeme
3763 if (!is.good()) goto finish;
3765 #ifdef BOOST_NO_STD_LOCALE
3768 cc = ct.narrow(ch, char());
3769 #endif /* BOOST_NO_STD_LOCALE */
3771 if (cc == ')') // read "(a,b,c,d,e,f,g)"
3773 o = octonion<T>(a,b,c,d,e,f,g);
3775 else if (cc == ',') // read "(a,b,c,d,e,f,g,"
3777 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"
3779 if (!is.good()) goto finish;
3781 is >> ch; // get the next lexeme
3783 if (!is.good()) goto finish;
3785 #ifdef BOOST_NO_STD_LOCALE
3788 cc = ct.narrow(ch, char());
3789 #endif /* BOOST_NO_STD_LOCALE */
3791 if (cc == ')') // read "(a,b,c,d,e,f,g,h)"
3793 o = octonion<T>(a,b,c,d,e,f,g,h);
3797 is.setstate(::std::ios_base::failbit);
3802 is.setstate(::std::ios_base::failbit);
3807 is.setstate(::std::ios_base::failbit);
3812 is.setstate(::std::ios_base::failbit);
3817 is.setstate(::std::ios_base::failbit);
3823 is.setstate(::std::ios_base::failbit);
3829 is.setstate(::std::ios_base::failbit);
3835 is.setstate(::std::ios_base::failbit);
3843 is >> a; // we extract the first component
3845 if (!is.good()) goto finish;
3855 template<typename T, typename charT, class traits>
3856 ::std::basic_ostream<charT,traits> & operator << ( ::std::basic_ostream<charT,traits> & os,
3857 octonion<T> const & o)
3859 ::std::basic_ostringstream<charT,traits> s;
3861 s.flags(os.flags());
3862 #ifdef BOOST_NO_STD_LOCALE
3864 s.imbue(os.getloc());
3865 #endif /* BOOST_NO_STD_LOCALE */
3866 s.precision(os.precision());
3868 s << '(' << o.R_component_1() << ','
3869 << o.R_component_2() << ','
3870 << o.R_component_3() << ','
3871 << o.R_component_4() << ','
3872 << o.R_component_5() << ','
3873 << o.R_component_6() << ','
3874 << o.R_component_7() << ','
3875 << o.R_component_8() << ')';
3877 return os << s.str();
3883 template<typename T>
3884 inline T real(octonion<T> const & o)
3890 template<typename T>
3891 inline octonion<T> unreal(octonion<T> const & o)
3897 #define BOOST_OCTONION_VALARRAY_LOADER \
3898 using ::std::valarray; \
3900 valarray<T> temp(8); \
3902 temp[0] = o.R_component_1(); \
3903 temp[1] = o.R_component_2(); \
3904 temp[2] = o.R_component_3(); \
3905 temp[3] = o.R_component_4(); \
3906 temp[4] = o.R_component_5(); \
3907 temp[5] = o.R_component_6(); \
3908 temp[6] = o.R_component_7(); \
3909 temp[7] = o.R_component_8();
3912 template<typename T>
3913 inline T sup(octonion<T> const & o)
3915 #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
3917 #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */
3919 BOOST_OCTONION_VALARRAY_LOADER
3921 return((abs(temp).max)());
3925 template<typename T>
3926 inline T l1(octonion<T> const & o)
3928 #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
3930 #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */
3932 BOOST_OCTONION_VALARRAY_LOADER
3934 return(abs(temp).sum());
3938 template<typename T>
3939 inline T abs(const octonion<T> & o)
3941 #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
3943 #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */
3947 BOOST_OCTONION_VALARRAY_LOADER
3949 T maxim = (abs(temp).max)(); // overflow protection
3951 if (maxim == static_cast<T>(0))
3957 T mixam = static_cast<T>(1)/maxim; // prefer multiplications over divisions
3963 return(maxim*sqrt(temp.sum()));
3966 //return(::std::sqrt(norm(o)));
3970 #undef BOOST_OCTONION_VALARRAY_LOADER
3973 // Note: This is the Cayley norm, not the Euclidian norm...
3975 template<typename T>
3976 inline T norm(octonion<T> const & o)
3978 return(real(o*conj(o)));
3982 template<typename T>
3983 inline octonion<T> conj(octonion<T> const & o)
3985 return(octonion<T>( +o.R_component_1(),
3992 -o.R_component_8()));
3996 // Note: There is little point, for the octonions, to introduce the equivalents
3997 // to the complex "arg" and the quaternionic "cylindropolar".
4000 template<typename T>
4001 inline octonion<T> spherical(T const & rho,
4013 //T a = cos(theta)*cos(phi1)*cos(phi2)*cos(phi3)*cos(phi4)*cos(phi5)*cos(phi6);
4014 //T b = sin(theta)*cos(phi1)*cos(phi2)*cos(phi3)*cos(phi4)*cos(phi5)*cos(phi6);
4015 //T c = sin(phi1)*cos(phi2)*cos(phi3)*cos(phi4)*cos(phi5)*cos(phi6);
4016 //T d = sin(phi2)*cos(phi3)*cos(phi4)*cos(phi5)*cos(phi6);
4017 //T e = sin(phi3)*cos(phi4)*cos(phi5)*cos(phi6);
4018 //T f = sin(phi4)*cos(phi5)*cos(phi6);
4019 //T g = sin(phi5)*cos(phi6);
4022 T courrant = static_cast<T>(1);
4026 courrant *= cos(phi6);
4028 T g = sin(phi5)*courrant;
4030 courrant *= cos(phi5);
4032 T f = sin(phi4)*courrant;
4034 courrant *= cos(phi4);
4036 T e = sin(phi3)*courrant;
4038 courrant *= cos(phi3);
4040 T d = sin(phi2)*courrant;
4042 courrant *= cos(phi2);
4044 T c = sin(phi1)*courrant;
4046 courrant *= cos(phi1);
4048 T b = sin(theta)*courrant;
4049 T a = cos(theta)*courrant;
4051 return(rho*octonion<T>(a,b,c,d,e,f,g,h));
4055 template<typename T>
4056 inline octonion<T> multipolar(T const & rho1,
4068 T a = rho1*cos(theta1);
4069 T b = rho1*sin(theta1);
4070 T c = rho2*cos(theta2);
4071 T d = rho2*sin(theta2);
4072 T e = rho3*cos(theta3);
4073 T f = rho3*sin(theta3);
4074 T g = rho4*cos(theta4);
4075 T h = rho4*sin(theta4);
4077 return(octonion<T>(a,b,c,d,e,f,g,h));
4081 template<typename T>
4082 inline octonion<T> cylindrical(T const & r,
4097 return(octonion<T>(a,b,h1,h2,h3,h4,h5,h6));
4101 template<typename T>
4102 inline octonion<T> exp(octonion<T> const & o)
4107 using ::boost::math::sinc_pi;
4111 T z = abs(unreal(o));
4115 return(u*octonion<T>(cos(z),
4116 w*o.R_component_2(), w*o.R_component_3(),
4117 w*o.R_component_4(), w*o.R_component_5(),
4118 w*o.R_component_6(), w*o.R_component_7(),
4119 w*o.R_component_8()));
4123 template<typename T>
4124 inline octonion<T> cos(octonion<T> const & o)
4130 using ::boost::math::sinhc_pi;
4132 T z = abs(unreal(o));
4134 T w = -sin(o.real())*sinhc_pi(z);
4136 return(octonion<T>(cos(o.real())*cosh(z),
4137 w*o.R_component_2(), w*o.R_component_3(),
4138 w*o.R_component_4(), w*o.R_component_5(),
4139 w*o.R_component_6(), w*o.R_component_7(),
4140 w*o.R_component_8()));
4144 template<typename T>
4145 inline octonion<T> sin(octonion<T> const & o)
4151 using ::boost::math::sinhc_pi;
4153 T z = abs(unreal(o));
4155 T w = +cos(o.real())*sinhc_pi(z);
4157 return(octonion<T>(sin(o.real())*cosh(z),
4158 w*o.R_component_2(), w*o.R_component_3(),
4159 w*o.R_component_4(), w*o.R_component_5(),
4160 w*o.R_component_6(), w*o.R_component_7(),
4161 w*o.R_component_8()));
4165 template<typename T>
4166 inline octonion<T> tan(octonion<T> const & o)
4168 return(sin(o)/cos(o));
4172 template<typename T>
4173 inline octonion<T> cosh(octonion<T> const & o)
4175 return((exp(+o)+exp(-o))/static_cast<T>(2));
4179 template<typename T>
4180 inline octonion<T> sinh(octonion<T> const & o)
4182 return((exp(+o)-exp(-o))/static_cast<T>(2));
4186 template<typename T>
4187 inline octonion<T> tanh(octonion<T> const & o)
4189 return(sinh(o)/cosh(o));
4193 template<typename T>
4194 octonion<T> pow(octonion<T> const & o,
4201 octonion<T> result = pow(o, m);
4207 result *= o; // n odd
4218 return(octonion<T>(static_cast<T>(1)));
4222 return(pow(octonion<T>(static_cast<T>(1))/o,-n));
4227 // helper templates for converting copy constructors (definition)
4232 template< typename T,
4235 octonion<T> octonion_type_converter(octonion<U> const & rhs)
4237 return(octonion<T>( static_cast<T>(rhs.R_component_1()),
4238 static_cast<T>(rhs.R_component_2()),
4239 static_cast<T>(rhs.R_component_3()),
4240 static_cast<T>(rhs.R_component_4()),
4241 static_cast<T>(rhs.R_component_5()),
4242 static_cast<T>(rhs.R_component_6()),
4243 static_cast<T>(rhs.R_component_7()),
4244 static_cast<T>(rhs.R_component_8())));
4250 #endif /* BOOST_OCTONION_HPP */