PageRenderTime 25ms CodeModel.GetById 20ms RepoModel.GetById 0ms 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

Large files files are truncated, but you can click here to view the full file

  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; \

Large files files are truncated, but you can click here to view the full file