PageRenderTime 117ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 1ms

/external/boost/math/octonion.hpp

http://rgdengine.googlecode.com/
C++ Header | 4754 lines | 3781 code | 845 blank | 128 comment | 635 complexity | 52102af4d2065386029ec37667270515 MD5 | raw file
Possible License(s): LGPL-2.0, BSD-3-Clause
  1. // boost octonion.hpp header file
  2. // (C) Copyright Hubert Holin 2001.
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. // See http://www.boost.org for updates, documentation, and revision history.
  7. #ifndef BOOST_OCTONION_HPP
  8. #define BOOST_OCTONION_HPP
  9. #include <boost/math/quaternion.hpp>
  10. namespace boost
  11. {
  12. namespace math
  13. {
  14. #if BOOST_WORKAROUND(__GNUC__, < 3)
  15. // gcc 2.95.x uses expression templates for valarray calculations, but
  16. // the result is not conforming. We need BOOST_GET_VALARRAY to get an
  17. // actual valarray result when we need to call a member function
  18. #define BOOST_GET_VALARRAY(T,x) ::std::valarray<T>(x)
  19. // gcc 2.95.x has an "std::ios" class that is similar to
  20. // "std::ios_base", so we just use a #define
  21. #define BOOST_IOS_BASE ::std::ios
  22. // gcc 2.x ignores function scope using declarations,
  23. // put them in the scope of the enclosing namespace instead:
  24. using ::std::valarray;
  25. using ::std::sqrt;
  26. using ::std::cos;
  27. using ::std::sin;
  28. using ::std::exp;
  29. using ::std::cosh;
  30. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  31. #define BOOST_OCTONION_ACCESSOR_GENERATOR(type) \
  32. type real() const \
  33. { \
  34. return(a); \
  35. } \
  36. \
  37. octonion<type> unreal() const \
  38. { \
  39. return( octonion<type>(static_cast<type>(0),b,c,d,e,f,g,h)); \
  40. } \
  41. \
  42. type R_component_1() const \
  43. { \
  44. return(a); \
  45. } \
  46. \
  47. type R_component_2() const \
  48. { \
  49. return(b); \
  50. } \
  51. \
  52. type R_component_3() const \
  53. { \
  54. return(c); \
  55. } \
  56. \
  57. type R_component_4() const \
  58. { \
  59. return(d); \
  60. } \
  61. \
  62. type R_component_5() const \
  63. { \
  64. return(e); \
  65. } \
  66. \
  67. type R_component_6() const \
  68. { \
  69. return(f); \
  70. } \
  71. \
  72. type R_component_7() const \
  73. { \
  74. return(g); \
  75. } \
  76. \
  77. type R_component_8() const \
  78. { \
  79. return(h); \
  80. } \
  81. \
  82. ::std::complex<type> C_component_1() const \
  83. { \
  84. return(::std::complex<type>(a,b)); \
  85. } \
  86. \
  87. ::std::complex<type> C_component_2() const \
  88. { \
  89. return(::std::complex<type>(c,d)); \
  90. } \
  91. \
  92. ::std::complex<type> C_component_3() const \
  93. { \
  94. return(::std::complex<type>(e,f)); \
  95. } \
  96. \
  97. ::std::complex<type> C_component_4() const \
  98. { \
  99. return(::std::complex<type>(g,h)); \
  100. } \
  101. \
  102. ::boost::math::quaternion<type> H_component_1() const \
  103. { \
  104. return(::boost::math::quaternion<type>(a,b,c,d)); \
  105. } \
  106. \
  107. ::boost::math::quaternion<type> H_component_2() const \
  108. { \
  109. return(::boost::math::quaternion<type>(e,f,g,h)); \
  110. }
  111. #define BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(type) \
  112. template<typename X> \
  113. octonion<type> & operator = (octonion<X> const & a_affecter) \
  114. { \
  115. a = static_cast<type>(a_affecter.R_component_1()); \
  116. b = static_cast<type>(a_affecter.R_component_2()); \
  117. c = static_cast<type>(a_affecter.R_component_3()); \
  118. d = static_cast<type>(a_affecter.R_component_4()); \
  119. e = static_cast<type>(a_affecter.R_component_5()); \
  120. f = static_cast<type>(a_affecter.R_component_6()); \
  121. g = static_cast<type>(a_affecter.R_component_7()); \
  122. h = static_cast<type>(a_affecter.R_component_8()); \
  123. \
  124. return(*this); \
  125. } \
  126. \
  127. octonion<type> & operator = (octonion<type> const & a_affecter) \
  128. { \
  129. a = a_affecter.a; \
  130. b = a_affecter.b; \
  131. c = a_affecter.c; \
  132. d = a_affecter.d; \
  133. e = a_affecter.e; \
  134. f = a_affecter.f; \
  135. g = a_affecter.g; \
  136. h = a_affecter.h; \
  137. \
  138. return(*this); \
  139. } \
  140. \
  141. octonion<type> & operator = (type const & a_affecter) \
  142. { \
  143. a = a_affecter; \
  144. \
  145. b = c = d = e = f= g = h = static_cast<type>(0); \
  146. \
  147. return(*this); \
  148. } \
  149. \
  150. octonion<type> & operator = (::std::complex<type> const & a_affecter) \
  151. { \
  152. a = a_affecter.real(); \
  153. b = a_affecter.imag(); \
  154. \
  155. c = d = e = f = g = h = static_cast<type>(0); \
  156. \
  157. return(*this); \
  158. } \
  159. \
  160. octonion<type> & operator = (::boost::math::quaternion<type> const & a_affecter) \
  161. { \
  162. a = a_affecter.R_component_1(); \
  163. b = a_affecter.R_component_2(); \
  164. c = a_affecter.R_component_3(); \
  165. d = a_affecter.R_component_4(); \
  166. \
  167. e = f = g = h = static_cast<type>(0); \
  168. \
  169. return(*this); \
  170. }
  171. #define BOOST_OCTONION_MEMBER_DATA_GENERATOR(type) \
  172. type a; \
  173. type b; \
  174. type c; \
  175. type d; \
  176. type e; \
  177. type f; \
  178. type g; \
  179. type h; \
  180. template<typename T>
  181. class octonion
  182. {
  183. public:
  184. typedef T value_type;
  185. // constructor for O seen as R^8
  186. // (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())
  195. : a(requested_a),
  196. b(requested_b),
  197. c(requested_c),
  198. d(requested_d),
  199. e(requested_e),
  200. f(requested_f),
  201. g(requested_g),
  202. h(requested_h)
  203. {
  204. // nothing to do!
  205. }
  206. // constructor for H seen as C^4
  207. explicit octonion( ::std::complex<T> const & z0,
  208. ::std::complex<T> const & z1 = ::std::complex<T>(),
  209. ::std::complex<T> const & z2 = ::std::complex<T>(),
  210. ::std::complex<T> const & z3 = ::std::complex<T>())
  211. : a(z0.real()),
  212. b(z0.imag()),
  213. c(z1.real()),
  214. d(z1.imag()),
  215. e(z2.real()),
  216. f(z2.imag()),
  217. g(z3.real()),
  218. h(z3.imag())
  219. {
  220. // nothing to do!
  221. }
  222. // constructor for O seen as H^2
  223. explicit octonion( ::boost::math::quaternion<T> const & q0,
  224. ::boost::math::quaternion<T> const & q1 = ::boost::math::quaternion<T>())
  225. : a(q0.R_component_1()),
  226. b(q0.R_component_2()),
  227. c(q0.R_component_3()),
  228. d(q0.R_component_4()),
  229. e(q1.R_component_1()),
  230. f(q1.R_component_2()),
  231. g(q1.R_component_3()),
  232. h(q1.R_component_4())
  233. {
  234. // nothing to do!
  235. }
  236. // UNtemplated copy constructor
  237. // (this is taken care of by the compiler itself)
  238. // templated copy constructor
  239. template<typename X>
  240. explicit octonion(octonion<X> const & a_recopier)
  241. : a(static_cast<T>(a_recopier.R_component_1())),
  242. b(static_cast<T>(a_recopier.R_component_2())),
  243. c(static_cast<T>(a_recopier.R_component_3())),
  244. d(static_cast<T>(a_recopier.R_component_4())),
  245. e(static_cast<T>(a_recopier.R_component_5())),
  246. f(static_cast<T>(a_recopier.R_component_6())),
  247. g(static_cast<T>(a_recopier.R_component_7())),
  248. h(static_cast<T>(a_recopier.R_component_8()))
  249. {
  250. // nothing to do!
  251. }
  252. // destructor
  253. // (this is taken care of by the compiler itself)
  254. // accessors
  255. //
  256. // Note: Like complex number, octonions do have a meaningful notion of "real part",
  257. // but unlike them there is no meaningful notion of "imaginary part".
  258. // Instead there is an "unreal part" which itself is an octonion, and usually
  259. // nothing simpler (as opposed to the complex number case).
  260. // However, for practicallity, there are accessors for the other components
  261. // (these are necessary for the templated copy constructor, for instance).
  262. BOOST_OCTONION_ACCESSOR_GENERATOR(T)
  263. // assignment operators
  264. BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(T)
  265. // other assignment-related operators
  266. //
  267. // NOTE: Octonion multiplication is *NOT* commutative;
  268. // symbolically, "q *= rhs;" means "q = q * rhs;"
  269. // and "q /= rhs;" means "q = q * inverse_of(rhs);";
  270. // octonion multiplication is also *NOT* associative
  271. octonion<T> & operator += (T const & rhs)
  272. {
  273. T at = a + rhs; // exception guard
  274. a = at;
  275. return(*this);
  276. }
  277. octonion<T> & operator += (::std::complex<T> const & rhs)
  278. {
  279. T at = a + rhs.real(); // exception guard
  280. T bt = b + rhs.imag(); // exception guard
  281. a = at;
  282. b = bt;
  283. return(*this);
  284. }
  285. octonion<T> & operator += (::boost::math::quaternion<T> const & rhs)
  286. {
  287. T at = a + rhs.R_component_1(); // exception guard
  288. T bt = b + rhs.R_component_2(); // exception guard
  289. T ct = c + rhs.R_component_3(); // exception guard
  290. T dt = d + rhs.R_component_4(); // exception guard
  291. a = at;
  292. b = bt;
  293. c = ct;
  294. d = dt;
  295. return(*this);
  296. }
  297. template<typename X>
  298. octonion<T> & operator += (octonion<X> const & rhs)
  299. {
  300. T at = a + static_cast<T>(rhs.R_component_1()); // exception guard
  301. T bt = b + static_cast<T>(rhs.R_component_2()); // exception guard
  302. T ct = c + static_cast<T>(rhs.R_component_3()); // exception guard
  303. T dt = d + static_cast<T>(rhs.R_component_4()); // exception guard
  304. T et = e + static_cast<T>(rhs.R_component_5()); // exception guard
  305. T ft = f + static_cast<T>(rhs.R_component_6()); // exception guard
  306. T gt = g + static_cast<T>(rhs.R_component_7()); // exception guard
  307. T ht = h + static_cast<T>(rhs.R_component_8()); // exception guard
  308. a = at;
  309. b = bt;
  310. c = ct;
  311. d = dt;
  312. e = et;
  313. f = ft;
  314. g = gt;
  315. h = ht;
  316. return(*this);
  317. }
  318. octonion<T> & operator -= (T const & rhs)
  319. {
  320. T at = a - rhs; // exception guard
  321. a = at;
  322. return(*this);
  323. }
  324. octonion<T> & operator -= (::std::complex<T> const & rhs)
  325. {
  326. T at = a - rhs.real(); // exception guard
  327. T bt = b - rhs.imag(); // exception guard
  328. a = at;
  329. b = bt;
  330. return(*this);
  331. }
  332. octonion<T> & operator -= (::boost::math::quaternion<T> const & rhs)
  333. {
  334. T at = a - rhs.R_component_1(); // exception guard
  335. T bt = b - rhs.R_component_2(); // exception guard
  336. T ct = c - rhs.R_component_3(); // exception guard
  337. T dt = d - rhs.R_component_4(); // exception guard
  338. a = at;
  339. b = bt;
  340. c = ct;
  341. d = dt;
  342. return(*this);
  343. }
  344. template<typename X>
  345. octonion<T> & operator -= (octonion<X> const & rhs)
  346. {
  347. T at = a - static_cast<T>(rhs.R_component_1()); // exception guard
  348. T bt = b - static_cast<T>(rhs.R_component_2()); // exception guard
  349. T ct = c - static_cast<T>(rhs.R_component_3()); // exception guard
  350. T dt = d - static_cast<T>(rhs.R_component_4()); // exception guard
  351. T et = e - static_cast<T>(rhs.R_component_5()); // exception guard
  352. T ft = f - static_cast<T>(rhs.R_component_6()); // exception guard
  353. T gt = g - static_cast<T>(rhs.R_component_7()); // exception guard
  354. T ht = h - static_cast<T>(rhs.R_component_8()); // exception guard
  355. a = at;
  356. b = bt;
  357. c = ct;
  358. d = dt;
  359. e = et;
  360. f = ft;
  361. g = gt;
  362. h = ht;
  363. return(*this);
  364. }
  365. octonion<T> & operator *= (T const & rhs)
  366. {
  367. T at = a * rhs; // exception guard
  368. T bt = b * rhs; // exception guard
  369. T ct = c * rhs; // exception guard
  370. T dt = d * rhs; // exception guard
  371. T et = e * rhs; // exception guard
  372. T ft = f * rhs; // exception guard
  373. T gt = g * rhs; // exception guard
  374. T ht = h * rhs; // exception guard
  375. a = at;
  376. b = bt;
  377. c = ct;
  378. d = dt;
  379. e = et;
  380. f = ft;
  381. g = gt;
  382. h = ht;
  383. return(*this);
  384. }
  385. octonion<T> & operator *= (::std::complex<T> const & rhs)
  386. {
  387. T ar = rhs.real();
  388. T br = rhs.imag();
  389. T at = +a*ar-b*br;
  390. T bt = +a*br+b*ar;
  391. T ct = +c*ar+d*br;
  392. T dt = -c*br+d*ar;
  393. T et = +e*ar+f*br;
  394. T ft = -e*br+f*ar;
  395. T gt = +g*ar-h*br;
  396. T ht = +g*br+h*ar;
  397. a = at;
  398. b = bt;
  399. c = ct;
  400. d = dt;
  401. e = et;
  402. f = ft;
  403. g = gt;
  404. h = ht;
  405. return(*this);
  406. }
  407. octonion<T> & operator *= (::boost::math::quaternion<T> const & rhs)
  408. {
  409. T ar = rhs.R_component_1();
  410. T br = rhs.R_component_2();
  411. T cr = rhs.R_component_2();
  412. T dr = rhs.R_component_2();
  413. T at = +a*ar-b*br-c*cr-d*dr;
  414. T bt = +a*br+b*ar+c*dr-d*cr;
  415. T ct = +a*cr-b*dr+c*ar+d*br;
  416. T dt = +a*dr+b*cr-c*br+d*ar;
  417. T et = +e*ar+f*br+g*cr+h*dr;
  418. T ft = -e*br+f*ar-g*dr+h*cr;
  419. T gt = -e*cr+f*dr+g*ar-h*br;
  420. T ht = -e*dr-f*cr+g*br+h*ar;
  421. a = at;
  422. b = bt;
  423. c = ct;
  424. d = dt;
  425. e = et;
  426. f = ft;
  427. g = gt;
  428. h = ht;
  429. return(*this);
  430. }
  431. template<typename X>
  432. octonion<T> & operator *= (octonion<X> const & rhs)
  433. {
  434. T ar = static_cast<T>(rhs.R_component_1());
  435. T br = static_cast<T>(rhs.R_component_2());
  436. T cr = static_cast<T>(rhs.R_component_3());
  437. T dr = static_cast<T>(rhs.R_component_4());
  438. T er = static_cast<T>(rhs.R_component_5());
  439. T fr = static_cast<T>(rhs.R_component_6());
  440. T gr = static_cast<T>(rhs.R_component_7());
  441. T hr = static_cast<T>(rhs.R_component_8());
  442. T at = +a*ar-b*br-c*cr-d*dr-e*er-f*fr-g*gr-h*hr;
  443. T bt = +a*br+b*ar+c*dr-d*cr+e*fr-f*er-g*hr+h*gr;
  444. T ct = +a*cr-b*dr+c*ar+d*br+e*gr+f*hr-g*er-h*fr;
  445. T dt = +a*dr+b*cr-c*br+d*ar+e*hr-f*gr+g*fr-h*er;
  446. T et = +a*er-b*fr-c*gr-d*hr+e*ar+f*br+g*cr+h*dr;
  447. T ft = +a*fr+b*er-c*hr+d*gr-e*br+f*ar-g*dr+h*cr;
  448. T gt = +a*gr+b*hr+c*er-d*fr-e*cr+f*dr+g*ar-h*br;
  449. T ht = +a*hr-b*gr+c*fr+d*er-e*dr-f*cr+g*br+h*ar;
  450. a = at;
  451. b = bt;
  452. c = ct;
  453. d = dt;
  454. e = et;
  455. f = ft;
  456. g = gt;
  457. h = ht;
  458. return(*this);
  459. }
  460. octonion<T> & operator /= (T const & rhs)
  461. {
  462. T at = a / rhs; // exception guard
  463. T bt = b / rhs; // exception guard
  464. T ct = c / rhs; // exception guard
  465. T dt = d / rhs; // exception guard
  466. T et = e / rhs; // exception guard
  467. T ft = f / rhs; // exception guard
  468. T gt = g / rhs; // exception guard
  469. T ht = h / rhs; // exception guard
  470. a = at;
  471. b = bt;
  472. c = ct;
  473. d = dt;
  474. e = et;
  475. f = ft;
  476. g = gt;
  477. h = ht;
  478. return(*this);
  479. }
  480. octonion<T> & operator /= (::std::complex<T> const & rhs)
  481. {
  482. T ar = rhs.real();
  483. T br = rhs.imag();
  484. T denominator = ar*ar+br*br;
  485. T at = (+a*ar-b*br)/denominator;
  486. T bt = (-a*br+b*ar)/denominator;
  487. T ct = (+c*ar-d*br)/denominator;
  488. T dt = (+c*br+d*ar)/denominator;
  489. T et = (+e*ar-f*br)/denominator;
  490. T ft = (+e*br+f*ar)/denominator;
  491. T gt = (+g*ar+h*br)/denominator;
  492. T ht = (+g*br+h*ar)/denominator;
  493. a = at;
  494. b = bt;
  495. c = ct;
  496. d = dt;
  497. e = et;
  498. f = ft;
  499. g = gt;
  500. h = ht;
  501. return(*this);
  502. }
  503. octonion<T> & operator /= (::boost::math::quaternion<T> const & rhs)
  504. {
  505. T ar = rhs.R_component_1();
  506. T br = rhs.R_component_2();
  507. T cr = rhs.R_component_2();
  508. T dr = rhs.R_component_2();
  509. T denominator = ar*ar+br*br+cr*cr+dr*dr;
  510. T at = (+a*ar+b*br+c*cr+d*dr)/denominator;
  511. T bt = (-a*br+b*ar-c*dr+d*cr)/denominator;
  512. T ct = (-a*cr+b*dr+c*ar-d*br)/denominator;
  513. T dt = (-a*dr-b*cr+c*br+d*ar)/denominator;
  514. T et = (+e*ar-f*br-g*cr-h*dr)/denominator;
  515. T ft = (+e*br+f*ar+g*dr-h*cr)/denominator;
  516. T gt = (+e*cr-f*dr+g*ar+h*br)/denominator;
  517. T ht = (+e*dr+f*cr-g*br+h*ar)/denominator;
  518. a = at;
  519. b = bt;
  520. c = ct;
  521. d = dt;
  522. e = et;
  523. f = ft;
  524. g = gt;
  525. h = ht;
  526. return(*this);
  527. }
  528. template<typename X>
  529. octonion<T> & operator /= (octonion<X> const & rhs)
  530. {
  531. T ar = static_cast<T>(rhs.R_component_1());
  532. T br = static_cast<T>(rhs.R_component_2());
  533. T cr = static_cast<T>(rhs.R_component_3());
  534. T dr = static_cast<T>(rhs.R_component_4());
  535. T er = static_cast<T>(rhs.R_component_5());
  536. T fr = static_cast<T>(rhs.R_component_6());
  537. T gr = static_cast<T>(rhs.R_component_7());
  538. T hr = static_cast<T>(rhs.R_component_8());
  539. T denominator = ar*ar+br*br+cr*cr+dr*dr+er*er+fr*fr+gr*gr+hr*hr;
  540. T at = (+a*ar+b*br+c*cr+d*dr+e*er+f*fr+g*gr+h*hr)/denominator;
  541. T bt = (-a*br+b*ar-c*dr+d*cr-e*fr+f*er+g*hr-h*gr)/denominator;
  542. T ct = (-a*cr+b*dr+c*ar-d*br-e*gr-f*hr+g*er+h*fr)/denominator;
  543. T dt = (-a*dr-b*cr+c*br+d*ar-e*hr+f*gr-g*fr+h*er)/denominator;
  544. T et = (-a*er+b*fr+c*gr+d*hr+e*ar-f*br-g*cr-h*dr)/denominator;
  545. T ft = (-a*fr-b*er+c*hr-d*gr+e*br+f*ar+g*dr-h*cr)/denominator;
  546. T gt = (-a*gr-b*hr-c*er+d*fr+e*cr-f*dr+g*ar+h*br)/denominator;
  547. T ht = (-a*hr+b*gr-c*fr-d*er+e*dr+f*cr-g*br+h*ar)/denominator;
  548. a = at;
  549. b = bt;
  550. c = ct;
  551. d = dt;
  552. e = et;
  553. f = ft;
  554. g = gt;
  555. h = ht;
  556. return(*this);
  557. }
  558. protected:
  559. BOOST_OCTONION_MEMBER_DATA_GENERATOR(T)
  560. private:
  561. };
  562. // declaration of octonion specialization
  563. template<> class octonion<float>;
  564. template<> class octonion<double>;
  565. template<> class octonion<long double>;
  566. // helper templates for converting copy constructors (declaration)
  567. namespace detail
  568. {
  569. template< typename T,
  570. typename U
  571. >
  572. octonion<T> octonion_type_converter(octonion<U> const & rhs);
  573. }
  574. // implementation of octonion specialization
  575. #define BOOST_OCTONION_CONSTRUCTOR_GENERATOR(type) \
  576. explicit octonion( type const & requested_a = static_cast<type>(0), \
  577. type const & requested_b = static_cast<type>(0), \
  578. type const & requested_c = static_cast<type>(0), \
  579. type const & requested_d = static_cast<type>(0), \
  580. type const & requested_e = static_cast<type>(0), \
  581. type const & requested_f = static_cast<type>(0), \
  582. type const & requested_g = static_cast<type>(0), \
  583. type const & requested_h = static_cast<type>(0)) \
  584. : a(requested_a), \
  585. b(requested_b), \
  586. c(requested_c), \
  587. d(requested_d), \
  588. e(requested_e), \
  589. f(requested_f), \
  590. g(requested_g), \
  591. h(requested_h) \
  592. { \
  593. } \
  594. \
  595. explicit octonion( ::std::complex<type> const & z0, \
  596. ::std::complex<type> const & z1 = ::std::complex<type>(), \
  597. ::std::complex<type> const & z2 = ::std::complex<type>(), \
  598. ::std::complex<type> const & z3 = ::std::complex<type>()) \
  599. : a(z0.real()), \
  600. b(z0.imag()), \
  601. c(z1.real()), \
  602. d(z1.imag()), \
  603. e(z2.real()), \
  604. f(z2.imag()), \
  605. g(z3.real()), \
  606. h(z3.imag()) \
  607. { \
  608. } \
  609. \
  610. explicit octonion( ::boost::math::quaternion<type> const & q0, \
  611. ::boost::math::quaternion<type> const & q1 = ::boost::math::quaternion<type>()) \
  612. : a(q0.R_component_1()), \
  613. b(q0.R_component_2()), \
  614. c(q0.R_component_3()), \
  615. d(q0.R_component_4()), \
  616. e(q1.R_component_1()), \
  617. f(q1.R_component_2()), \
  618. g(q1.R_component_3()), \
  619. h(q1.R_component_4()) \
  620. { \
  621. }
  622. #define BOOST_OCTONION_MEMBER_ADD_GENERATOR_1(type) \
  623. octonion<type> & operator += (type const & rhs) \
  624. { \
  625. a += rhs; \
  626. \
  627. return(*this); \
  628. }
  629. #define BOOST_OCTONION_MEMBER_ADD_GENERATOR_2(type) \
  630. octonion<type> & operator += (::std::complex<type> const & rhs) \
  631. { \
  632. a += rhs.real(); \
  633. b += rhs.imag(); \
  634. \
  635. return(*this); \
  636. }
  637. #define BOOST_OCTONION_MEMBER_ADD_GENERATOR_3(type) \
  638. octonion<type> & operator += (::boost::math::quaternion<type> const & rhs) \
  639. { \
  640. a += rhs.R_component_1(); \
  641. b += rhs.R_component_2(); \
  642. c += rhs.R_component_3(); \
  643. d += rhs.R_component_4(); \
  644. \
  645. return(*this); \
  646. }
  647. #define BOOST_OCTONION_MEMBER_ADD_GENERATOR_4(type) \
  648. template<typename X> \
  649. octonion<type> & operator += (octonion<X> const & rhs) \
  650. { \
  651. a += static_cast<type>(rhs.R_component_1()); \
  652. b += static_cast<type>(rhs.R_component_2()); \
  653. c += static_cast<type>(rhs.R_component_3()); \
  654. d += static_cast<type>(rhs.R_component_4()); \
  655. e += static_cast<type>(rhs.R_component_5()); \
  656. f += static_cast<type>(rhs.R_component_6()); \
  657. g += static_cast<type>(rhs.R_component_7()); \
  658. h += static_cast<type>(rhs.R_component_8()); \
  659. \
  660. return(*this); \
  661. }
  662. #define BOOST_OCTONION_MEMBER_SUB_GENERATOR_1(type) \
  663. octonion<type> & operator -= (type const & rhs) \
  664. { \
  665. a -= rhs; \
  666. \
  667. return(*this); \
  668. }
  669. #define BOOST_OCTONION_MEMBER_SUB_GENERATOR_2(type) \
  670. octonion<type> & operator -= (::std::complex<type> const & rhs) \
  671. { \
  672. a -= rhs.real(); \
  673. b -= rhs.imag(); \
  674. \
  675. return(*this); \
  676. }
  677. #define BOOST_OCTONION_MEMBER_SUB_GENERATOR_3(type) \
  678. octonion<type> & operator -= (::boost::math::quaternion<type> const & rhs) \
  679. { \
  680. a -= rhs.R_component_1(); \
  681. b -= rhs.R_component_2(); \
  682. c -= rhs.R_component_3(); \
  683. d -= rhs.R_component_4(); \
  684. \
  685. return(*this); \
  686. }
  687. #define BOOST_OCTONION_MEMBER_SUB_GENERATOR_4(type) \
  688. template<typename X> \
  689. octonion<type> & operator -= (octonion<X> const & rhs) \
  690. { \
  691. a -= static_cast<type>(rhs.R_component_1()); \
  692. b -= static_cast<type>(rhs.R_component_2()); \
  693. c -= static_cast<type>(rhs.R_component_3()); \
  694. d -= static_cast<type>(rhs.R_component_4()); \
  695. e -= static_cast<type>(rhs.R_component_5()); \
  696. f -= static_cast<type>(rhs.R_component_6()); \
  697. g -= static_cast<type>(rhs.R_component_7()); \
  698. h -= static_cast<type>(rhs.R_component_8()); \
  699. \
  700. return(*this); \
  701. }
  702. #define BOOST_OCTONION_MEMBER_MUL_GENERATOR_1(type) \
  703. octonion<type> & operator *= (type const & rhs) \
  704. { \
  705. a *= rhs; \
  706. b *= rhs; \
  707. c *= rhs; \
  708. d *= rhs; \
  709. e *= rhs; \
  710. f *= rhs; \
  711. g *= rhs; \
  712. h *= rhs; \
  713. \
  714. return(*this); \
  715. }
  716. #define BOOST_OCTONION_MEMBER_MUL_GENERATOR_2(type) \
  717. octonion<type> & operator *= (::std::complex<type> const & rhs) \
  718. { \
  719. type ar = rhs.real(); \
  720. type br = rhs.imag(); \
  721. \
  722. type at = +a*ar-b*br; \
  723. type bt = +a*br+b*ar; \
  724. type ct = +c*ar+d*br; \
  725. type dt = -c*br+d*ar; \
  726. type et = +e*ar+f*br; \
  727. type ft = -e*br+f*ar; \
  728. type gt = +g*ar-h*br; \
  729. type ht = +g*br+h*ar; \
  730. \
  731. a = at; \
  732. b = bt; \
  733. c = ct; \
  734. d = dt; \
  735. e = et; \
  736. f = ft; \
  737. g = gt; \
  738. h = ht; \
  739. \
  740. return(*this); \
  741. }
  742. #define BOOST_OCTONION_MEMBER_MUL_GENERATOR_3(type) \
  743. octonion<type> & operator *= (::boost::math::quaternion<type> const & rhs) \
  744. { \
  745. type ar = rhs.R_component_1(); \
  746. type br = rhs.R_component_2(); \
  747. type cr = rhs.R_component_2(); \
  748. type dr = rhs.R_component_2(); \
  749. \
  750. type at = +a*ar-b*br-c*cr-d*dr; \
  751. type bt = +a*br+b*ar+c*dr-d*cr; \
  752. type ct = +a*cr-b*dr+c*ar+d*br; \
  753. type dt = +a*dr+b*cr-c*br+d*ar; \
  754. type et = +e*ar+f*br+g*cr+h*dr; \
  755. type ft = -e*br+f*ar-g*dr+h*cr; \
  756. type gt = -e*cr+f*dr+g*ar-h*br; \
  757. type ht = -e*dr-f*cr+g*br+h*ar; \
  758. \
  759. a = at; \
  760. b = bt; \
  761. c = ct; \
  762. d = dt; \
  763. e = et; \
  764. f = ft; \
  765. g = gt; \
  766. h = ht; \
  767. \
  768. return(*this); \
  769. }
  770. #define BOOST_OCTONION_MEMBER_MUL_GENERATOR_4(type) \
  771. template<typename X> \
  772. octonion<type> & operator *= (octonion<X> const & rhs) \
  773. { \
  774. type ar = static_cast<type>(rhs.R_component_1()); \
  775. type br = static_cast<type>(rhs.R_component_2()); \
  776. type cr = static_cast<type>(rhs.R_component_3()); \
  777. type dr = static_cast<type>(rhs.R_component_4()); \
  778. type er = static_cast<type>(rhs.R_component_5()); \
  779. type fr = static_cast<type>(rhs.R_component_6()); \
  780. type gr = static_cast<type>(rhs.R_component_7()); \
  781. type hr = static_cast<type>(rhs.R_component_8()); \
  782. \
  783. type at = +a*ar-b*br-c*cr-d*dr-e*er-f*fr-g*gr-h*hr; \
  784. type bt = +a*br+b*ar+c*dr-d*cr+e*fr-f*er-g*hr+h*gr; \
  785. type ct = +a*cr-b*dr+c*ar+d*br+e*gr+f*hr-g*er-h*fr; \
  786. type dt = +a*dr+b*cr-c*br+d*ar+e*hr-f*gr+g*fr-h*er; \
  787. type et = +a*er-b*fr-c*gr-d*hr+e*ar+f*br+g*cr+h*dr; \
  788. type ft = +a*fr+b*er-c*hr+d*gr-e*br+f*ar-g*dr+h*cr; \
  789. type gt = +a*gr+b*hr+c*er-d*fr-e*cr+f*dr+g*ar-h*br; \
  790. type ht = +a*hr-b*gr+c*fr+d*er-e*dr-f*cr+g*br+h*ar; \
  791. \
  792. a = at; \
  793. b = bt; \
  794. c = ct; \
  795. d = dt; \
  796. e = et; \
  797. f = ft; \
  798. g = gt; \
  799. h = ht; \
  800. \
  801. return(*this); \
  802. }
  803. // There is quite a lot of repetition in the code below. This is intentional.
  804. // The last conditional block is the normal form, and the others merely
  805. // consist of workarounds for various compiler deficiencies. Hopefuly, when
  806. // more compilers are conformant and we can retire support for those that are
  807. // not, we will be able to remove the clutter. This is makes the situation
  808. // (painfully) explicit.
  809. #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_1(type) \
  810. octonion<type> & operator /= (type const & rhs) \
  811. { \
  812. a /= rhs; \
  813. b /= rhs; \
  814. c /= rhs; \
  815. d /= rhs; \
  816. \
  817. return(*this); \
  818. }
  819. #if defined(__GNUC__) && (__GNUC__ < 3)
  820. #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_2(type) \
  821. octonion<type> & operator /= (::std::complex<type> const & rhs) \
  822. { \
  823. using ::std::valarray; \
  824. \
  825. valarray<type> tr(2); \
  826. \
  827. tr[0] = rhs.real(); \
  828. tr[1] = rhs.imag(); \
  829. \
  830. type mixam = (BOOST_GET_VALARRAY(type,static_cast<type>(1)/abs(tr)).max)(); \
  831. \
  832. tr *= mixam; \
  833. \
  834. valarray<type> tt(8); \
  835. \
  836. tt[0] = +a*tr[0]-b*tr[1]; \
  837. tt[1] = -a*tr[1]+b*tr[0]; \
  838. tt[2] = +c*tr[0]-d*tr[1]; \
  839. tt[3] = +c*tr[1]+d*tr[0]; \
  840. tt[4] = +e*tr[0]-f*tr[1]; \
  841. tt[5] = +e*tr[1]+f*tr[0]; \
  842. tt[6] = +g*tr[0]+h*tr[1]; \
  843. tt[7] = +g*tr[1]+h*tr[0]; \
  844. \
  845. tr *= tr; \
  846. \
  847. tt *= (mixam/tr.sum()); \
  848. \
  849. a = tt[0]; \
  850. b = tt[1]; \
  851. c = tt[2]; \
  852. d = tt[3]; \
  853. e = tt[4]; \
  854. f = tt[5]; \
  855. g = tt[6]; \
  856. h = tt[7]; \
  857. \
  858. return(*this); \
  859. }
  860. #elif defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
  861. #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_2(type) \
  862. octonion<type> & operator /= (::std::complex<type> const & rhs) \
  863. { \
  864. using ::std::valarray; \
  865. using ::std::abs; \
  866. \
  867. valarray<type> tr(2); \
  868. \
  869. tr[0] = rhs.real(); \
  870. tr[1] = rhs.imag(); \
  871. \
  872. type mixam = static_cast<type>(1)/(abs(tr).max)(); \
  873. \
  874. tr *= mixam; \
  875. \
  876. valarray<type> tt(8); \
  877. \
  878. tt[0] = +a*tr[0]-b*tr[1]; \
  879. tt[1] = -a*tr[1]+b*tr[0]; \
  880. tt[2] = +c*tr[0]-d*tr[1]; \
  881. tt[3] = +c*tr[1]+d*tr[0]; \
  882. tt[4] = +e*tr[0]-f*tr[1]; \
  883. tt[5] = +e*tr[1]+f*tr[0]; \
  884. tt[6] = +g*tr[0]+h*tr[1]; \
  885. tt[7] = +g*tr[1]+h*tr[0]; \
  886. \
  887. tr *= tr; \
  888. \
  889. tt *= (mixam/tr.sum()); \
  890. \
  891. a = tt[0]; \
  892. b = tt[1]; \
  893. c = tt[2]; \
  894. d = tt[3]; \
  895. e = tt[4]; \
  896. f = tt[5]; \
  897. g = tt[6]; \
  898. h = tt[7]; \
  899. \
  900. return(*this); \
  901. }
  902. #else
  903. #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_2(type) \
  904. octonion<type> & operator /= (::std::complex<type> const & rhs) \
  905. { \
  906. using ::std::valarray; \
  907. \
  908. valarray<type> tr(2); \
  909. \
  910. tr[0] = rhs.real(); \
  911. tr[1] = rhs.imag(); \
  912. \
  913. type mixam = static_cast<type>(1)/(abs(tr).max)(); \
  914. \
  915. tr *= mixam; \
  916. \
  917. valarray<type> tt(8); \
  918. \
  919. tt[0] = +a*tr[0]-b*tr[1]; \
  920. tt[1] = -a*tr[1]+b*tr[0]; \
  921. tt[2] = +c*tr[0]-d*tr[1]; \
  922. tt[3] = +c*tr[1]+d*tr[0]; \
  923. tt[4] = +e*tr[0]-f*tr[1]; \
  924. tt[5] = +e*tr[1]+f*tr[0]; \
  925. tt[6] = +g*tr[0]+h*tr[1]; \
  926. tt[7] = +g*tr[1]+h*tr[0]; \
  927. \
  928. tr *= tr; \
  929. \
  930. tt *= (mixam/tr.sum()); \
  931. \
  932. a = tt[0]; \
  933. b = tt[1]; \
  934. c = tt[2]; \
  935. d = tt[3]; \
  936. e = tt[4]; \
  937. f = tt[5]; \
  938. g = tt[6]; \
  939. h = tt[7]; \
  940. \
  941. return(*this); \
  942. }
  943. #endif /* defined(__GNUC__) && (__GNUC__ < 3) */ /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */
  944. #if defined(__GNUC__) && (__GNUC__ < 3)
  945. #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_3(type) \
  946. octonion<type> & operator /= (::boost::math::quaternion<type> const & rhs) \
  947. { \
  948. using ::std::valarray; \
  949. \
  950. valarray<type> tr(4); \
  951. \
  952. tr[0] = static_cast<type>(rhs.R_component_1()); \
  953. tr[1] = static_cast<type>(rhs.R_component_2()); \
  954. tr[2] = static_cast<type>(rhs.R_component_3()); \
  955. tr[3] = static_cast<type>(rhs.R_component_4()); \
  956. \
  957. type mixam = (BOOST_GET_VALARRAY(type,static_cast<type>(1)/abs(tr)).max)();\
  958. \
  959. tr *= mixam; \
  960. \
  961. valarray<type> tt(8); \
  962. \
  963. tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]; \
  964. tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]; \
  965. tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]; \
  966. tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]; \
  967. tt[4] = +e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \
  968. tt[5] = +e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \
  969. tt[6] = +e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \
  970. tt[7] = +e*tr[3]+f*tr[2]-g*tr[1]+h*tr[0]; \
  971. \
  972. tr *= tr; \
  973. \
  974. tt *= (mixam/tr.sum()); \
  975. \
  976. a = tt[0]; \
  977. b = tt[1]; \
  978. c = tt[2]; \
  979. d = tt[3]; \
  980. e = tt[4]; \
  981. f = tt[5]; \
  982. g = tt[6]; \
  983. h = tt[7]; \
  984. \
  985. return(*this); \
  986. }
  987. #elif defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
  988. #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_3(type) \
  989. octonion<type> & operator /= (::boost::math::quaternion<type> const & rhs) \
  990. { \
  991. using ::std::valarray; \
  992. using ::std::abs; \
  993. \
  994. valarray<type> tr(4); \
  995. \
  996. tr[0] = static_cast<type>(rhs.R_component_1()); \
  997. tr[1] = static_cast<type>(rhs.R_component_2()); \
  998. tr[2] = static_cast<type>(rhs.R_component_3()); \
  999. tr[3] = static_cast<type>(rhs.R_component_4()); \
  1000. \
  1001. type mixam = static_cast<type>(1)/(abs(tr).max)(); \
  1002. \
  1003. tr *= mixam; \
  1004. \
  1005. valarray<type> tt(8); \
  1006. \
  1007. tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]; \
  1008. tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]; \
  1009. tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]; \
  1010. tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]; \
  1011. tt[4] = +e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \
  1012. tt[5] = +e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \
  1013. tt[6] = +e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \
  1014. tt[7] = +e*tr[3]+f*tr[2]-g*tr[1]+h*tr[0]; \
  1015. \
  1016. tr *= tr; \
  1017. \
  1018. tt *= (mixam/tr.sum()); \
  1019. \
  1020. a = tt[0]; \
  1021. b = tt[1]; \
  1022. c = tt[2]; \
  1023. d = tt[3]; \
  1024. e = tt[4]; \
  1025. f = tt[5]; \
  1026. g = tt[6]; \
  1027. h = tt[7]; \
  1028. \
  1029. return(*this); \
  1030. }
  1031. #else
  1032. #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_3(type) \
  1033. octonion<type> & operator /= (::boost::math::quaternion<type> const & rhs) \
  1034. { \
  1035. using ::std::valarray; \
  1036. \
  1037. valarray<type> tr(4); \
  1038. \
  1039. tr[0] = static_cast<type>(rhs.R_component_1()); \
  1040. tr[1] = static_cast<type>(rhs.R_component_2()); \
  1041. tr[2] = static_cast<type>(rhs.R_component_3()); \
  1042. tr[3] = static_cast<type>(rhs.R_component_4()); \
  1043. \
  1044. type mixam = static_cast<type>(1)/(abs(tr).max)(); \
  1045. \
  1046. tr *= mixam; \
  1047. \
  1048. valarray<type> tt(8); \
  1049. \
  1050. tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]; \
  1051. tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]; \
  1052. tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]; \
  1053. tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]; \
  1054. tt[4] = +e*tr[0]-f*tr[1]-g*tr[2]-h*tr[3]; \
  1055. tt[5] = +e*tr[1]+f*tr[0]+g*tr[3]-h*tr[2]; \
  1056. tt[6] = +e*tr[2]-f*tr[3]+g*tr[0]+h*tr[1]; \
  1057. tt[7] = +e*tr[3]+f*tr[2]-g*tr[1]+h*tr[0]; \
  1058. \
  1059. tr *= tr; \
  1060. \
  1061. tt *= (mixam/tr.sum()); \
  1062. \
  1063. a = tt[0]; \
  1064. b = tt[1]; \
  1065. c = tt[2]; \
  1066. d = tt[3]; \
  1067. e = tt[4]; \
  1068. f = tt[5]; \
  1069. g = tt[6]; \
  1070. h = tt[7]; \
  1071. \
  1072. return(*this); \
  1073. }
  1074. #endif /* defined(__GNUC__) && (__GNUC__ < 3) */ /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */
  1075. #if defined(__GNUC__) && (__GNUC__ < 3)
  1076. #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_4(type) \
  1077. template<typename X> \
  1078. octonion<type> & operator /= (octonion<X> const & rhs) \
  1079. { \
  1080. using ::std::valarray; \
  1081. \
  1082. valarray<type> tr(8); \
  1083. \
  1084. tr[0] = static_cast<type>(rhs.R_component_1()); \
  1085. tr[1] = static_cast<type>(rhs.R_component_2()); \
  1086. tr[2] = static_cast<type>(rhs.R_component_3()); \
  1087. tr[3] = static_cast<type>(rhs.R_component_4()); \
  1088. tr[4] = static_cast<type>(rhs.R_component_5()); \
  1089. tr[5] = static_cast<type>(rhs.R_component_6()); \
  1090. tr[6] = static_cast<type>(rhs.R_component_7()); \
  1091. tr[7] = static_cast<type>(rhs.R_component_8()); \
  1092. \
  1093. type mixam = (BOOST_GET_VALARRAY(type,static_cast<type>(1)/abs(tr)).max)();\
  1094. \
  1095. tr *= mixam; \
  1096. \
  1097. valarray<type> tt(8); \
  1098. \
  1099. 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]; \
  1100. 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]; \
  1101. 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]; \
  1102. 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]; \
  1103. 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]; \
  1104. 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]; \
  1105. 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]; \
  1106. 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]; \
  1107. \
  1108. tr *= tr; \
  1109. \
  1110. tt *= (mixam/tr.sum()); \
  1111. \
  1112. a = tt[0]; \
  1113. b = tt[1]; \
  1114. c = tt[2]; \
  1115. d = tt[3]; \
  1116. e = tt[4]; \
  1117. f = tt[5]; \
  1118. g = tt[6]; \
  1119. h = tt[7]; \
  1120. \
  1121. return(*this); \
  1122. }
  1123. #elif defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
  1124. #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_4(type) \
  1125. template<typename X> \
  1126. octonion<type> & operator /= (octonion<X> const & rhs) \
  1127. { \
  1128. using ::std::valarray; \
  1129. using ::std::abs; \
  1130. \
  1131. valarray<type> tr(8); \
  1132. \
  1133. tr[0] = static_cast<type>(rhs.R_component_1()); \
  1134. tr[1] = static_cast<type>(rhs.R_component_2()); \
  1135. tr[2] = static_cast<type>(rhs.R_component_3()); \
  1136. tr[3] = static_cast<type>(rhs.R_component_4()); \
  1137. tr[4] = static_cast<type>(rhs.R_component_5()); \
  1138. tr[5] = static_cast<type>(rhs.R_component_6()); \
  1139. tr[6] = static_cast<type>(rhs.R_component_7()); \
  1140. tr[7] = static_cast<type>(rhs.R_component_8()); \
  1141. \
  1142. type mixam = static_cast<type>(1)/(abs(tr).max)(); \
  1143. \
  1144. tr *= mixam; \
  1145. \
  1146. valarray<type> tt(8); \
  1147. \
  1148. 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]; \
  1149. 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]; \
  1150. 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]; \
  1151. 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]; \
  1152. 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]; \
  1153. 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]; \
  1154. 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]; \
  1155. 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]; \
  1156. \
  1157. tr *= tr; \
  1158. \
  1159. tt *= (mixam/tr.sum()); \
  1160. \
  1161. a = tt[0]; \
  1162. b = tt[1]; \
  1163. c = tt[2]; \
  1164. d = tt[3]; \
  1165. e = tt[4]; \
  1166. f = tt[5]; \
  1167. g = tt[6]; \
  1168. h = tt[7]; \
  1169. \
  1170. return(*this); \
  1171. }
  1172. #else
  1173. #define BOOST_OCTONION_MEMBER_DIV_GENERATOR_4(type) \
  1174. template<typename X> \
  1175. octonion<type> & operator /= (octonion<X> const & rhs) \
  1176. { \
  1177. using ::std::valarray; \
  1178. \
  1179. valarray<type> tr(8); \
  1180. \
  1181. tr[0] = static_cast<type>(rhs.R_component_1()); \
  1182. tr[1] = static_cast<type>(rhs.R_component_2()); \
  1183. tr[2] = static_cast<type>(rhs.R_component_3()); \
  1184. tr[3] = static_cast<type>(rhs.R_component_4()); \
  1185. tr[4] = static_cast<type>(rhs.R_component_5()); \
  1186. tr[5] = static_cast<type>(rhs.R_component_6()); \
  1187. tr[6] = static_cast<type>(rhs.R_component_7()); \
  1188. tr[7] = static_cast<type>(rhs.R_component_8()); \
  1189. \
  1190. type mixam = static_cast<type>(1)/(abs(tr).max)(); \
  1191. \
  1192. tr *= mixam; \
  1193. \
  1194. valarray<type> tt(8); \
  1195. \
  1196. 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]; \
  1197. 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]; \
  1198. 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]; \
  1199. 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]; \
  1200. 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]; \
  1201. 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]; \
  1202. 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]; \
  1203. 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]; \
  1204. \
  1205. tr *= tr; \
  1206. \
  1207. tt *= (mixam/tr.sum()); \
  1208. \
  1209. a = tt[0]; \
  1210. b = tt[1]; \
  1211. c = tt[2]; \
  1212. d = tt[3]; \
  1213. e = tt[4]; \
  1214. f = tt[5]; \
  1215. g = tt[6]; \
  1216. h = tt[7]; \
  1217. \
  1218. return(*this); \
  1219. }
  1220. #endif /* defined(__GNUC__) && (__GNUC__ < 3) */ /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */
  1221. #define BOOST_OCTONION_MEMBER_ADD_GENERATOR(type) \
  1222. BOOST_OCTONION_MEMBER_ADD_GENERATOR_1(type) \
  1223. BOOST_OCTONION_MEMBER_ADD_GENERATOR_2(type) \
  1224. BOOST_OCTONION_MEMBER_ADD_GENERATOR_3(type) \
  1225. BOOST_OCTONION_MEMBER_ADD_GENERATOR_4(type)
  1226. #define BOOST_OCTONION_MEMBER_SUB_GENERATOR(type) \
  1227. BOOST_OCTONION_MEMBER_SUB_GENERATOR_1(type) \
  1228. BOOST_OCTONION_MEMBER_SUB_GENERATOR_2(type) \
  1229. BOOST_OCTONION_MEMBER_SUB_GENERATOR_3(type) \
  1230. BOOST_OCTONION_MEMBER_SUB_GENERATOR_4(type)
  1231. #define BOOST_OCTONION_MEMBER_MUL_GENERATOR(type) \
  1232. BOOST_OCTONION_MEMBER_MUL_GENERATOR_1(type) \
  1233. BOOST_OCTONION_MEMBER_MUL_GENERATOR_2(type) \
  1234. BOOST_OCTONION_MEMBER_MUL_GENERATOR_3(type) \
  1235. 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)
  1241. #define BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR(type) \
  1242. BOOST_OCTONION_MEMBER_ADD_GENERATOR(type) \
  1243. BOOST_OCTONION_MEMBER_SUB_GENERATOR(type) \
  1244. BOOST_OCTONION_MEMBER_MUL_GENERATOR(type) \
  1245. BOOST_OCTONION_MEMBER_DIV_GENERATOR(type)
  1246. template<>
  1247. class octonion<float>
  1248. {
  1249. public:
  1250. typedef float value_type;
  1251. BOOST_OCTONION_CONSTRUCTOR_GENERATOR(float)
  1252. // UNtemplated copy constructor
  1253. // (this is taken care of by the compiler itself)
  1254. // explicit copy constructors (precision-loosing converters)
  1255. explicit octonion(octonion<double> const & a_recopier)
  1256. {
  1257. *this = detail::octonion_type_converter<float, double>(a_recopier);
  1258. }
  1259. explicit octonion(octonion<long double> const & a_recopier)
  1260. {
  1261. *this = detail::octonion_type_converter<float, long double>(a_recopier);
  1262. }
  1263. // destructor
  1264. // (this is taken care of by the compiler itself)
  1265. // accessors
  1266. //
  1267. // Note: Like complex number, octonions do have a meaningful notion of "real part",
  1268. // but unlike them there is no meaningful notion of "imaginary part".
  1269. // Instead there is an "unreal part" which itself is an octonion, and usually
  1270. // nothing simpler (as opposed to the complex number case).
  1271. // However, for practicallity, there are accessors for the other components
  1272. // (these are necessary for the templated copy constructor, for instance).
  1273. BOOST_OCTONION_ACCESSOR_GENERATOR(float)
  1274. // assignment operators
  1275. BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(float)
  1276. // other assignment-related operators
  1277. //
  1278. // NOTE: Octonion multiplication is *NOT* commutative;
  1279. // symbolically, "q *= rhs;" means "q = q * rhs;"
  1280. // and "q /= rhs;" means "q = q * inverse_of(rhs);";
  1281. // octonion multiplication is also *NOT* associative
  1282. BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR(float)
  1283. protected:
  1284. BOOST_OCTONION_MEMBER_DATA_GENERATOR(float)
  1285. private:
  1286. };
  1287. template<>
  1288. class octonion<double>
  1289. {
  1290. public:
  1291. typedef double value_type;
  1292. BOOST_OCTONION_CONSTRUCTOR_GENERATOR(double)
  1293. // UNtemplated copy constructor
  1294. // (this is taken care of by the compiler itself)
  1295. // converting copy constructor
  1296. explicit octonion(octonion<float> const & a_recopier)
  1297. {
  1298. *this = detail::octonion_type_converter<double, float>(a_recopier);
  1299. }
  1300. // explicit copy constructors (precision-loosing converters)
  1301. explicit octonion(octonion<long double> const & a_recopier)
  1302. {
  1303. *this = detail::octonion_type_converter<double, long double>(a_recopier);
  1304. }
  1305. // destructor
  1306. // (this is taken care of by the compiler itself)
  1307. // accessors
  1308. //
  1309. // Note: Like complex number, octonions do have a meaningful notion of "real part",
  1310. // but unlike them there is no meaningful notion of "imaginary part".
  1311. // Instead there is an "unreal part" which itself is an octonion, and usually
  1312. // nothing simpler (as opposed to the complex number case).
  1313. // However, for practicallity, there are accessors for the other components
  1314. // (these are necessary for the templated copy constructor, for instance).
  1315. BOOST_OCTONION_ACCESSOR_GENERATOR(double)
  1316. // assignment operators
  1317. BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(double)
  1318. // other assignment-related operators
  1319. //
  1320. // NOTE: Octonion multiplication is *NOT* commutative;
  1321. // symbolically, "q *= rhs;" means "q = q * rhs;"
  1322. // and "q /= rhs;" means "q = q * inverse_of(rhs);";
  1323. // octonion multiplication is also *NOT* associative
  1324. BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR(double)
  1325. protected:
  1326. BOOST_OCTONION_MEMBER_DATA_GENERATOR(double)
  1327. private:
  1328. };
  1329. template<>
  1330. class octonion<long double>
  1331. {
  1332. public:
  1333. typedef long double value_type;
  1334. BOOST_OCTONION_CONSTRUCTOR_GENERATOR(long double)
  1335. // UNtemplated copy constructor
  1336. // (this is taken care of by the compiler itself)
  1337. // converting copy constructor
  1338. explicit octonion(octonion<float> const & a_recopier)
  1339. {
  1340. *this = detail::octonion_type_converter<long double, float>(a_recopier);
  1341. }
  1342. explicit octonion(octonion<double> const & a_recopier)
  1343. {
  1344. *this = detail::octonion_type_converter<long double, double>(a_recopier);
  1345. }
  1346. // destructor
  1347. // (this is taken care of by the compiler itself)
  1348. // accessors
  1349. //
  1350. // Note: Like complex number, octonions do have a meaningful notion of "real part",
  1351. // but unlike them there is no meaningful notion of "imaginary part".
  1352. // Instead there is an "unreal part" which itself is an octonion, and usually
  1353. // nothing simpler (as opposed to the complex number case).
  1354. // However, for practicallity, there are accessors for the other components
  1355. // (these are necessary for the templated copy constructor, for instance).
  1356. BOOST_OCTONION_ACCESSOR_GENERATOR(long double)
  1357. // assignment operators
  1358. BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR(long double)
  1359. // other assignment-related operators
  1360. //
  1361. // NOTE: Octonion multiplication is *NOT* commutative;
  1362. // symbolically, "q *= rhs;" means "q = q * rhs;"
  1363. // and "q /= rhs;" means "q = q * inverse_of(rhs);";
  1364. // octonion multiplication is also *NOT* associative
  1365. BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR(long double)
  1366. protected:
  1367. BOOST_OCTONION_MEMBER_DATA_GENERATOR(long double)
  1368. private:
  1369. };
  1370. #undef BOOST_OCTONION_CONSTRUCTOR_GENERATOR
  1371. #undef BOOST_OCTONION_MEMBER_ALGEBRAIC_GENERATOR
  1372. #undef BOOST_OCTONION_MEMBER_ADD_GENERATOR
  1373. #undef BOOST_OCTONION_MEMBER_SUB_GENERATOR
  1374. #undef BOOST_OCTONION_MEMBER_MUL_GENERATOR
  1375. #undef BOOST_OCTONION_MEMBER_DIV_GENERATOR
  1376. #undef BOOST_OCTONION_MEMBER_ADD_GENERATOR_1
  1377. #undef BOOST_OCTONION_MEMBER_ADD_GENERATOR_2
  1378. #undef BOOST_OCTONION_MEMBER_ADD_GENERATOR_3
  1379. #undef BOOST_OCTONION_MEMBER_ADD_GENERATOR_4
  1380. #undef BOOST_OCTONION_MEMBER_SUB_GENERATOR_1
  1381. #undef BOOST_OCTONION_MEMBER_SUB_GENERATOR_2
  1382. #undef BOOST_OCTONION_MEMBER_SUB_GENERATOR_3
  1383. #undef BOOST_OCTONION_MEMBER_SUB_GENERATOR_4
  1384. #undef BOOST_OCTONION_MEMBER_MUL_GENERATOR_1
  1385. #undef BOOST_OCTONION_MEMBER_MUL_GENERATOR_2
  1386. #undef BOOST_OCTONION_MEMBER_MUL_GENERATOR_3
  1387. #undef BOOST_OCTONION_MEMBER_MUL_GENERATOR_4
  1388. #undef BOOST_OCTONION_MEMBER_DIV_GENERATOR_1
  1389. #undef BOOST_OCTONION_MEMBER_DIV_GENERATOR_2
  1390. #undef BOOST_OCTONION_MEMBER_DIV_GENERATOR_3
  1391. #undef BOOST_OCTONION_MEMBER_DIV_GENERATOR_4
  1392. #undef BOOST_OCTONION_MEMBER_DATA_GENERATOR
  1393. #undef BOOST_OCTONION_MEMBER_ASSIGNMENT_GENERATOR
  1394. #undef BOOST_OCTONION_ACCESSOR_GENERATOR
  1395. // operators
  1396. #define BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op) \
  1397. { \
  1398. octonion<T> res(lhs); \
  1399. res op##= rhs; \
  1400. return(res); \
  1401. }
  1402. #define BOOST_OCTONION_OPERATOR_GENERATOR_1_L(op) \
  1403. template<typename T> \
  1404. inline octonion<T> operator op (T const & lhs, octonion<T> const & rhs) \
  1405. BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op)
  1406. #define BOOST_OCTONION_OPERATOR_GENERATOR_1_R(op) \
  1407. template<typename T> \
  1408. inline octonion<T> operator op (octonion<T> const & lhs, T const & rhs) \
  1409. BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op)
  1410. #define BOOST_OCTONION_OPERATOR_GENERATOR_2_L(op) \
  1411. template<typename T> \
  1412. inline octonion<T> operator op (::std::complex<T> const & lhs, octonion<T> const & rhs) \
  1413. BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op)
  1414. #define BOOST_OCTONION_OPERATOR_GENERATOR_2_R(op) \
  1415. template<typename T> \
  1416. inline octonion<T> operator op (octonion<T> const & lhs, ::std::complex<T> const & rhs) \
  1417. BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op)
  1418. #define BOOST_OCTONION_OPERATOR_GENERATOR_3_L(op) \
  1419. template<typename T> \
  1420. inline octonion<T> operator op (::boost::math::quaternion<T> const & lhs, octonion<T> const & rhs) \
  1421. BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op)
  1422. #define BOOST_OCTONION_OPERATOR_GENERATOR_3_R(op) \
  1423. template<typename T> \
  1424. inline octonion<T> operator op (octonion<T> const & lhs, ::boost::math::quaternion<T> const & rhs) \
  1425. BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op)
  1426. #define BOOST_OCTONION_OPERATOR_GENERATOR_4(op) \
  1427. template<typename T> \
  1428. inline octonion<T> operator op (octonion<T> const & lhs, octonion<T> const & rhs) \
  1429. BOOST_OCTONION_OPERATOR_GENERATOR_BODY(op)
  1430. #define BOOST_OCTONION_OPERATOR_GENERATOR(op) \
  1431. BOOST_OCTONION_OPERATOR_GENERATOR_1_L(op) \
  1432. BOOST_OCTONION_OPERATOR_GENERATOR_1_R(op) \
  1433. BOOST_OCTONION_OPERATOR_GENERATOR_2_L(op) \
  1434. BOOST_OCTONION_OPERATOR_GENERATOR_2_R(op) \
  1435. BOOST_OCTONION_OPERATOR_GENERATOR_3_L(op) \
  1436. BOOST_OCTONION_OPERATOR_GENERATOR_3_R(op) \
  1437. BOOST_OCTONION_OPERATOR_GENERATOR_4(op)
  1438. BOOST_OCTONION_OPERATOR_GENERATOR(+)
  1439. BOOST_OCTONION_OPERATOR_GENERATOR(-)
  1440. BOOST_OCTONION_OPERATOR_GENERATOR(*)
  1441. BOOST_OCTONION_OPERATOR_GENERATOR(/)
  1442. #undef BOOST_OCTONION_OPERATOR_GENERATOR
  1443. #undef BOOST_OCTONION_OPERATOR_GENERATOR_1_L
  1444. #undef BOOST_OCTONION_OPERATOR_GENERATOR_1_R
  1445. #undef BOOST_OCTONION_OPERATOR_GENERATOR_2_L
  1446. #undef BOOST_OCTONION_OPERATOR_GENERATOR_2_R
  1447. #undef BOOST_OCTONION_OPERATOR_GENERATOR_3_L
  1448. #undef BOOST_OCTONION_OPERATOR_GENERATOR_3_R
  1449. #undef BOOST_OCTONION_OPERATOR_GENERATOR_4
  1450. #undef BOOST_OCTONION_OPERATOR_GENERATOR_BODY
  1451. template<typename T>
  1452. inline octonion<T> operator + (octonion<T> const & o)
  1453. {
  1454. return(o);
  1455. }
  1456. template<typename T>
  1457. inline octonion<T> operator - (octonion<T> const & o)
  1458. {
  1459. 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()));
  1460. }
  1461. template<typename T>
  1462. inline bool operator == (T const & lhs, octonion<T> const & rhs)
  1463. {
  1464. return(
  1465. (rhs.R_component_1() == lhs)&&
  1466. (rhs.R_component_2() == static_cast<T>(0))&&
  1467. (rhs.R_component_3() == static_cast<T>(0))&&
  1468. (rhs.R_component_4() == static_cast<T>(0))&&
  1469. (rhs.R_component_5() == static_cast<T>(0))&&
  1470. (rhs.R_component_6() == static_cast<T>(0))&&
  1471. (rhs.R_component_7() == static_cast<T>(0))&&
  1472. (rhs.R_component_8() == static_cast<T>(0))
  1473. );
  1474. }
  1475. template<typename T>
  1476. inline bool operator == (octonion<T> const & lhs, T const & rhs)
  1477. {
  1478. return(
  1479. (lhs.R_component_1() == rhs)&&
  1480. (lhs.R_component_2() == static_cast<T>(0))&&
  1481. (lhs.R_component_3() == static_cast<T>(0))&&
  1482. (lhs.R_component_4() == static_cast<T>(0))&&
  1483. (lhs.R_component_5() == static_cast<T>(0))&&
  1484. (lhs.R_component_6() == static_cast<T>(0))&&
  1485. (lhs.R_component_7() == static_cast<T>(0))&&
  1486. (lhs.R_component_8() == static_cast<T>(0))
  1487. );
  1488. }
  1489. template<typename T>
  1490. inline bool operator == (::std::complex<T> const & lhs, octonion<T> const & rhs)
  1491. {
  1492. return(
  1493. (rhs.R_component_1() == lhs.real())&&
  1494. (rhs.R_component_2() == lhs.imag())&&
  1495. (rhs.R_component_3() == static_cast<T>(0))&&
  1496. (rhs.R_component_4() == static_cast<T>(0))&&
  1497. (rhs.R_component_5() == static_cast<T>(0))&&
  1498. (rhs.R_component_6() == static_cast<T>(0))&&
  1499. (rhs.R_component_7() == static_cast<T>(0))&&
  1500. (rhs.R_component_8() == static_cast<T>(0))
  1501. );
  1502. }
  1503. template<typename T>
  1504. inline bool operator == (octonion<T> const & lhs, ::std::complex<T> const & rhs)
  1505. {
  1506. return(
  1507. (lhs.R_component_1() == rhs.real())&&
  1508. (lhs.R_component_2() == rhs.imag())&&
  1509. (lhs.R_component_3() == static_cast<T>(0))&&
  1510. (lhs.R_component_4() == static_cast<T>(0))&&
  1511. (lhs.R_component_5() == static_cast<T>(0))&&
  1512. (lhs.R_component_6() == static_cast<T>(0))&&
  1513. (lhs.R_component_7() == static_cast<T>(0))&&
  1514. (lhs.R_component_8() == static_cast<T>(0))
  1515. );
  1516. }
  1517. template<typename T>
  1518. inline bool operator == (::boost::math::quaternion<T> const & lhs, octonion<T> const & rhs)
  1519. {
  1520. return(
  1521. (rhs.R_component_1() == lhs.R_component_1())&&
  1522. (rhs.R_component_2() == lhs.R_component_2())&&
  1523. (rhs.R_component_3() == lhs.R_component_3())&&
  1524. (rhs.R_component_4() == lhs.R_component_4())&&
  1525. (rhs.R_component_5() == static_cast<T>(0))&&
  1526. (rhs.R_component_6() == static_cast<T>(0))&&
  1527. (rhs.R_component_7() == static_cast<T>(0))&&
  1528. (rhs.R_component_8() == static_cast<T>(0))
  1529. );
  1530. }
  1531. template<typename T>
  1532. inline bool operator == (octonion<T> const & lhs, ::boost::math::quaternion<T> const & rhs)
  1533. {
  1534. return(
  1535. (lhs.R_component_1() == rhs.R_component_1())&&
  1536. (lhs.R_component_2() == rhs.R_component_2())&&
  1537. (lhs.R_component_3() == rhs.R_component_3())&&
  1538. (lhs.R_component_4() == rhs.R_component_4())&&
  1539. (lhs.R_component_5() == static_cast<T>(0))&&
  1540. (lhs.R_component_6() == static_cast<T>(0))&&
  1541. (lhs.R_component_7() == static_cast<T>(0))&&
  1542. (lhs.R_component_8() == static_cast<T>(0))
  1543. );
  1544. }
  1545. template<typename T>
  1546. inline bool operator == (octonion<T> const & lhs, octonion<T> const & rhs)
  1547. {
  1548. return(
  1549. (rhs.R_component_1() == lhs.R_component_1())&&
  1550. (rhs.R_component_2() == lhs.R_component_2())&&
  1551. (rhs.R_component_3() == lhs.R_component_3())&&
  1552. (rhs.R_component_4() == lhs.R_component_4())&&
  1553. (rhs.R_component_5() == lhs.R_component_5())&&
  1554. (rhs.R_component_6() == lhs.R_component_6())&&
  1555. (rhs.R_component_7() == lhs.R_component_7())&&
  1556. (rhs.R_component_8() == lhs.R_component_8())
  1557. );
  1558. }
  1559. #define BOOST_OCTONION_NOT_EQUAL_GENERATOR \
  1560. { \
  1561. return(!(lhs == rhs)); \
  1562. }
  1563. template<typename T>
  1564. inline bool operator != (T const & lhs, octonion<T> const & rhs)
  1565. BOOST_OCTONION_NOT_EQUAL_GENERATOR
  1566. template<typename T>
  1567. inline bool operator != (octonion<T> const & lhs, T const & rhs)
  1568. BOOST_OCTONION_NOT_EQUAL_GENERATOR
  1569. template<typename T>
  1570. inline bool operator != (::std::complex<T> const & lhs, octonion<T> const & rhs)
  1571. BOOST_OCTONION_NOT_EQUAL_GENERATOR
  1572. template<typename T>
  1573. inline bool operator != (octonion<T> const & lhs, ::std::complex<T> const & rhs)
  1574. BOOST_OCTONION_NOT_EQUAL_GENERATOR
  1575. template<typename T>
  1576. inline bool operator != (::boost::math::quaternion<T> const & lhs, octonion<T> const & rhs)
  1577. BOOST_OCTONION_NOT_EQUAL_GENERATOR
  1578. template<typename T>
  1579. inline bool operator != (octonion<T> const & lhs, ::boost::math::quaternion<T> const & rhs)
  1580. BOOST_OCTONION_NOT_EQUAL_GENERATOR
  1581. template<typename T>
  1582. inline bool operator != (octonion<T> const & lhs, octonion<T> const & rhs)
  1583. BOOST_OCTONION_NOT_EQUAL_GENERATOR
  1584. #undef BOOST_OCTONION_NOT_EQUAL_GENERATOR
  1585. // Note: the default values in the constructors of the complex and quaternions make for
  1586. // a very complex and ambiguous situation; we have made choices to disambiguate.
  1587. #if BOOST_WORKAROUND(__GNUC__, < 3)
  1588. template<typename T>
  1589. ::std::istream & operator >> ( ::std::istream & is,
  1590. octonion<T>& o)
  1591. #else
  1592. template<typename T, typename charT, class traits>
  1593. ::std::basic_istream<charT,traits> & operator >> ( ::std::basic_istream<charT,traits> & is,
  1594. octonion<T> & o)
  1595. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  1596. {
  1597. #if BOOST_WORKAROUND(__GNUC__, < 3)
  1598. typedef char charT;
  1599. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  1600. #ifdef BOOST_NO_STD_LOCALE
  1601. #else
  1602. const ::std::ctype<charT> & ct = ::std::use_facet< ::std::ctype<charT> >(is.getloc());
  1603. #endif /* BOOST_NO_STD_LOCALE */
  1604. T a = T();
  1605. T b = T();
  1606. T c = T();
  1607. T d = T();
  1608. T e = T();
  1609. T f = T();
  1610. T g = T();
  1611. T h = T();
  1612. ::std::complex<T> u = ::std::complex<T>();
  1613. ::std::complex<T> v = ::std::complex<T>();
  1614. ::std::complex<T> x = ::std::complex<T>();
  1615. ::std::complex<T> y = ::std::complex<T>();
  1616. ::boost::math::quaternion<T> p = ::boost::math::quaternion<T>();
  1617. ::boost::math::quaternion<T> q = ::boost::math::quaternion<T>();
  1618. charT ch = charT();
  1619. char cc;
  1620. is >> ch; // get the first lexeme
  1621. if (!is.good()) goto finish;
  1622. #ifdef BOOST_NO_STD_LOCALE
  1623. cc = ch;
  1624. #else
  1625. cc = ct.narrow(ch, char());
  1626. #endif /* BOOST_NO_STD_LOCALE */
  1627. if (cc == '(') // read "("
  1628. {
  1629. is >> ch; // get the second lexeme
  1630. if (!is.good()) goto finish;
  1631. #ifdef BOOST_NO_STD_LOCALE
  1632. cc = ch;
  1633. #else
  1634. cc = ct.narrow(ch, char());
  1635. #endif /* BOOST_NO_STD_LOCALE */
  1636. if (cc == '(') // read "(("
  1637. {
  1638. is >> ch; // get the third lexeme
  1639. if (!is.good()) goto finish;
  1640. #ifdef BOOST_NO_STD_LOCALE
  1641. cc = ch;
  1642. #else
  1643. cc = ct.narrow(ch, char());
  1644. #endif /* BOOST_NO_STD_LOCALE */
  1645. if (cc == '(') // read "((("
  1646. {
  1647. is.putback(ch);
  1648. is >> u; // read "((u"
  1649. if (!is.good()) goto finish;
  1650. is >> ch; // get the next lexeme
  1651. if (!is.good()) goto finish;
  1652. #ifdef BOOST_NO_STD_LOCALE
  1653. cc = ch;
  1654. #else
  1655. cc = ct.narrow(ch, char());
  1656. #endif /* BOOST_NO_STD_LOCALE */
  1657. if (cc == ')') // read "((u)"
  1658. {
  1659. is >> ch; // get the next lexeme
  1660. if (!is.good()) goto finish;
  1661. #ifdef BOOST_NO_STD_LOCALE
  1662. cc = ch;
  1663. #else
  1664. cc = ct.narrow(ch, char());
  1665. #endif /* BOOST_NO_STD_LOCALE */
  1666. if (cc == ')') // format: (((a))), (((a,b)))
  1667. {
  1668. o = octonion<T>(u);
  1669. }
  1670. else if (cc == ',') // read "((u),"
  1671. {
  1672. p = ::boost::math::quaternion<T>(u);
  1673. is >> q; // read "((u),q"
  1674. if (!is.good()) goto finish;
  1675. is >> ch; // get the next lexeme
  1676. if (!is.good()) goto finish;
  1677. #ifdef BOOST_NO_STD_LOCALE
  1678. cc = ch;
  1679. #else
  1680. cc = ct.narrow(ch, char());
  1681. #endif /* BOOST_NO_STD_LOCALE */
  1682. if (cc == ')') // format: (((a)),q), (((a,b)),q)
  1683. {
  1684. o = octonion<T>(p,q);
  1685. }
  1686. else // error
  1687. {
  1688. #if BOOST_WORKAROUND(__GNUC__, < 3)
  1689. is.setstate(::std::ios::failbit);
  1690. #else
  1691. is.setstate(::std::ios_base::failbit);
  1692. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  1693. }
  1694. }
  1695. else // error
  1696. {
  1697. #if BOOST_WORKAROUND(__GNUC__, < 3)
  1698. is.setstate(::std::ios::failbit);
  1699. #else
  1700. is.setstate(::std::ios_base::failbit);
  1701. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  1702. }
  1703. }
  1704. else if (cc ==',') // read "((u,"
  1705. {
  1706. is >> v; // read "((u,v"
  1707. if (!is.good()) goto finish;
  1708. is >> ch; // get the next lexeme
  1709. if (!is.good()) goto finish;
  1710. #ifdef BOOST_NO_STD_LOCALE
  1711. cc = ch;
  1712. #else
  1713. cc = ct.narrow(ch, char());
  1714. #endif /* BOOST_NO_STD_LOCALE */
  1715. if (cc == ')') // read "((u,v)"
  1716. {
  1717. p = ::boost::math::quaternion<T>(u,v);
  1718. is >> ch; // get the next lexeme
  1719. if (!is.good()) goto finish;
  1720. #ifdef BOOST_NO_STD_LOCALE
  1721. cc = ch;
  1722. #else
  1723. cc = ct.narrow(ch, char());
  1724. #endif /* BOOST_NO_STD_LOCALE */
  1725. if (cc == ')') // format: (((a),v)), (((a,b),v))
  1726. {
  1727. o = octonion<T>(p);
  1728. }
  1729. else if (cc == ',') // read "((u,v),"
  1730. {
  1731. is >> q; // read "(p,q"
  1732. if (!is.good()) goto finish;
  1733. is >> ch; // get the next lexeme
  1734. if (!is.good()) goto finish;
  1735. #ifdef BOOST_NO_STD_LOCALE
  1736. cc = ch;
  1737. #else
  1738. cc = ct.narrow(ch, char());
  1739. #endif /* BOOST_NO_STD_LOCALE */
  1740. if (cc == ')') // format: (((a),v),q), (((a,b),v),q)
  1741. {
  1742. o = octonion<T>(p,q);
  1743. }
  1744. else // error
  1745. {
  1746. #if BOOST_WORKAROUND(__GNUC__, < 3)
  1747. is.setstate(::std::ios::failbit);
  1748. #else
  1749. is.setstate(::std::ios_base::failbit);
  1750. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  1751. }
  1752. }
  1753. else // error
  1754. {
  1755. #if BOOST_WORKAROUND(__GNUC__, < 3)
  1756. is.setstate(::std::ios::failbit);
  1757. #else
  1758. is.setstate(::std::ios_base::failbit);
  1759. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  1760. }
  1761. }
  1762. else // error
  1763. {
  1764. #if BOOST_WORKAROUND(__GNUC__, < 3)
  1765. is.setstate(::std::ios::failbit);
  1766. #else
  1767. is.setstate(::std::ios_base::failbit);
  1768. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  1769. }
  1770. }
  1771. else // error
  1772. {
  1773. #if BOOST_WORKAROUND(__GNUC__, < 3)
  1774. is.setstate(::std::ios::failbit);
  1775. #else
  1776. is.setstate(::std::ios_base::failbit);
  1777. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  1778. }
  1779. }
  1780. else // read "((a"
  1781. {
  1782. is.putback(ch);
  1783. is >> a; // we extract the first component
  1784. if (!is.good()) goto finish;
  1785. is >> ch; // get the next lexeme
  1786. if (!is.good()) goto finish;
  1787. #ifdef BOOST_NO_STD_LOCALE
  1788. cc = ch;
  1789. #else
  1790. cc = ct.narrow(ch, char());
  1791. #endif /* BOOST_NO_STD_LOCALE */
  1792. if (cc == ')') // read "((a)"
  1793. {
  1794. is >> ch; // get the next lexeme
  1795. if (!is.good()) goto finish;
  1796. #ifdef BOOST_NO_STD_LOCALE
  1797. cc = ch;
  1798. #else
  1799. cc = ct.narrow(ch, char());
  1800. #endif /* BOOST_NO_STD_LOCALE */
  1801. if (cc == ')') // read "((a))"
  1802. {
  1803. o = octonion<T>(a);
  1804. }
  1805. else if (cc == ',') // read "((a),"
  1806. {
  1807. is >> ch; // get the next lexeme
  1808. if (!is.good()) goto finish;
  1809. #ifdef BOOST_NO_STD_LOCALE
  1810. cc = ch;
  1811. #else
  1812. cc = ct.narrow(ch, char());
  1813. #endif /* BOOST_NO_STD_LOCALE */
  1814. if (cc == '(') // read "((a),("
  1815. {
  1816. is >> ch; // get the next lexeme
  1817. if (!is.good()) goto finish;
  1818. #ifdef BOOST_NO_STD_LOCALE
  1819. cc = ch;
  1820. #else
  1821. cc = ct.narrow(ch, char());
  1822. #endif /* BOOST_NO_STD_LOCALE */
  1823. if (cc == '(') // read "((a),(("
  1824. {
  1825. is.putback(ch);
  1826. is.putback(ch); // we backtrack twice, with the same value!
  1827. is >> q; // read "((a),q"
  1828. if (!is.good()) goto finish;
  1829. is >> ch; // get the next lexeme
  1830. if (!is.good()) goto finish;
  1831. #ifdef BOOST_NO_STD_LOCALE
  1832. cc = ch;
  1833. #else
  1834. cc = ct.narrow(ch, char());
  1835. #endif /* BOOST_NO_STD_LOCALE */
  1836. if (cc == ')') // read "((a),q)"
  1837. {
  1838. p = ::boost::math::quaternion<T>(a);
  1839. o = octonion<T>(p,q);
  1840. }
  1841. else // error
  1842. {
  1843. #if BOOST_WORKAROUND(__GNUC__, < 3)
  1844. is.setstate(::std::ios::failbit);
  1845. #else
  1846. is.setstate(::std::ios_base::failbit);
  1847. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  1848. }
  1849. }
  1850. else // read "((a),(c" or "((a),(e"
  1851. {
  1852. is.putback(ch);
  1853. is >> c;
  1854. if (!is.good()) goto finish;
  1855. is >> ch; // get the next lexeme
  1856. if (!is.good()) goto finish;
  1857. #ifdef BOOST_NO_STD_LOCALE
  1858. cc = ch;
  1859. #else
  1860. cc = ct.narrow(ch, char());
  1861. #endif /* BOOST_NO_STD_LOCALE */
  1862. if (cc == ')') // read "((a),(c)" (ambiguity resolution)
  1863. {
  1864. is >> ch; // get the next lexeme
  1865. if (!is.good()) goto finish;
  1866. #ifdef BOOST_NO_STD_LOCALE
  1867. cc = ch;
  1868. #else
  1869. cc = ct.narrow(ch, char());
  1870. #endif /* BOOST_NO_STD_LOCALE */
  1871. if (cc == ')') // read "((a),(c))"
  1872. {
  1873. o = octonion<T>(a,b,c);
  1874. }
  1875. else if (cc == ',') // read "((a),(c),"
  1876. {
  1877. u = ::std::complex<T>(a);
  1878. v = ::std::complex<T>(c);
  1879. is >> x; // read "((a),(c),x"
  1880. if (!is.good()) goto finish;
  1881. is >> ch; // get the next lexeme
  1882. if (!is.good()) goto finish;
  1883. #ifdef BOOST_NO_STD_LOCALE
  1884. cc = ch;
  1885. #else
  1886. cc = ct.narrow(ch, char());
  1887. #endif /* BOOST_NO_STD_LOCALE */
  1888. if (cc == ')') // read "((a),(c),x)"
  1889. {
  1890. o = octonion<T>(u,v,x);
  1891. }
  1892. else if (cc == ',') // read "((a),(c),x,"
  1893. {
  1894. is >> y; // read "((a),(c),x,y"
  1895. if (!is.good()) goto finish;
  1896. is >> ch; // get the next lexeme
  1897. if (!is.good()) goto finish;
  1898. #ifdef BOOST_NO_STD_LOCALE
  1899. cc = ch;
  1900. #else
  1901. cc = ct.narrow(ch, char());
  1902. #endif /* BOOST_NO_STD_LOCALE */
  1903. if (cc == ')') // read "((a),(c),x,y)"
  1904. {
  1905. o = octonion<T>(u,v,x,y);
  1906. }
  1907. else // error
  1908. {
  1909. #if BOOST_WORKAROUND(__GNUC__, < 3)
  1910. is.setstate(::std::ios::failbit);
  1911. #else
  1912. is.setstate(::std::ios_base::failbit);
  1913. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  1914. }
  1915. }
  1916. else // error
  1917. {
  1918. #if BOOST_WORKAROUND(__GNUC__, < 3)
  1919. is.setstate(::std::ios::failbit);
  1920. #else
  1921. is.setstate(::std::ios_base::failbit);
  1922. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  1923. }
  1924. }
  1925. else // error
  1926. {
  1927. #if BOOST_WORKAROUND(__GNUC__, < 3)
  1928. is.setstate(::std::ios::failbit);
  1929. #else
  1930. is.setstate(::std::ios_base::failbit);
  1931. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  1932. }
  1933. }
  1934. else if (cc == ',') // read "((a),(c," or "((a),(e,"
  1935. {
  1936. is >> ch; // get the next lexeme
  1937. if (!is.good()) goto finish;
  1938. #ifdef BOOST_NO_STD_LOCALE
  1939. cc = ch;
  1940. #else
  1941. cc = ct.narrow(ch, char());
  1942. #endif /* BOOST_NO_STD_LOCALE */
  1943. if (cc == '(') // read "((a),(e,(" (ambiguity resolution)
  1944. {
  1945. p = ::boost::math::quaternion<T>(a);
  1946. x = ::std::complex<T>(c); // "c" was actually "e"
  1947. is.putback(ch); // we can only backtrace once
  1948. is >> y; // read "((a),(e,y"
  1949. if (!is.good()) goto finish;
  1950. is >> ch; // get the next lexeme
  1951. #ifdef BOOST_NO_STD_LOCALE
  1952. cc = ch;
  1953. #else
  1954. cc = ct.narrow(ch, char());
  1955. #endif /* BOOST_NO_STD_LOCALE */
  1956. if (cc == ')') // read "((a),(e,y)"
  1957. {
  1958. q = ::boost::math::quaternion<T>(x,y);
  1959. is >> ch; // get the next lexeme
  1960. #ifdef BOOST_NO_STD_LOCALE
  1961. cc = ch;
  1962. #else
  1963. cc = ct.narrow(ch, char());
  1964. #endif /* BOOST_NO_STD_LOCALE */
  1965. if (cc == ')') // read "((a),(e,y))"
  1966. {
  1967. o = octonion<T>(p,q);
  1968. }
  1969. else // error
  1970. {
  1971. #if BOOST_WORKAROUND(__GNUC__, < 3)
  1972. is.setstate(::std::ios::failbit);
  1973. #else
  1974. is.setstate(::std::ios_base::failbit);
  1975. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  1976. }
  1977. }
  1978. else // error
  1979. {
  1980. #if BOOST_WORKAROUND(__GNUC__, < 3)
  1981. is.setstate(::std::ios::failbit);
  1982. #else
  1983. is.setstate(::std::ios_base::failbit);
  1984. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  1985. }
  1986. }
  1987. else // read "((a),(c,d" or "((a),(e,f"
  1988. {
  1989. is.putback(ch);
  1990. is >> d;
  1991. if (!is.good()) goto finish;
  1992. is >> ch; // get the next lexeme
  1993. if (!is.good()) goto finish;
  1994. #ifdef BOOST_NO_STD_LOCALE
  1995. cc = ch;
  1996. #else
  1997. cc = ct.narrow(ch, char());
  1998. #endif /* BOOST_NO_STD_LOCALE */
  1999. if (cc == ')') // read "((a),(c,d)" (ambiguity resolution)
  2000. {
  2001. is >> ch; // get the next lexeme
  2002. if (!is.good()) goto finish;
  2003. #ifdef BOOST_NO_STD_LOCALE
  2004. cc = ch;
  2005. #else
  2006. cc = ct.narrow(ch, char());
  2007. #endif /* BOOST_NO_STD_LOCALE */
  2008. if (cc == ')') // read "((a),(c,d))"
  2009. {
  2010. o = octonion<T>(a,b,c,d);
  2011. }
  2012. else if (cc == ',') // read "((a),(c,d),"
  2013. {
  2014. u = ::std::complex<T>(a);
  2015. v = ::std::complex<T>(c,d);
  2016. is >> x; // read "((a),(c,d),x"
  2017. if (!is.good()) goto finish;
  2018. is >> ch; // get the next lexeme
  2019. if (!is.good()) goto finish;
  2020. #ifdef BOOST_NO_STD_LOCALE
  2021. cc = ch;
  2022. #else
  2023. cc = ct.narrow(ch, char());
  2024. #endif /* BOOST_NO_STD_LOCALE */
  2025. if (cc == ')') // read "((a),(c,d),x)"
  2026. {
  2027. o = octonion<T>(u,v,x);
  2028. }
  2029. else if (cc == ',') // read "((a),(c,d),x,"
  2030. {
  2031. is >> y; // read "((a),(c,d),x,y"
  2032. if (!is.good()) goto finish;
  2033. is >> ch; // get the next lexeme
  2034. if (!is.good()) goto finish;
  2035. #ifdef BOOST_NO_STD_LOCALE
  2036. cc = ch;
  2037. #else
  2038. cc = ct.narrow(ch, char());
  2039. #endif /* BOOST_NO_STD_LOCALE */
  2040. if (cc == ')') // read "((a),(c,d),x,y)"
  2041. {
  2042. o = octonion<T>(u,v,x,y);
  2043. }
  2044. else // error
  2045. {
  2046. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2047. is.setstate(::std::ios::failbit);
  2048. #else
  2049. is.setstate(::std::ios_base::failbit);
  2050. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2051. }
  2052. }
  2053. else // error
  2054. {
  2055. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2056. is.setstate(::std::ios::failbit);
  2057. #else
  2058. is.setstate(::std::ios_base::failbit);
  2059. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2060. }
  2061. }
  2062. else // error
  2063. {
  2064. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2065. is.setstate(::std::ios::failbit);
  2066. #else
  2067. is.setstate(::std::ios_base::failbit);
  2068. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2069. }
  2070. }
  2071. else if (cc == ',') // read "((a),(e,f," (ambiguity resolution)
  2072. {
  2073. p = ::boost::math::quaternion<T>(a);
  2074. is >> g; // read "((a),(e,f,g" (too late to backtrack)
  2075. if (!is.good()) goto finish;
  2076. is >> ch; // get the next lexeme
  2077. if (!is.good()) goto finish;
  2078. #ifdef BOOST_NO_STD_LOCALE
  2079. cc = ch;
  2080. #else
  2081. cc = ct.narrow(ch, char());
  2082. #endif /* BOOST_NO_STD_LOCALE */
  2083. if (cc == ')') // read "((a),(e,f,g)"
  2084. {
  2085. q = ::boost::math::quaternion<T>(c,d,g); // "c" was actually "e", and "d" was actually "f"
  2086. is >> ch; // get the next lexeme
  2087. if (!is.good()) goto finish;
  2088. #ifdef BOOST_NO_STD_LOCALE
  2089. cc = ch;
  2090. #else
  2091. cc = ct.narrow(ch, char());
  2092. #endif /* BOOST_NO_STD_LOCALE */
  2093. if (cc == ')') // read "((a),(e,f,g))"
  2094. {
  2095. o = octonion<T>(p,q);
  2096. }
  2097. else // error
  2098. {
  2099. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2100. is.setstate(::std::ios::failbit);
  2101. #else
  2102. is.setstate(::std::ios_base::failbit);
  2103. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2104. }
  2105. }
  2106. else if (cc == ',') // read "((a),(e,f,g,"
  2107. {
  2108. is >> h; // read "((a),(e,f,g,h"
  2109. if (!is.good()) goto finish;
  2110. is >> ch; // get the next lexeme
  2111. if (!is.good()) goto finish;
  2112. #ifdef BOOST_NO_STD_LOCALE
  2113. cc = ch;
  2114. #else
  2115. cc = ct.narrow(ch, char());
  2116. #endif /* BOOST_NO_STD_LOCALE */
  2117. if (cc == ')') // read "((a),(e,f,g,h)"
  2118. {
  2119. q = ::boost::math::quaternion<T>(c,d,g,h); // "c" was actually "e", and "d" was actually "f"
  2120. is >> ch; // get the next lexeme
  2121. if (!is.good()) goto finish;
  2122. #ifdef BOOST_NO_STD_LOCALE
  2123. cc = ch;
  2124. #else
  2125. cc = ct.narrow(ch, char());
  2126. #endif /* BOOST_NO_STD_LOCALE */
  2127. if (cc == ')') // read "((a),(e,f,g,h))"
  2128. {
  2129. o = octonion<T>(p,q);
  2130. }
  2131. else // error
  2132. {
  2133. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2134. is.setstate(::std::ios::failbit);
  2135. #else
  2136. is.setstate(::std::ios_base::failbit);
  2137. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2138. }
  2139. }
  2140. else // error
  2141. {
  2142. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2143. is.setstate(::std::ios::failbit);
  2144. #else
  2145. is.setstate(::std::ios_base::failbit);
  2146. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2147. }
  2148. }
  2149. else // error
  2150. {
  2151. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2152. is.setstate(::std::ios::failbit);
  2153. #else
  2154. is.setstate(::std::ios_base::failbit);
  2155. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2156. }
  2157. }
  2158. else // error
  2159. {
  2160. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2161. is.setstate(::std::ios::failbit);
  2162. #else
  2163. is.setstate(::std::ios_base::failbit);
  2164. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2165. }
  2166. }
  2167. }
  2168. else // error
  2169. {
  2170. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2171. is.setstate(::std::ios::failbit);
  2172. #else
  2173. is.setstate(::std::ios_base::failbit);
  2174. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2175. }
  2176. }
  2177. }
  2178. else // read "((a),c" (ambiguity resolution)
  2179. {
  2180. is.putback(ch);
  2181. is >> c; // we extract the third component
  2182. if (!is.good()) goto finish;
  2183. is >> ch; // get the next lexeme
  2184. if (!is.good()) goto finish;
  2185. #ifdef BOOST_NO_STD_LOCALE
  2186. cc = ch;
  2187. #else
  2188. cc = ct.narrow(ch, char());
  2189. #endif /* BOOST_NO_STD_LOCALE */
  2190. if (cc == ')') // read "((a),c)"
  2191. {
  2192. o = octonion<T>(a,b,c);
  2193. }
  2194. else if (cc == ',') // read "((a),c,"
  2195. {
  2196. is >> x; // read "((a),c,x"
  2197. if (!is.good()) goto finish;
  2198. is >> ch; // get the next lexeme
  2199. if (!is.good()) goto finish;
  2200. #ifdef BOOST_NO_STD_LOCALE
  2201. cc = ch;
  2202. #else
  2203. cc = ct.narrow(ch, char());
  2204. #endif /* BOOST_NO_STD_LOCALE */
  2205. if (cc == ')') // read "((a),c,x)"
  2206. {
  2207. o = octonion<T>(a,b,c,d,x.real(),x.imag());
  2208. }
  2209. else if (cc == ',') // read "((a),c,x,"
  2210. {
  2211. is >> y;if (!is.good()) goto finish; // read "((a),c,x,y"
  2212. is >> ch; // get the next lexeme
  2213. if (!is.good()) goto finish;
  2214. #ifdef BOOST_NO_STD_LOCALE
  2215. cc = ch;
  2216. #else
  2217. cc = ct.narrow(ch, char());
  2218. #endif /* BOOST_NO_STD_LOCALE */
  2219. if (cc == ')') // read "((a),c,x,y)"
  2220. {
  2221. o = octonion<T>(a,b,c,d,x.real(),x.imag(),y.real(),y.imag());
  2222. }
  2223. else // error
  2224. {
  2225. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2226. is.setstate(::std::ios::failbit);
  2227. #else
  2228. is.setstate(::std::ios_base::failbit);
  2229. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2230. }
  2231. }
  2232. else // error
  2233. {
  2234. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2235. is.setstate(::std::ios::failbit);
  2236. #else
  2237. is.setstate(::std::ios_base::failbit);
  2238. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2239. }
  2240. }
  2241. else // error
  2242. {
  2243. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2244. is.setstate(::std::ios::failbit);
  2245. #else
  2246. is.setstate(::std::ios_base::failbit);
  2247. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2248. }
  2249. }
  2250. }
  2251. else // error
  2252. {
  2253. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2254. is.setstate(::std::ios::failbit);
  2255. #else
  2256. is.setstate(::std::ios_base::failbit);
  2257. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2258. }
  2259. }
  2260. else if (cc ==',') // read "((a,"
  2261. {
  2262. is >> ch; // get the next lexeme
  2263. if (!is.good()) goto finish;
  2264. #ifdef BOOST_NO_STD_LOCALE
  2265. cc = ch;
  2266. #else
  2267. cc = ct.narrow(ch, char());
  2268. #endif /* BOOST_NO_STD_LOCALE */
  2269. if (cc == '(') // read "((a,("
  2270. {
  2271. u = ::std::complex<T>(a);
  2272. is.putback(ch); // can only backtrack so much
  2273. is >> v; // read "((a,v"
  2274. if (!is.good()) goto finish;
  2275. is >> ch; // get the next lexeme
  2276. if (!is.good()) goto finish;
  2277. #ifdef BOOST_NO_STD_LOCALE
  2278. cc = ch;
  2279. #else
  2280. cc = ct.narrow(ch, char());
  2281. #endif /* BOOST_NO_STD_LOCALE */
  2282. if (cc == ')') // read "((a,v)"
  2283. {
  2284. is >> ch; // get the next lexeme
  2285. if (!is.good()) goto finish;
  2286. #ifdef BOOST_NO_STD_LOCALE
  2287. cc = ch;
  2288. #else
  2289. cc = ct.narrow(ch, char());
  2290. #endif /* BOOST_NO_STD_LOCALE */
  2291. if (cc == ')') // read "((a,v))"
  2292. {
  2293. o = octonion<T>(u,v);
  2294. }
  2295. else if (cc == ',') // read "((a,v),"
  2296. {
  2297. p = ::boost::math::quaternion<T>(u,v);
  2298. is >> q; // read "((a,v),q"
  2299. if (!is.good()) goto finish;
  2300. is >> ch; // get the next lexeme
  2301. if (!is.good()) goto finish;
  2302. #ifdef BOOST_NO_STD_LOCALE
  2303. cc = ch;
  2304. #else
  2305. cc = ct.narrow(ch, char());
  2306. #endif /* BOOST_NO_STD_LOCALE */
  2307. if (cc == ')') // read "((a,v),q)"
  2308. {
  2309. o = octonion<T>(p,q);
  2310. }
  2311. else // error
  2312. {
  2313. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2314. is.setstate(::std::ios::failbit);
  2315. #else
  2316. is.setstate(::std::ios_base::failbit);
  2317. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2318. }
  2319. }
  2320. else // error
  2321. {
  2322. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2323. is.setstate(::std::ios::failbit);
  2324. #else
  2325. is.setstate(::std::ios_base::failbit);
  2326. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2327. }
  2328. }
  2329. else // error
  2330. {
  2331. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2332. is.setstate(::std::ios::failbit);
  2333. #else
  2334. is.setstate(::std::ios_base::failbit);
  2335. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2336. }
  2337. }
  2338. else
  2339. {
  2340. is.putback(ch);
  2341. is >> b; // read "((a,b"
  2342. if (!is.good()) goto finish;
  2343. is >> ch; // get the next lexeme
  2344. if (!is.good()) goto finish;
  2345. #ifdef BOOST_NO_STD_LOCALE
  2346. cc = ch;
  2347. #else
  2348. cc = ct.narrow(ch, char());
  2349. #endif /* BOOST_NO_STD_LOCALE */
  2350. if (cc == ')') // read "((a,b)"
  2351. {
  2352. is >> ch; // get the next lexeme
  2353. if (!is.good()) goto finish;
  2354. #ifdef BOOST_NO_STD_LOCALE
  2355. cc = ch;
  2356. #else
  2357. cc = ct.narrow(ch, char());
  2358. #endif /* BOOST_NO_STD_LOCALE */
  2359. if (cc == ')') // read "((a,b))"
  2360. {
  2361. o = octonion<T>(a,b);
  2362. }
  2363. else if (cc == ',') // read "((a,b),"
  2364. {
  2365. is >> ch; // get the next lexeme
  2366. if (!is.good()) goto finish;
  2367. #ifdef BOOST_NO_STD_LOCALE
  2368. cc = ch;
  2369. #else
  2370. cc = ct.narrow(ch, char());
  2371. #endif /* BOOST_NO_STD_LOCALE */
  2372. if (cc == '(') // read "((a,b),("
  2373. {
  2374. is >> ch; // get the next lexeme
  2375. if (!is.good()) goto finish;
  2376. #ifdef BOOST_NO_STD_LOCALE
  2377. cc = ch;
  2378. #else
  2379. cc = ct.narrow(ch, char());
  2380. #endif /* BOOST_NO_STD_LOCALE */
  2381. if (cc == '(') // read "((a,b),(("
  2382. {
  2383. p = ::boost::math::quaternion<T>(a,b);
  2384. is.putback(ch);
  2385. is.putback(ch); // we backtrack twice, with the same value
  2386. is >> q; // read "((a,b),q"
  2387. if (!is.good()) goto finish;
  2388. is >> ch; // get the next lexeme
  2389. if (!is.good()) goto finish;
  2390. #ifdef BOOST_NO_STD_LOCALE
  2391. cc = ch;
  2392. #else
  2393. cc = ct.narrow(ch, char());
  2394. #endif /* BOOST_NO_STD_LOCALE */
  2395. if (cc == ')') // read "((a,b),q)"
  2396. {
  2397. o = octonion<T>(p,q);
  2398. }
  2399. else // error
  2400. {
  2401. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2402. is.setstate(::std::ios::failbit);
  2403. #else
  2404. is.setstate(::std::ios_base::failbit);
  2405. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2406. }
  2407. }
  2408. else // read "((a,b),(c" or "((a,b),(e"
  2409. {
  2410. is.putback(ch);
  2411. is >> c;
  2412. if (!is.good()) goto finish;
  2413. is >> ch; // get the next lexeme
  2414. if (!is.good()) goto finish;
  2415. #ifdef BOOST_NO_STD_LOCALE
  2416. cc = ch;
  2417. #else
  2418. cc = ct.narrow(ch, char());
  2419. #endif /* BOOST_NO_STD_LOCALE */
  2420. if (cc == ')') // read "((a,b),(c)" (ambiguity resolution)
  2421. {
  2422. is >> ch; // get the next lexeme
  2423. if (!is.good()) goto finish;
  2424. #ifdef BOOST_NO_STD_LOCALE
  2425. cc = ch;
  2426. #else
  2427. cc = ct.narrow(ch, char());
  2428. #endif /* BOOST_NO_STD_LOCALE */
  2429. if (cc == ')') // read "((a,b),(c))"
  2430. {
  2431. o = octonion<T>(a,b,c);
  2432. }
  2433. else if (cc == ',') // read "((a,b),(c),"
  2434. {
  2435. u = ::std::complex<T>(a,b);
  2436. v = ::std::complex<T>(c);
  2437. is >> x; // read "((a,b),(c),x"
  2438. if (!is.good()) goto finish;
  2439. is >> ch; // get the next lexeme
  2440. if (!is.good()) goto finish;
  2441. #ifdef BOOST_NO_STD_LOCALE
  2442. cc = ch;
  2443. #else
  2444. cc = ct.narrow(ch, char());
  2445. #endif /* BOOST_NO_STD_LOCALE */
  2446. if (cc == ')') // read "((a,b),(c),x)"
  2447. {
  2448. o = octonion<T>(u,v,x);
  2449. }
  2450. else if (cc == ',') // read "((a,b),(c),x,"
  2451. {
  2452. is >> y; // read "((a,b),(c),x,y"
  2453. if (!is.good()) goto finish;
  2454. is >> ch; // get the next lexeme
  2455. if (!is.good()) goto finish;
  2456. #ifdef BOOST_NO_STD_LOCALE
  2457. cc = ch;
  2458. #else
  2459. cc = ct.narrow(ch, char());
  2460. #endif /* BOOST_NO_STD_LOCALE */
  2461. if (cc == ')') // read "((a,b),(c),x,y)"
  2462. {
  2463. o = octonion<T>(u,v,x,y);
  2464. }
  2465. else // error
  2466. {
  2467. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2468. is.setstate(::std::ios::failbit);
  2469. #else
  2470. is.setstate(::std::ios_base::failbit);
  2471. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2472. }
  2473. }
  2474. else // error
  2475. {
  2476. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2477. is.setstate(::std::ios::failbit);
  2478. #else
  2479. is.setstate(::std::ios_base::failbit);
  2480. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2481. }
  2482. }
  2483. else // error
  2484. {
  2485. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2486. is.setstate(::std::ios::failbit);
  2487. #else
  2488. is.setstate(::std::ios_base::failbit);
  2489. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2490. }
  2491. }
  2492. else if (cc == ',') // read "((a,b),(c," or "((a,b),(e,"
  2493. {
  2494. is >> ch; // get the next lexeme
  2495. if (!is.good()) goto finish;
  2496. #ifdef BOOST_NO_STD_LOCALE
  2497. cc = ch;
  2498. #else
  2499. cc = ct.narrow(ch, char());
  2500. #endif /* BOOST_NO_STD_LOCALE */
  2501. if (cc == '(') // read "((a,b),(e,(" (ambiguity resolution)
  2502. {
  2503. u = ::std::complex<T>(a,b);
  2504. x = ::std::complex<T>(c); // "c" is actually "e"
  2505. is.putback(ch);
  2506. is >> y; // read "((a,b),(e,y"
  2507. if (!is.good()) goto finish;
  2508. is >> ch; // get the next lexeme
  2509. if (!is.good()) goto finish;
  2510. #ifdef BOOST_NO_STD_LOCALE
  2511. cc = ch;
  2512. #else
  2513. cc = ct.narrow(ch, char());
  2514. #endif /* BOOST_NO_STD_LOCALE */
  2515. if (cc == ')') // read "((a,b),(e,y)"
  2516. {
  2517. is >> ch; // get the next lexeme
  2518. if (!is.good()) goto finish;
  2519. #ifdef BOOST_NO_STD_LOCALE
  2520. cc = ch;
  2521. #else
  2522. cc = ct.narrow(ch, char());
  2523. #endif /* BOOST_NO_STD_LOCALE */
  2524. if (cc == ')') // read "((a,b),(e,y))"
  2525. {
  2526. o = octonion<T>(u,v,x,y);
  2527. }
  2528. else // error
  2529. {
  2530. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2531. is.setstate(::std::ios::failbit);
  2532. #else
  2533. is.setstate(::std::ios_base::failbit);
  2534. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2535. }
  2536. }
  2537. else // error
  2538. {
  2539. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2540. is.setstate(::std::ios::failbit);
  2541. #else
  2542. is.setstate(::std::ios_base::failbit);
  2543. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2544. }
  2545. }
  2546. else // read "((a,b),(c,d" or "((a,b),(e,f"
  2547. {
  2548. is.putback(ch);
  2549. is >> d;
  2550. if (!is.good()) goto finish;
  2551. is >> ch; // get the next lexeme
  2552. if (!is.good()) goto finish;
  2553. #ifdef BOOST_NO_STD_LOCALE
  2554. cc = ch;
  2555. #else
  2556. cc = ct.narrow(ch, char());
  2557. #endif /* BOOST_NO_STD_LOCALE */
  2558. if (cc == ')') // read "((a,b),(c,d)" (ambiguity resolution)
  2559. {
  2560. u = ::std::complex<T>(a,b);
  2561. v = ::std::complex<T>(c,d);
  2562. is >> ch; // get the next lexeme
  2563. if (!is.good()) goto finish;
  2564. #ifdef BOOST_NO_STD_LOCALE
  2565. cc = ch;
  2566. #else
  2567. cc = ct.narrow(ch, char());
  2568. #endif /* BOOST_NO_STD_LOCALE */
  2569. if (cc == ')') // read "((a,b),(c,d))"
  2570. {
  2571. o = octonion<T>(u,v);
  2572. }
  2573. else if (cc == ',') // read "((a,b),(c,d),"
  2574. {
  2575. is >> x; // read "((a,b),(c,d),x
  2576. if (!is.good()) goto finish;
  2577. is >> ch; // get the next lexeme
  2578. if (!is.good()) goto finish;
  2579. #ifdef BOOST_NO_STD_LOCALE
  2580. cc = ch;
  2581. #else
  2582. cc = ct.narrow(ch, char());
  2583. #endif /* BOOST_NO_STD_LOCALE */
  2584. if (cc == ')') // read "((a,b),(c,d),x)"
  2585. {
  2586. o = octonion<T>(u,v,x);
  2587. }
  2588. else if (cc == ',') // read "((a,b),(c,d),x,"
  2589. {
  2590. is >> y; // read "((a,b),(c,d),x,y"
  2591. if (!is.good()) goto finish;
  2592. is >> ch; // get the next lexeme
  2593. if (!is.good()) goto finish;
  2594. #ifdef BOOST_NO_STD_LOCALE
  2595. cc = ch;
  2596. #else
  2597. cc = ct.narrow(ch, char());
  2598. #endif /* BOOST_NO_STD_LOCALE */
  2599. if (cc == ')') // read "((a,b),(c,d),x,y)"
  2600. {
  2601. o = octonion<T>(u,v,x,y);
  2602. }
  2603. else // error
  2604. {
  2605. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2606. is.setstate(::std::ios::failbit);
  2607. #else
  2608. is.setstate(::std::ios_base::failbit);
  2609. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2610. }
  2611. }
  2612. else // error
  2613. {
  2614. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2615. is.setstate(::std::ios::failbit);
  2616. #else
  2617. is.setstate(::std::ios_base::failbit);
  2618. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2619. }
  2620. }
  2621. else // error
  2622. {
  2623. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2624. is.setstate(::std::ios::failbit);
  2625. #else
  2626. is.setstate(::std::ios_base::failbit);
  2627. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2628. }
  2629. }
  2630. else if (cc == ',') // read "((a,b),(e,f," (ambiguity resolution)
  2631. {
  2632. p = ::boost::math::quaternion<T>(a,b); // too late to backtrack
  2633. is >> g; // read "((a,b),(e,f,g"
  2634. if (!is.good()) goto finish;
  2635. is >> ch; // get the next lexeme
  2636. if (!is.good()) goto finish;
  2637. #ifdef BOOST_NO_STD_LOCALE
  2638. cc = ch;
  2639. #else
  2640. cc = ct.narrow(ch, char());
  2641. #endif /* BOOST_NO_STD_LOCALE */
  2642. if (cc == ')') // read "((a,b),(e,f,g)"
  2643. {
  2644. is >> ch; // get the next lexeme
  2645. if (!is.good()) goto finish;
  2646. #ifdef BOOST_NO_STD_LOCALE
  2647. cc = ch;
  2648. #else
  2649. cc = ct.narrow(ch, char());
  2650. #endif /* BOOST_NO_STD_LOCALE */
  2651. if (cc == ')') // read "((a,b),(e,f,g))"
  2652. {
  2653. q = ::boost::math::quaternion<T>(c,d,g); // "c" is actually "e" and "d" is actually "f"
  2654. o = octonion<T>(p,q);
  2655. }
  2656. else // error
  2657. {
  2658. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2659. is.setstate(::std::ios::failbit);
  2660. #else
  2661. is.setstate(::std::ios_base::failbit);
  2662. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2663. }
  2664. }
  2665. else if (cc == ',') // read "((a,b),(e,f,g,"
  2666. {
  2667. is >> h; // read "((a,b),(e,f,g,h"
  2668. if (!is.good()) goto finish;
  2669. is >> ch; // get the next lexeme
  2670. if (!is.good()) goto finish;
  2671. #ifdef BOOST_NO_STD_LOCALE
  2672. cc = ch;
  2673. #else
  2674. cc = ct.narrow(ch, char());
  2675. #endif /* BOOST_NO_STD_LOCALE */
  2676. if (cc == ')') // read "((a,b),(e,f,g,h)"
  2677. {
  2678. is >> ch; // get the next lexeme
  2679. if (!is.good()) goto finish;
  2680. #ifdef BOOST_NO_STD_LOCALE
  2681. cc = ch;
  2682. #else
  2683. cc = ct.narrow(ch, char());
  2684. #endif /* BOOST_NO_STD_LOCALE */
  2685. if (cc == ')') // read ((a,b),(e,f,g,h))"
  2686. {
  2687. q = ::boost::math::quaternion<T>(c,d,g,h); // "c" is actually "e" and "d" is actually "f"
  2688. o = octonion<T>(p,q);
  2689. }
  2690. else // error
  2691. {
  2692. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2693. is.setstate(::std::ios::failbit);
  2694. #else
  2695. is.setstate(::std::ios_base::failbit);
  2696. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2697. }
  2698. }
  2699. else // error
  2700. {
  2701. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2702. is.setstate(::std::ios::failbit);
  2703. #else
  2704. is.setstate(::std::ios_base::failbit);
  2705. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2706. }
  2707. }
  2708. else // error
  2709. {
  2710. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2711. is.setstate(::std::ios::failbit);
  2712. #else
  2713. is.setstate(::std::ios_base::failbit);
  2714. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2715. }
  2716. }
  2717. else // error
  2718. {
  2719. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2720. is.setstate(::std::ios::failbit);
  2721. #else
  2722. is.setstate(::std::ios_base::failbit);
  2723. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2724. }
  2725. }
  2726. }
  2727. else // error
  2728. {
  2729. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2730. is.setstate(::std::ios::failbit);
  2731. #else
  2732. is.setstate(::std::ios_base::failbit);
  2733. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2734. }
  2735. }
  2736. }
  2737. else // error
  2738. {
  2739. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2740. is.setstate(::std::ios::failbit);
  2741. #else
  2742. is.setstate(::std::ios_base::failbit);
  2743. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2744. }
  2745. }
  2746. else // error
  2747. {
  2748. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2749. is.setstate(::std::ios::failbit);
  2750. #else
  2751. is.setstate(::std::ios_base::failbit);
  2752. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2753. }
  2754. }
  2755. else if (cc == ',') // read "((a,b,"
  2756. {
  2757. is >> c; // read "((a,b,c"
  2758. if (!is.good()) goto finish;
  2759. is >> ch; // get the next lexeme
  2760. if (!is.good()) goto finish;
  2761. #ifdef BOOST_NO_STD_LOCALE
  2762. cc = ch;
  2763. #else
  2764. cc = ct.narrow(ch, char());
  2765. #endif /* BOOST_NO_STD_LOCALE */
  2766. if (cc == ')') // read "((a,b,c)"
  2767. {
  2768. is >> ch; // get the next lexeme
  2769. if (!is.good()) goto finish;
  2770. #ifdef BOOST_NO_STD_LOCALE
  2771. cc = ch;
  2772. #else
  2773. cc = ct.narrow(ch, char());
  2774. #endif /* BOOST_NO_STD_LOCALE */
  2775. if (cc == ')') // read "((a,b,c))"
  2776. {
  2777. o = octonion<T>(a,b,c);
  2778. }
  2779. else if (cc == ',') // read "((a,b,c),"
  2780. {
  2781. p = ::boost::math::quaternion<T>(a,b,c);
  2782. is >> q; // read "((a,b,c),q"
  2783. if (!is.good()) goto finish;
  2784. is >> ch; // get the next lexeme
  2785. if (!is.good()) goto finish;
  2786. #ifdef BOOST_NO_STD_LOCALE
  2787. cc = ch;
  2788. #else
  2789. cc = ct.narrow(ch, char());
  2790. #endif /* BOOST_NO_STD_LOCALE */
  2791. if (cc == ')') // read "((a,b,c),q)"
  2792. {
  2793. o = octonion<T>(p,q);
  2794. }
  2795. else // error
  2796. {
  2797. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2798. is.setstate(::std::ios::failbit);
  2799. #else
  2800. is.setstate(::std::ios_base::failbit);
  2801. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2802. }
  2803. }
  2804. else // error
  2805. {
  2806. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2807. is.setstate(::std::ios::failbit);
  2808. #else
  2809. is.setstate(::std::ios_base::failbit);
  2810. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2811. }
  2812. }
  2813. else if (cc == ',') // read "((a,b,c,"
  2814. {
  2815. is >> d; // read "((a,b,c,d"
  2816. if (!is.good()) goto finish;
  2817. is >> ch; // get the next lexeme
  2818. if (!is.good()) goto finish;
  2819. #ifdef BOOST_NO_STD_LOCALE
  2820. cc = ch;
  2821. #else
  2822. cc = ct.narrow(ch, char());
  2823. #endif /* BOOST_NO_STD_LOCALE */
  2824. if (cc == ')') // read "((a,b,c,d)"
  2825. {
  2826. is >> ch; // get the next lexeme
  2827. if (!is.good()) goto finish;
  2828. #ifdef BOOST_NO_STD_LOCALE
  2829. cc = ch;
  2830. #else
  2831. cc = ct.narrow(ch, char());
  2832. #endif /* BOOST_NO_STD_LOCALE */
  2833. if (cc == ')') // read "((a,b,c,d))"
  2834. {
  2835. o = octonion<T>(a,b,c,d);
  2836. }
  2837. else if (cc == ',') // read "((a,b,c,d),"
  2838. {
  2839. p = ::boost::math::quaternion<T>(a,b,c,d);
  2840. is >> q; // read "((a,b,c,d),q"
  2841. if (!is.good()) goto finish;
  2842. is >> ch; // get the next lexeme
  2843. if (!is.good()) goto finish;
  2844. #ifdef BOOST_NO_STD_LOCALE
  2845. cc = ch;
  2846. #else
  2847. cc = ct.narrow(ch, char());
  2848. #endif /* BOOST_NO_STD_LOCALE */
  2849. if (cc == ')') // read "((a,b,c,d),q)"
  2850. {
  2851. o = octonion<T>(p,q);
  2852. }
  2853. else // error
  2854. {
  2855. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2856. is.setstate(::std::ios::failbit);
  2857. #else
  2858. is.setstate(::std::ios_base::failbit);
  2859. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2860. }
  2861. }
  2862. else // error
  2863. {
  2864. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2865. is.setstate(::std::ios::failbit);
  2866. #else
  2867. is.setstate(::std::ios_base::failbit);
  2868. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2869. }
  2870. }
  2871. else // error
  2872. {
  2873. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2874. is.setstate(::std::ios::failbit);
  2875. #else
  2876. is.setstate(::std::ios_base::failbit);
  2877. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2878. }
  2879. }
  2880. else // error
  2881. {
  2882. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2883. is.setstate(::std::ios::failbit);
  2884. #else
  2885. is.setstate(::std::ios_base::failbit);
  2886. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2887. }
  2888. }
  2889. else // error
  2890. {
  2891. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2892. is.setstate(::std::ios::failbit);
  2893. #else
  2894. is.setstate(::std::ios_base::failbit);
  2895. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2896. }
  2897. }
  2898. }
  2899. else // error
  2900. {
  2901. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2902. is.setstate(::std::ios::failbit);
  2903. #else
  2904. is.setstate(::std::ios_base::failbit);
  2905. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2906. }
  2907. }
  2908. }
  2909. else // read "(a"
  2910. {
  2911. is.putback(ch);
  2912. is >> a; // we extract the first component
  2913. if (!is.good()) goto finish;
  2914. is >> ch; // get the next lexeme
  2915. if (!is.good()) goto finish;
  2916. #ifdef BOOST_NO_STD_LOCALE
  2917. cc = ch;
  2918. #else
  2919. cc = ct.narrow(ch, char());
  2920. #endif /* BOOST_NO_STD_LOCALE */
  2921. if (cc == ')') // read "(a)"
  2922. {
  2923. o = octonion<T>(a);
  2924. }
  2925. else if (cc == ',') // read "(a,"
  2926. {
  2927. is >> ch; // get the next lexeme
  2928. if (!is.good()) goto finish;
  2929. #ifdef BOOST_NO_STD_LOCALE
  2930. cc = ch;
  2931. #else
  2932. cc = ct.narrow(ch, char());
  2933. #endif /* BOOST_NO_STD_LOCALE */
  2934. if (cc == '(') // read "(a,("
  2935. {
  2936. is >> ch; // get the next lexeme
  2937. if (!is.good()) goto finish;
  2938. #ifdef BOOST_NO_STD_LOCALE
  2939. cc = ch;
  2940. #else
  2941. cc = ct.narrow(ch, char());
  2942. #endif /* BOOST_NO_STD_LOCALE */
  2943. if (cc == '(') // read "(a,(("
  2944. {
  2945. p = ::boost::math::quaternion<T>(a);
  2946. is.putback(ch);
  2947. is.putback(ch); // we backtrack twice, with the same value
  2948. is >> q; // read "(a,q"
  2949. if (!is.good()) goto finish;
  2950. is >> ch; // get the next lexeme
  2951. if (!is.good()) goto finish;
  2952. #ifdef BOOST_NO_STD_LOCALE
  2953. cc = ch;
  2954. #else
  2955. cc = ct.narrow(ch, char());
  2956. #endif /* BOOST_NO_STD_LOCALE */
  2957. if (cc == ')') // read "(a,q)"
  2958. {
  2959. o = octonion<T>(p,q);
  2960. }
  2961. else // error
  2962. {
  2963. #if BOOST_WORKAROUND(__GNUC__, < 3)
  2964. is.setstate(::std::ios::failbit);
  2965. #else
  2966. is.setstate(::std::ios_base::failbit);
  2967. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  2968. }
  2969. }
  2970. else // read "(a,(c" or "(a,(e"
  2971. {
  2972. is.putback(ch);
  2973. is >> c;
  2974. if (!is.good()) goto finish;
  2975. is >> ch; // get the next lexeme
  2976. if (!is.good()) goto finish;
  2977. #ifdef BOOST_NO_STD_LOCALE
  2978. cc = ch;
  2979. #else
  2980. cc = ct.narrow(ch, char());
  2981. #endif /* BOOST_NO_STD_LOCALE */
  2982. if (cc == ')') // read "(a,(c)" (ambiguity resolution)
  2983. {
  2984. is >> ch; // get the next lexeme
  2985. if (!is.good()) goto finish;
  2986. #ifdef BOOST_NO_STD_LOCALE
  2987. cc = ch;
  2988. #else
  2989. cc = ct.narrow(ch, char());
  2990. #endif /* BOOST_NO_STD_LOCALE */
  2991. if (cc == ')') // read "(a,(c))"
  2992. {
  2993. o = octonion<T>(a,b,c);
  2994. }
  2995. else if (cc == ',') // read "(a,(c),"
  2996. {
  2997. u = ::std::complex<T>(a);
  2998. v = ::std::complex<T>(c);
  2999. is >> x; // read "(a,(c),x"
  3000. if (!is.good()) goto finish;
  3001. is >> ch; // get the next lexeme
  3002. if (!is.good()) goto finish;
  3003. #ifdef BOOST_NO_STD_LOCALE
  3004. cc = ch;
  3005. #else
  3006. cc = ct.narrow(ch, char());
  3007. #endif /* BOOST_NO_STD_LOCALE */
  3008. if (cc == ')') // read "(a,(c),x)"
  3009. {
  3010. o = octonion<T>(u,v,x);
  3011. }
  3012. else if (cc == ',') // read "(a,(c),x,"
  3013. {
  3014. is >> y; // read "(a,(c),x,y"
  3015. if (!is.good()) goto finish;
  3016. is >> ch; // get the next lexeme
  3017. if (!is.good()) goto finish;
  3018. #ifdef BOOST_NO_STD_LOCALE
  3019. cc = ch;
  3020. #else
  3021. cc = ct.narrow(ch, char());
  3022. #endif /* BOOST_NO_STD_LOCALE */
  3023. if (cc == ')') // read "(a,(c),x,y)"
  3024. {
  3025. o = octonion<T>(u,v,x,y);
  3026. }
  3027. else // error
  3028. {
  3029. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3030. is.setstate(::std::ios::failbit);
  3031. #else
  3032. is.setstate(::std::ios_base::failbit);
  3033. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3034. }
  3035. }
  3036. else // error
  3037. {
  3038. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3039. is.setstate(::std::ios::failbit);
  3040. #else
  3041. is.setstate(::std::ios_base::failbit);
  3042. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3043. }
  3044. }
  3045. else // error
  3046. {
  3047. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3048. is.setstate(::std::ios::failbit);
  3049. #else
  3050. is.setstate(::std::ios_base::failbit);
  3051. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3052. }
  3053. }
  3054. else if (cc == ',') // read "(a,(c," or "(a,(e,"
  3055. {
  3056. is >> ch; // get the next lexeme
  3057. if (!is.good()) goto finish;
  3058. #ifdef BOOST_NO_STD_LOCALE
  3059. cc = ch;
  3060. #else
  3061. cc = ct.narrow(ch, char());
  3062. #endif /* BOOST_NO_STD_LOCALE */
  3063. if (cc == '(') // read "(a,(e,(" (ambiguity resolution)
  3064. {
  3065. u = ::std::complex<T>(a);
  3066. x = ::std::complex<T>(c); // "c" is actually "e"
  3067. is.putback(ch); // we backtrack
  3068. is >> y; // read "(a,(e,y"
  3069. if (!is.good()) goto finish;
  3070. is >> ch; // get the next lexeme
  3071. if (!is.good()) goto finish;
  3072. #ifdef BOOST_NO_STD_LOCALE
  3073. cc = ch;
  3074. #else
  3075. cc = ct.narrow(ch, char());
  3076. #endif /* BOOST_NO_STD_LOCALE */
  3077. if (cc == ')') // read "(a,(e,y)"
  3078. {
  3079. is >> ch; // get the next lexeme
  3080. if (!is.good()) goto finish;
  3081. #ifdef BOOST_NO_STD_LOCALE
  3082. cc = ch;
  3083. #else
  3084. cc = ct.narrow(ch, char());
  3085. #endif /* BOOST_NO_STD_LOCALE */
  3086. if (cc == ')') // read "(a,(e,y))"
  3087. {
  3088. o = octonion<T>(u,v,x,y);
  3089. }
  3090. else // error
  3091. {
  3092. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3093. is.setstate(::std::ios::failbit);
  3094. #else
  3095. is.setstate(::std::ios_base::failbit);
  3096. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3097. }
  3098. }
  3099. else // error
  3100. {
  3101. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3102. is.setstate(::std::ios::failbit);
  3103. #else
  3104. is.setstate(::std::ios_base::failbit);
  3105. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3106. }
  3107. }
  3108. else // read "(a,(c,d" or "(a,(e,f"
  3109. {
  3110. is.putback(ch);
  3111. is >> d;
  3112. if (!is.good()) goto finish;
  3113. is >> ch; // get the next lexeme
  3114. if (!is.good()) goto finish;
  3115. #ifdef BOOST_NO_STD_LOCALE
  3116. cc = ch;
  3117. #else
  3118. cc = ct.narrow(ch, char());
  3119. #endif /* BOOST_NO_STD_LOCALE */
  3120. if (cc == ')') // read "(a,(c,d)" (ambiguity resolution)
  3121. {
  3122. is >> ch; // get the next lexeme
  3123. if (!is.good()) goto finish;
  3124. #ifdef BOOST_NO_STD_LOCALE
  3125. cc = ch;
  3126. #else
  3127. cc = ct.narrow(ch, char());
  3128. #endif /* BOOST_NO_STD_LOCALE */
  3129. if (cc == ')') // read "(a,(c,d))"
  3130. {
  3131. o = octonion<T>(a,b,c,d);
  3132. }
  3133. else if (cc == ',') // read "(a,(c,d),"
  3134. {
  3135. u = ::std::complex<T>(a);
  3136. v = ::std::complex<T>(c,d);
  3137. is >> x; // read "(a,(c,d),x"
  3138. if (!is.good()) goto finish;
  3139. is >> ch; // get the next lexeme
  3140. if (!is.good()) goto finish;
  3141. #ifdef BOOST_NO_STD_LOCALE
  3142. cc = ch;
  3143. #else
  3144. cc = ct.narrow(ch, char());
  3145. #endif /* BOOST_NO_STD_LOCALE */
  3146. if (cc == ')') // read "(a,(c,d),x)"
  3147. {
  3148. o = octonion<T>(u,v,x);
  3149. }
  3150. else if (cc == ',') // read "(a,(c,d),x,"
  3151. {
  3152. is >> y; // read "(a,(c,d),x,y"
  3153. if (!is.good()) goto finish;
  3154. is >> ch; // get the next lexeme
  3155. if (!is.good()) goto finish;
  3156. #ifdef BOOST_NO_STD_LOCALE
  3157. cc = ch;
  3158. #else
  3159. cc = ct.narrow(ch, char());
  3160. #endif /* BOOST_NO_STD_LOCALE */
  3161. if (cc == ')') // read "(a,(c,d),x,y)"
  3162. {
  3163. o = octonion<T>(u,v,x,y);
  3164. }
  3165. else // error
  3166. {
  3167. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3168. is.setstate(::std::ios::failbit);
  3169. #else
  3170. is.setstate(::std::ios_base::failbit);
  3171. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3172. }
  3173. }
  3174. else // error
  3175. {
  3176. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3177. is.setstate(::std::ios::failbit);
  3178. #else
  3179. is.setstate(::std::ios_base::failbit);
  3180. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3181. }
  3182. }
  3183. else // error
  3184. {
  3185. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3186. is.setstate(::std::ios::failbit);
  3187. #else
  3188. is.setstate(::std::ios_base::failbit);
  3189. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3190. }
  3191. }
  3192. else if (cc == ',') // read "(a,(e,f," (ambiguity resolution)
  3193. {
  3194. p = ::boost::math::quaternion<T>(a);
  3195. is >> g; // read "(a,(e,f,g"
  3196. if (!is.good()) goto finish;
  3197. is >> ch; // get the next lexeme
  3198. if (!is.good()) goto finish;
  3199. #ifdef BOOST_NO_STD_LOCALE
  3200. cc = ch;
  3201. #else
  3202. cc = ct.narrow(ch, char());
  3203. #endif /* BOOST_NO_STD_LOCALE */
  3204. if (cc == ')') // read "(a,(e,f,g)"
  3205. {
  3206. is >> ch; // get the next lexeme
  3207. if (!is.good()) goto finish;
  3208. #ifdef BOOST_NO_STD_LOCALE
  3209. cc = ch;
  3210. #else
  3211. cc = ct.narrow(ch, char());
  3212. #endif /* BOOST_NO_STD_LOCALE */
  3213. if (cc == ')') // read "(a,(e,f,g))"
  3214. {
  3215. q = ::boost::math::quaternion<T>(c,d,g); // "c" is actually "e" and "d" is actually "f"
  3216. o = octonion<T>(p,q);
  3217. }
  3218. else // error
  3219. {
  3220. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3221. is.setstate(::std::ios::failbit);
  3222. #else
  3223. is.setstate(::std::ios_base::failbit);
  3224. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3225. }
  3226. }
  3227. else if (cc == ',') // read "(a,(e,f,g,"
  3228. {
  3229. is >> h; // read "(a,(e,f,g,h"
  3230. if (!is.good()) goto finish;
  3231. is >> ch; // get the next lexeme
  3232. if (!is.good()) goto finish;
  3233. #ifdef BOOST_NO_STD_LOCALE
  3234. cc = ch;
  3235. #else
  3236. cc = ct.narrow(ch, char());
  3237. #endif /* BOOST_NO_STD_LOCALE */
  3238. if (cc == ')') // read "(a,(e,f,g,h)"
  3239. {
  3240. is >> ch; // get the next lexeme
  3241. if (!is.good()) goto finish;
  3242. #ifdef BOOST_NO_STD_LOCALE
  3243. cc = ch;
  3244. #else
  3245. cc = ct.narrow(ch, char());
  3246. #endif /* BOOST_NO_STD_LOCALE */
  3247. if (cc == ')') // read "(a,(e,f,g,h))"
  3248. {
  3249. q = ::boost::math::quaternion<T>(c,d,g,h); // "c" is actually "e" and "d" is actually "f"
  3250. o = octonion<T>(p,q);
  3251. }
  3252. else // error
  3253. {
  3254. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3255. is.setstate(::std::ios::failbit);
  3256. #else
  3257. is.setstate(::std::ios_base::failbit);
  3258. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3259. }
  3260. }
  3261. else // error
  3262. {
  3263. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3264. is.setstate(::std::ios::failbit);
  3265. #else
  3266. is.setstate(::std::ios_base::failbit);
  3267. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3268. }
  3269. }
  3270. else // error
  3271. {
  3272. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3273. is.setstate(::std::ios::failbit);
  3274. #else
  3275. is.setstate(::std::ios_base::failbit);
  3276. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3277. }
  3278. }
  3279. else // error
  3280. {
  3281. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3282. is.setstate(::std::ios::failbit);
  3283. #else
  3284. is.setstate(::std::ios_base::failbit);
  3285. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3286. }
  3287. }
  3288. }
  3289. else // error
  3290. {
  3291. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3292. is.setstate(::std::ios::failbit);
  3293. #else
  3294. is.setstate(::std::ios_base::failbit);
  3295. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3296. }
  3297. }
  3298. }
  3299. else // read "(a,b" or "(a,c" (ambiguity resolution)
  3300. {
  3301. is.putback(ch);
  3302. is >> b;
  3303. if (!is.good()) goto finish;
  3304. is >> ch; // get the next lexeme
  3305. if (!is.good()) goto finish;
  3306. #ifdef BOOST_NO_STD_LOCALE
  3307. cc = ch;
  3308. #else
  3309. cc = ct.narrow(ch, char());
  3310. #endif /* BOOST_NO_STD_LOCALE */
  3311. if (cc == ')') // read "(a,b)" (ambiguity resolution)
  3312. {
  3313. o = octonion<T>(a,b);
  3314. }
  3315. else if (cc == ',') // read "(a,b," or "(a,c,"
  3316. {
  3317. is >> ch; // get the next lexeme
  3318. if (!is.good()) goto finish;
  3319. #ifdef BOOST_NO_STD_LOCALE
  3320. cc = ch;
  3321. #else
  3322. cc = ct.narrow(ch, char());
  3323. #endif /* BOOST_NO_STD_LOCALE */
  3324. if (cc == '(') // read "(a,c,(" (ambiguity resolution)
  3325. {
  3326. u = ::std::complex<T>(a);
  3327. v = ::std::complex<T>(b); // "b" is actually "c"
  3328. is.putback(ch); // we backtrack
  3329. is >> x; // read "(a,c,x"
  3330. if (!is.good()) goto finish;
  3331. is >> ch; // get the next lexeme
  3332. if (!is.good()) goto finish;
  3333. #ifdef BOOST_NO_STD_LOCALE
  3334. cc = ch;
  3335. #else
  3336. cc = ct.narrow(ch, char());
  3337. #endif /* BOOST_NO_STD_LOCALE */
  3338. if (cc == ')') // read "(a,c,x)"
  3339. {
  3340. o = octonion<T>(u,v,x);
  3341. }
  3342. else if (cc == ',') // read "(a,c,x,"
  3343. {
  3344. is >> y; // read "(a,c,x,y" // read "(a,c,x"
  3345. if (!is.good()) goto finish;
  3346. is >> ch; // get the next lexeme
  3347. if (!is.good()) goto finish;
  3348. #ifdef BOOST_NO_STD_LOCALE
  3349. cc = ch;
  3350. #else
  3351. cc = ct.narrow(ch, char());
  3352. #endif /* BOOST_NO_STD_LOCALE */
  3353. if (cc == ')') // read "(a,c,x,y)"
  3354. {
  3355. o = octonion<T>(u,v,x,y);
  3356. }
  3357. else // error
  3358. {
  3359. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3360. is.setstate(::std::ios::failbit);
  3361. #else
  3362. is.setstate(::std::ios_base::failbit);
  3363. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3364. }
  3365. }
  3366. else // error
  3367. {
  3368. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3369. is.setstate(::std::ios::failbit);
  3370. #else
  3371. is.setstate(::std::ios_base::failbit);
  3372. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3373. }
  3374. }
  3375. else // read "(a,b,c" or "(a,c,e"
  3376. {
  3377. is.putback(ch);
  3378. is >> c;
  3379. if (!is.good()) goto finish;
  3380. is >> ch; // get the next lexeme
  3381. if (!is.good()) goto finish;
  3382. #ifdef BOOST_NO_STD_LOCALE
  3383. cc = ch;
  3384. #else
  3385. cc = ct.narrow(ch, char());
  3386. #endif /* BOOST_NO_STD_LOCALE */
  3387. if (cc == ')') // read "(a,b,c)" (ambiguity resolution)
  3388. {
  3389. o = octonion<T>(a,b,c);
  3390. }
  3391. else if (cc == ',') // read "(a,b,c," or "(a,c,e,"
  3392. {
  3393. is >> ch; // get the next lexeme
  3394. if (!is.good()) goto finish;
  3395. #ifdef BOOST_NO_STD_LOCALE
  3396. cc = ch;
  3397. #else
  3398. cc = ct.narrow(ch, char());
  3399. #endif /* BOOST_NO_STD_LOCALE */
  3400. if (cc == '(') // read "(a,c,e,(") (ambiguity resolution)
  3401. {
  3402. u = ::std::complex<T>(a);
  3403. v = ::std::complex<T>(b); // "b" is actually "c"
  3404. x = ::std::complex<T>(c); // "c" is actually "e"
  3405. is.putback(ch); // we backtrack
  3406. is >> y; // read "(a,c,e,y"
  3407. if (!is.good()) goto finish;
  3408. is >> ch; // get the next lexeme
  3409. if (!is.good()) goto finish;
  3410. #ifdef BOOST_NO_STD_LOCALE
  3411. cc = ch;
  3412. #else
  3413. cc = ct.narrow(ch, char());
  3414. #endif /* BOOST_NO_STD_LOCALE */
  3415. if (cc == ')') // read "(a,c,e,y)"
  3416. {
  3417. o = octonion<T>(u,v,x,y);
  3418. }
  3419. else // error
  3420. {
  3421. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3422. is.setstate(::std::ios::failbit);
  3423. #else
  3424. is.setstate(::std::ios_base::failbit);
  3425. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3426. }
  3427. }
  3428. else // read "(a,b,c,d" (ambiguity resolution)
  3429. {
  3430. is.putback(ch); // we backtrack
  3431. is >> d;
  3432. if (!is.good()) goto finish;
  3433. is >> ch; // get the next lexeme
  3434. if (!is.good()) goto finish;
  3435. #ifdef BOOST_NO_STD_LOCALE
  3436. cc = ch;
  3437. #else
  3438. cc = ct.narrow(ch, char());
  3439. #endif /* BOOST_NO_STD_LOCALE */
  3440. if (cc == ')') // read "(a,b,c,d)"
  3441. {
  3442. o = octonion<T>(a,b,c,d);
  3443. }
  3444. else if (cc == ',') // read "(a,b,c,d,"
  3445. {
  3446. is >> e; // read "(a,b,c,d,e"
  3447. if (!is.good()) goto finish;
  3448. is >> ch; // get the next lexeme
  3449. if (!is.good()) goto finish;
  3450. #ifdef BOOST_NO_STD_LOCALE
  3451. cc = ch;
  3452. #else
  3453. cc = ct.narrow(ch, char());
  3454. #endif /* BOOST_NO_STD_LOCALE */
  3455. if (cc == ')') // read "(a,b,c,d,e)"
  3456. {
  3457. o = octonion<T>(a,b,c,d,e);
  3458. }
  3459. else if (cc == ',') // read "(a,b,c,d,e,"
  3460. {
  3461. is >> f; // read "(a,b,c,d,e,f"
  3462. if (!is.good()) goto finish;
  3463. is >> ch; // get the next lexeme
  3464. if (!is.good()) goto finish;
  3465. #ifdef BOOST_NO_STD_LOCALE
  3466. cc = ch;
  3467. #else
  3468. cc = ct.narrow(ch, char());
  3469. #endif /* BOOST_NO_STD_LOCALE */
  3470. if (cc == ')') // read "(a,b,c,d,e,f)"
  3471. {
  3472. o = octonion<T>(a,b,c,d,e,f);
  3473. }
  3474. else if (cc == ',') // read "(a,b,c,d,e,f,"
  3475. {
  3476. is >> g; // read "(a,b,c,d,e,f,g" // read "(a,b,c,d,e,f"
  3477. if (!is.good()) goto finish;
  3478. is >> ch; // get the next lexeme
  3479. if (!is.good()) goto finish;
  3480. #ifdef BOOST_NO_STD_LOCALE
  3481. cc = ch;
  3482. #else
  3483. cc = ct.narrow(ch, char());
  3484. #endif /* BOOST_NO_STD_LOCALE */
  3485. if (cc == ')') // read "(a,b,c,d,e,f,g)"
  3486. {
  3487. o = octonion<T>(a,b,c,d,e,f,g);
  3488. }
  3489. else if (cc == ',') // read "(a,b,c,d,e,f,g,"
  3490. {
  3491. 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"
  3492. if (!is.good()) goto finish;
  3493. is >> ch; // get the next lexeme
  3494. if (!is.good()) goto finish;
  3495. #ifdef BOOST_NO_STD_LOCALE
  3496. cc = ch;
  3497. #else
  3498. cc = ct.narrow(ch, char());
  3499. #endif /* BOOST_NO_STD_LOCALE */
  3500. if (cc == ')') // read "(a,b,c,d,e,f,g,h)"
  3501. {
  3502. o = octonion<T>(a,b,c,d,e,f,g,h);
  3503. }
  3504. else // error
  3505. {
  3506. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3507. is.setstate(::std::ios::failbit);
  3508. #else
  3509. is.setstate(::std::ios_base::failbit);
  3510. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3511. }
  3512. }
  3513. else // error
  3514. {
  3515. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3516. is.setstate(::std::ios::failbit);
  3517. #else
  3518. is.setstate(::std::ios_base::failbit);
  3519. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3520. }
  3521. }
  3522. else // error
  3523. {
  3524. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3525. is.setstate(::std::ios::failbit);
  3526. #else
  3527. is.setstate(::std::ios_base::failbit);
  3528. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3529. }
  3530. }
  3531. else // error
  3532. {
  3533. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3534. is.setstate(::std::ios::failbit);
  3535. #else
  3536. is.setstate(::std::ios_base::failbit);
  3537. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3538. }
  3539. }
  3540. else // error
  3541. {
  3542. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3543. is.setstate(::std::ios::failbit);
  3544. #else
  3545. is.setstate(::std::ios_base::failbit);
  3546. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3547. }
  3548. }
  3549. }
  3550. else // error
  3551. {
  3552. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3553. is.setstate(::std::ios::failbit);
  3554. #else
  3555. is.setstate(::std::ios_base::failbit);
  3556. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3557. }
  3558. }
  3559. }
  3560. else // error
  3561. {
  3562. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3563. is.setstate(::std::ios::failbit);
  3564. #else
  3565. is.setstate(::std::ios_base::failbit);
  3566. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3567. }
  3568. }
  3569. }
  3570. else // error
  3571. {
  3572. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3573. is.setstate(::std::ios::failbit);
  3574. #else
  3575. is.setstate(::std::ios_base::failbit);
  3576. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3577. }
  3578. }
  3579. }
  3580. else // format: a
  3581. {
  3582. is.putback(ch);
  3583. is >> a; // we extract the first component
  3584. if (!is.good()) goto finish;
  3585. o = octonion<T>(a);
  3586. }
  3587. finish:
  3588. return(is);
  3589. }
  3590. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3591. template<typename T>
  3592. ::std::ostream & operator << ( ::std::ostream & os,
  3593. octonion<T> const & o)
  3594. #else
  3595. template<typename T, typename charT, class traits>
  3596. ::std::basic_ostream<charT,traits> & operator << ( ::std::basic_ostream<charT,traits> & os,
  3597. octonion<T> const & o)
  3598. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3599. {
  3600. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3601. ::std::ostringstream s;
  3602. #else
  3603. ::std::basic_ostringstream<charT,traits> s;
  3604. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3605. s.flags(os.flags());
  3606. #ifdef BOOST_NO_STD_LOCALE
  3607. #else
  3608. s.imbue(os.getloc());
  3609. #endif /* BOOST_NO_STD_LOCALE */
  3610. s.precision(os.precision());
  3611. s << '(' << o.R_component_1() << ','
  3612. << o.R_component_2() << ','
  3613. << o.R_component_3() << ','
  3614. << o.R_component_4() << ','
  3615. << o.R_component_5() << ','
  3616. << o.R_component_6() << ','
  3617. << o.R_component_7() << ','
  3618. << o.R_component_8() << ')';
  3619. return os << s.str();
  3620. }
  3621. // values
  3622. template<typename T>
  3623. inline T real(octonion<T> const & o)
  3624. {
  3625. return(o.real());
  3626. }
  3627. template<typename T>
  3628. inline octonion<T> unreal(octonion<T> const & o)
  3629. {
  3630. return(o.unreal());
  3631. }
  3632. #define BOOST_OCTONION_VALARRAY_LOADER \
  3633. using ::std::valarray; \
  3634. \
  3635. valarray<T> temp(8); \
  3636. \
  3637. temp[0] = o.R_component_1(); \
  3638. temp[1] = o.R_component_2(); \
  3639. temp[2] = o.R_component_3(); \
  3640. temp[3] = o.R_component_4(); \
  3641. temp[4] = o.R_component_5(); \
  3642. temp[5] = o.R_component_6(); \
  3643. temp[6] = o.R_component_7(); \
  3644. temp[7] = o.R_component_8();
  3645. template<typename T>
  3646. inline T sup(octonion<T> const & o)
  3647. {
  3648. #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
  3649. using ::std::abs;
  3650. #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */
  3651. BOOST_OCTONION_VALARRAY_LOADER
  3652. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3653. return((BOOST_GET_VALARRAY(T, abs(temp)).max)());
  3654. #else
  3655. return((abs(temp).max)());
  3656. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3657. }
  3658. template<typename T>
  3659. inline T l1(octonion<T> const & o)
  3660. {
  3661. #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
  3662. using ::std::abs;
  3663. #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */
  3664. BOOST_OCTONION_VALARRAY_LOADER
  3665. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3666. return(BOOST_GET_VALARRAY(T, abs(temp)).sum());
  3667. #else
  3668. return(abs(temp).sum());
  3669. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3670. }
  3671. template<typename T>
  3672. inline T abs(const octonion<T> & o)
  3673. {
  3674. #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
  3675. using ::std::abs;
  3676. #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */
  3677. using ::std::sqrt;
  3678. BOOST_OCTONION_VALARRAY_LOADER
  3679. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3680. T maxim = (BOOST_GET_VALARRAY(T,abs(temp)).max)(); // overflow protection
  3681. #else
  3682. T maxim = (abs(temp).max)(); // overflow protection
  3683. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3684. if (maxim == static_cast<T>(0))
  3685. {
  3686. return(maxim);
  3687. }
  3688. else
  3689. {
  3690. T mixam = static_cast<T>(1)/maxim; // prefer multiplications over divisions
  3691. temp *= mixam;
  3692. temp *= temp;
  3693. return(maxim*sqrt(temp.sum()));
  3694. }
  3695. //return(::std::sqrt(norm(o)));
  3696. }
  3697. #undef BOOST_OCTONION_VALARRAY_LOADER
  3698. // Note: This is the Cayley norm, not the Euclidian norm...
  3699. template<typename T>
  3700. inline T norm(octonion<T> const & o)
  3701. {
  3702. return(real(o*conj(o)));
  3703. }
  3704. template<typename T>
  3705. inline octonion<T> conj(octonion<T> const & o)
  3706. {
  3707. return(octonion<T>( +o.R_component_1(),
  3708. -o.R_component_2(),
  3709. -o.R_component_3(),
  3710. -o.R_component_4(),
  3711. -o.R_component_5(),
  3712. -o.R_component_6(),
  3713. -o.R_component_7(),
  3714. -o.R_component_8()));
  3715. }
  3716. // Note: There is little point, for the octonions, to introduce the equivalents
  3717. // to the complex "arg" and the quaternionic "cylindropolar".
  3718. template<typename T>
  3719. inline octonion<T> spherical(T const & rho,
  3720. T const & theta,
  3721. T const & phi1,
  3722. T const & phi2,
  3723. T const & phi3,
  3724. T const & phi4,
  3725. T const & phi5,
  3726. T const & phi6)
  3727. {
  3728. using ::std::cos;
  3729. using ::std::sin;
  3730. //T a = cos(theta)*cos(phi1)*cos(phi2)*cos(phi3)*cos(phi4)*cos(phi5)*cos(phi6);
  3731. //T b = sin(theta)*cos(phi1)*cos(phi2)*cos(phi3)*cos(phi4)*cos(phi5)*cos(phi6);
  3732. //T c = sin(phi1)*cos(phi2)*cos(phi3)*cos(phi4)*cos(phi5)*cos(phi6);
  3733. //T d = sin(phi2)*cos(phi3)*cos(phi4)*cos(phi5)*cos(phi6);
  3734. //T e = sin(phi3)*cos(phi4)*cos(phi5)*cos(phi6);
  3735. //T f = sin(phi4)*cos(phi5)*cos(phi6);
  3736. //T g = sin(phi5)*cos(phi6);
  3737. //T h = sin(phi6);
  3738. T courrant = static_cast<T>(1);
  3739. T h = sin(phi6);
  3740. courrant *= cos(phi6);
  3741. T g = sin(phi5)*courrant;
  3742. courrant *= cos(phi5);
  3743. T f = sin(phi4)*courrant;
  3744. courrant *= cos(phi4);
  3745. T e = sin(phi3)*courrant;
  3746. courrant *= cos(phi3);
  3747. T d = sin(phi2)*courrant;
  3748. courrant *= cos(phi2);
  3749. T c = sin(phi1)*courrant;
  3750. courrant *= cos(phi1);
  3751. T b = sin(theta)*courrant;
  3752. T a = cos(theta)*courrant;
  3753. return(rho*octonion<T>(a,b,c,d,e,f,g,h));
  3754. }
  3755. template<typename T>
  3756. inline octonion<T> multipolar(T const & rho1,
  3757. T const & theta1,
  3758. T const & rho2,
  3759. T const & theta2,
  3760. T const & rho3,
  3761. T const & theta3,
  3762. T const & rho4,
  3763. T const & theta4)
  3764. {
  3765. using ::std::cos;
  3766. using ::std::sin;
  3767. T a = rho1*cos(theta1);
  3768. T b = rho1*sin(theta1);
  3769. T c = rho2*cos(theta2);
  3770. T d = rho2*sin(theta2);
  3771. T e = rho3*cos(theta3);
  3772. T f = rho3*sin(theta3);
  3773. T g = rho4*cos(theta4);
  3774. T h = rho4*sin(theta4);
  3775. return(octonion<T>(a,b,c,d,e,f,g,h));
  3776. }
  3777. template<typename T>
  3778. inline octonion<T> cylindrical(T const & r,
  3779. T const & angle,
  3780. T const & h1,
  3781. T const & h2,
  3782. T const & h3,
  3783. T const & h4,
  3784. T const & h5,
  3785. T const & h6)
  3786. {
  3787. using ::std::cos;
  3788. using ::std::sin;
  3789. T a = r*cos(angle);
  3790. T b = r*sin(angle);
  3791. return(octonion<T>(a,b,h1,h2,h3,h4,h5,h6));
  3792. }
  3793. template<typename T>
  3794. inline octonion<T> exp(octonion<T> const & o)
  3795. {
  3796. using ::std::exp;
  3797. using ::std::cos;
  3798. using ::boost::math::sinc_pi;
  3799. T u = exp(real(o));
  3800. T z = abs(unreal(o));
  3801. T w = sinc_pi(z);
  3802. return(u*octonion<T>(cos(z),
  3803. w*o.R_component_2(), w*o.R_component_3(),
  3804. w*o.R_component_4(), w*o.R_component_5(),
  3805. w*o.R_component_6(), w*o.R_component_7(),
  3806. w*o.R_component_8()));
  3807. }
  3808. template<typename T>
  3809. inline octonion<T> cos(octonion<T> const & o)
  3810. {
  3811. using ::std::sin;
  3812. using ::std::cos;
  3813. using ::std::cosh;
  3814. using ::boost::math::sinhc_pi;
  3815. T z = abs(unreal(o));
  3816. T w = -sin(o.real())*sinhc_pi(z);
  3817. return(octonion<T>(cos(o.real())*cosh(z),
  3818. w*o.R_component_2(), w*o.R_component_3(),
  3819. w*o.R_component_4(), w*o.R_component_5(),
  3820. w*o.R_component_6(), w*o.R_component_7(),
  3821. w*o.R_component_8()));
  3822. }
  3823. template<typename T>
  3824. inline octonion<T> sin(octonion<T> const & o)
  3825. {
  3826. using ::std::sin;
  3827. using ::std::cos;
  3828. using ::std::cosh;
  3829. using ::boost::math::sinhc_pi;
  3830. T z = abs(unreal(o));
  3831. T w = +cos(o.real())*sinhc_pi(z);
  3832. return(octonion<T>(sin(o.real())*cosh(z),
  3833. w*o.R_component_2(), w*o.R_component_3(),
  3834. w*o.R_component_4(), w*o.R_component_5(),
  3835. w*o.R_component_6(), w*o.R_component_7(),
  3836. w*o.R_component_8()));
  3837. }
  3838. template<typename T>
  3839. inline octonion<T> tan(octonion<T> const & o)
  3840. {
  3841. return(sin(o)/cos(o));
  3842. }
  3843. template<typename T>
  3844. inline octonion<T> cosh(octonion<T> const & o)
  3845. {
  3846. return((exp(+o)+exp(-o))/static_cast<T>(2));
  3847. }
  3848. template<typename T>
  3849. inline octonion<T> sinh(octonion<T> const & o)
  3850. {
  3851. return((exp(+o)-exp(-o))/static_cast<T>(2));
  3852. }
  3853. template<typename T>
  3854. inline octonion<T> tanh(octonion<T> const & o)
  3855. {
  3856. return(sinh(o)/cosh(o));
  3857. }
  3858. template<typename T>
  3859. octonion<T> pow(octonion<T> const & o,
  3860. int n)
  3861. {
  3862. if (n > 1)
  3863. {
  3864. int m = n>>1;
  3865. octonion<T> result = pow(o, m);
  3866. result *= result;
  3867. if (n != (m<<1))
  3868. {
  3869. result *= o; // n odd
  3870. }
  3871. return(result);
  3872. }
  3873. else if (n == 1)
  3874. {
  3875. return(o);
  3876. }
  3877. else if (n == 0)
  3878. {
  3879. return(octonion<T>(1));
  3880. }
  3881. else /* n < 0 */
  3882. {
  3883. return(pow(octonion<T>(1)/o,-n));
  3884. }
  3885. }
  3886. // helper templates for converting copy constructors (definition)
  3887. namespace detail
  3888. {
  3889. template< typename T,
  3890. typename U
  3891. >
  3892. octonion<T> octonion_type_converter(octonion<U> const & rhs)
  3893. {
  3894. return(octonion<T>( static_cast<T>(rhs.R_component_1()),
  3895. static_cast<T>(rhs.R_component_2()),
  3896. static_cast<T>(rhs.R_component_3()),
  3897. static_cast<T>(rhs.R_component_4()),
  3898. static_cast<T>(rhs.R_component_5()),
  3899. static_cast<T>(rhs.R_component_6()),
  3900. static_cast<T>(rhs.R_component_7()),
  3901. static_cast<T>(rhs.R_component_8())));
  3902. }
  3903. }
  3904. }
  3905. }
  3906. #if BOOST_WORKAROUND(__GNUC__, < 3)
  3907. #undef BOOST_GET_VALARRAY
  3908. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  3909. #endif /* BOOST_OCTONION_HPP */