octonion_test.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. // test file for octonion.hpp
  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. #include <iomanip>
  7. #include <boost/mpl/list.hpp>
  8. #include <boost/test/unit_test.hpp>
  9. #include <boost/test/unit_test_log.hpp>
  10. #include <boost/math/octonion.hpp>
  11. template<typename T>
  12. struct string_type_name;
  13. #define DEFINE_TYPE_NAME(Type) \
  14. template<> struct string_type_name<Type> \
  15. { \
  16. static char const * _() \
  17. { \
  18. return #Type; \
  19. } \
  20. }
  21. DEFINE_TYPE_NAME(float);
  22. DEFINE_TYPE_NAME(double);
  23. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  24. DEFINE_TYPE_NAME(long double);
  25. #endif
  26. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  27. typedef boost::mpl::list<float,double,long double> test_types;
  28. #else
  29. typedef boost::mpl::list<float,double> test_types;
  30. #endif
  31. // Apple GCC 4.0 uses the "double double" format for its long double,
  32. // which means that epsilon is VERY small but useless for
  33. // comparisons. So, don't do those comparisons.
  34. #if (defined(__APPLE_CC__) && defined(__GNUC__) && __GNUC__ == 4) || defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
  35. typedef boost::mpl::list<float,double> near_eps_test_types;
  36. #else
  37. typedef boost::mpl::list<float,double,long double> near_eps_test_types;
  38. #endif
  39. #if BOOST_WORKAROUND(__GNUC__, < 3)
  40. // gcc 2.x ignores function scope using declarations,
  41. // put them in the scope of the enclosing namespace instead:
  42. using ::std::sqrt;
  43. using ::std::atan;
  44. using ::std::log;
  45. using ::std::exp;
  46. using ::std::cos;
  47. using ::std::sin;
  48. using ::std::tan;
  49. using ::std::cosh;
  50. using ::std::sinh;
  51. using ::std::tanh;
  52. using ::std::numeric_limits;
  53. using ::boost::math::abs;
  54. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  55. #ifdef BOOST_NO_STDC_NAMESPACE
  56. using ::sqrt;
  57. using ::atan;
  58. using ::log;
  59. using ::exp;
  60. using ::cos;
  61. using ::sin;
  62. using ::tan;
  63. using ::cosh;
  64. using ::sinh;
  65. using ::tanh;
  66. #endif /* BOOST_NO_STDC_NAMESPACE */
  67. #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
  68. using ::boost::math::real;
  69. using ::boost::math::unreal;
  70. using ::boost::math::sup;
  71. using ::boost::math::l1;
  72. using ::boost::math::abs;
  73. using ::boost::math::norm;
  74. using ::boost::math::conj;
  75. using ::boost::math::exp;
  76. using ::boost::math::pow;
  77. using ::boost::math::cos;
  78. using ::boost::math::sin;
  79. using ::boost::math::tan;
  80. using ::boost::math::cosh;
  81. using ::boost::math::sinh;
  82. using ::boost::math::tanh;
  83. using ::boost::math::sinc_pi;
  84. using ::boost::math::sinhc_pi;
  85. #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */
  86. // Provide standard floating point abs() overloads if older Microsoft
  87. // library is used with _MSC_EXTENSIONS defined. This code also works
  88. // for the Intel compiler using the Microsoft library.
  89. #if defined(_MSC_EXTENSIONS) && defined(_MSC_VER) && _MSC_VER < 1310
  90. inline float abs(float v)
  91. {
  92. return(fabs(v));
  93. }
  94. inline double abs(double v)
  95. {
  96. return(fabs(v));
  97. }
  98. inline long double abs(long double v)
  99. {
  100. return(fabs(v));
  101. }
  102. #endif /* BOOST_WORKAROUND(BOOST_MSVC) */
  103. // explicit (if ludicrous) instanciation
  104. #if !BOOST_WORKAROUND(__GNUC__, < 3)
  105. template class ::boost::math::octonion<int>;
  106. #else
  107. // gcc doesn't like the absolutely-qualified namespace
  108. template class boost::math::octonion<int>;
  109. #endif /* !BOOST_WORKAROUND(__GNUC__) */
  110. namespace
  111. {
  112. template<typename T>
  113. ::boost::math::octonion<T> index_i_element(int idx)
  114. {
  115. return(
  116. ::boost::math::octonion<T>(
  117. (idx == 0) ?
  118. static_cast<T>(1) :
  119. static_cast<T>(0),
  120. (idx == 1) ?
  121. static_cast<T>(1) :
  122. static_cast<T>(0),
  123. (idx == 2) ?
  124. static_cast<T>(1) :
  125. static_cast<T>(0),
  126. (idx == 3) ?
  127. static_cast<T>(1) :
  128. static_cast<T>(0),
  129. (idx == 4) ?
  130. static_cast<T>(1) :
  131. static_cast<T>(0),
  132. (idx == 5) ?
  133. static_cast<T>(1) :
  134. static_cast<T>(0),
  135. (idx == 6) ?
  136. static_cast<T>(1) :
  137. static_cast<T>(0),
  138. (idx == 7) ?
  139. static_cast<T>(1) :
  140. static_cast<T>(0)
  141. ));
  142. }
  143. }
  144. void octonion_manual_test()
  145. {
  146. // tests for evaluation by humans
  147. // using default constructor
  148. ::boost::math::octonion<float> o0;
  149. ::boost::math::octonion<float> oa[2];
  150. // using constructor "O seen as R^8"
  151. ::boost::math::octonion<float> o1(1,2,3,4,5,6,7,8);
  152. ::std::complex<double> c0(9,10);
  153. // using constructor "O seen as C^4"
  154. ::boost::math::octonion<double> o2(c0);
  155. ::boost::math::quaternion<long double> q0(11,12,13,14);
  156. // using constructor "O seen as H^2"
  157. ::boost::math::octonion<long double> o3(q0);
  158. // using UNtemplated copy constructor
  159. ::boost::math::octonion<float> o4(o1);
  160. // using templated copy constructor
  161. ::boost::math::octonion<long double> o5(o2);
  162. // using UNtemplated assignment operator
  163. o5 = o3;
  164. oa[0] = o0;
  165. // using templated assignment operator
  166. o5 = o2;
  167. oa[1] = o5;
  168. float f0(15);
  169. // using converting assignment operator
  170. o0 = f0;
  171. // using converting assignment operator
  172. o2 = c0;
  173. // using converting assignment operator
  174. o5 = q0;
  175. // using += (const T &)
  176. o4 += f0;
  177. // using += (const ::std::complex<T> &)
  178. o2 += c0;
  179. // using += (const ::boost::math::quaternion<T> &)
  180. o3 += q0;
  181. // using += (const quaternion<X> &)
  182. o5 += o4;
  183. // using -= (const T &)
  184. o1 -= f0;
  185. // using -= (const ::std::complex<T> &)
  186. o2 -= c0;
  187. // using -= (const ::boost::math::quaternion<T> &)
  188. o5 -= q0;
  189. // using -= (const octonion<X> &)
  190. o3 -= o4;
  191. double d0(16);
  192. ::std::complex<double> c1(17,18);
  193. ::boost::math::quaternion<double> q1(19,20,21,22);
  194. // using *= (const T &)
  195. o2 *= d0;
  196. // using *= (const ::std::complex<T> &)
  197. o2 *= c1;
  198. // using *= (const ::boost::math::quaternion<T> &)
  199. o2 *= q1;
  200. // using *= (const octonion<X> &)
  201. o2 *= o4;
  202. long double l0(23);
  203. ::std::complex<long double> c2(24,25);
  204. // using /= (const T &)
  205. o5 /= l0;
  206. // using /= (const ::std::complex<T> &)
  207. o5 /= c2;
  208. // using /= (const quaternion<X> &)
  209. o5 /= q0;
  210. // using /= (const octonion<X> &)
  211. o5 /= o5;
  212. // using + (const T &, const octonion<T> &)
  213. ::boost::math::octonion<float> o6 = f0+o0;
  214. // using + (const octonion<T> &, const T &)
  215. ::boost::math::octonion<float> o7 = o0+f0;
  216. // using + (const ::std::complex<T> &, const quaternion<T> &)
  217. ::boost::math::octonion<double> o8 = c0+o2;
  218. // using + (const octonion<T> &, const ::std::complex<T> &)
  219. ::boost::math::octonion<double> o9 = o2+c0;
  220. // using + (const ::boost::math::quaternion<T>, const octonion<T> &)
  221. ::boost::math::octonion<long double> o10 = q0+o3;
  222. // using + (const octonion<T> &, const ::boost::math::quaternion<T> &)
  223. ::boost::math::octonion<long double> o11 = o3+q0;
  224. // using + (const quaternion<T> &,const quaternion<T> &)
  225. ::boost::math::octonion<float> o12 = o0+o4;
  226. // using - (const T &, const octonion<T> &)
  227. o6 = f0-o0;
  228. // using - (const octonion<T> &, const T &)
  229. o7 = o0-f0;
  230. // using - (const ::std::complex<T> &, const octonion<T> &)
  231. o8 = c0-o2;
  232. // using - (const octonion<T> &, const ::std::complex<T> &)
  233. o9 = o2-c0;
  234. // using - (const quaternion<T> &,const octonion<T> &)
  235. o10 = q0-o3;
  236. // using - (const octonion<T> &,const quaternion<T> &)
  237. o11 = o3-q0;
  238. // using - (const octonion<T> &,const octonion<T> &)
  239. o12 = o0-o4;
  240. // using * (const T &, const octonion<T> &)
  241. o6 = f0*o0;
  242. // using * (const octonion<T> &, const T &)
  243. o7 = o0*f0;
  244. // using * (const ::std::complex<T> &, const octonion<T> &)
  245. o8 = c0*o2;
  246. // using * (const octonion<T> &, const ::std::complex<T> &)
  247. o9 = o2*c0;
  248. // using * (const quaternion<T> &,const octonion<T> &)
  249. o10 = q0*o3;
  250. // using * (const octonion<T> &,const quaternion<T> &)
  251. o11 = o3*q0;
  252. // using * (const octonion<T> &,const octonion<T> &)
  253. o12 = o0*o4;
  254. // using / (const T &, const octonion<T> &)
  255. o6 = f0/o0;
  256. // using / (const octonion<T> &, const T &)
  257. o7 = o0/f0;
  258. // using / (const ::std::complex<T> &, const octonion<T> &)
  259. o8 = c0/o2;
  260. // using / (const octonion<T> &, const ::std::complex<T> &)
  261. o9 = o2/c0;
  262. // using / (const ::boost::math::quaternion<T> &, const octonion<T> &)
  263. o10 = q0/o3;
  264. // using / (const octonion<T> &, const ::boost::math::quaternion<T> &)
  265. o11 = o3/q0;
  266. // using / (const octonion<T> &,const octonion<T> &)
  267. o12 = o0/o4;
  268. // using + (const octonion<T> &)
  269. o4 = +o0;
  270. // using - (const octonion<T> &)
  271. o0 = -o4;
  272. // using == (const T &, const octonion<T> &)
  273. f0 == o0;
  274. // using == (const octonion<T> &, const T &)
  275. o0 == f0;
  276. // using == (const ::std::complex<T> &, const octonion<T> &)
  277. c0 == o2;
  278. // using == (const octonion<T> &, const ::std::complex<T> &)
  279. o2 == c0;
  280. // using == (const ::boost::math::quaternion<T> &, const octonion<T> &)
  281. q0 == o3;
  282. // using == (const octonion<T> &, const ::boost::math::quaternion<T> &)
  283. o3 == q0;
  284. // using == (const octonion<T> &,const octonion<T> &)
  285. o0 == o4;
  286. // using != (const T &, const octonion<T> &)
  287. f0 != o0;
  288. // using != (const octonion<T> &, const T &)
  289. o0 != f0;
  290. // using != (const ::std::complex<T> &, const octonion<T> &)
  291. c0 != o2;
  292. // using != (const octonion<T> &, const ::std::complex<T> &)
  293. o2 != c0;
  294. // using != (const ::boost::math::quaternion<T> &, const octonion<T> &)
  295. q0 != o3;
  296. // using != (const octonion<T> &, const ::boost::math::quaternion<T> &)
  297. o3 != q0;
  298. // using != (const octonion<T> &,const octonion<T> &)
  299. o0 != o4;
  300. BOOST_TEST_MESSAGE("Please input an octonion...");
  301. #ifdef BOOST_INTERACTIVE_TEST_INPUT_ITERATOR
  302. ::std::cin >> o0;
  303. if (::std::cin.fail())
  304. {
  305. BOOST_TEST_MESSAGE("You have entered nonsense!");
  306. }
  307. else
  308. {
  309. BOOST_TEST_MESSAGE("You have entered the octonion " << o0 << " .");
  310. }
  311. #else
  312. ::std::istringstream bogus("(1,2,3,4,5,6,7,8)");
  313. bogus >> o0;
  314. BOOST_TEST_MESSAGE("You have entered the octonion " << o0 << " .");
  315. #endif
  316. BOOST_TEST_MESSAGE("For this octonion:");
  317. BOOST_TEST_MESSAGE( "the value of the real part is "
  318. << real(o0));
  319. BOOST_TEST_MESSAGE( "the value of the unreal part is "
  320. << unreal(o0));
  321. BOOST_TEST_MESSAGE( "the value of the sup norm is "
  322. << sup(o0));
  323. BOOST_TEST_MESSAGE( "the value of the l1 norm is "
  324. << l1(o0));
  325. BOOST_TEST_MESSAGE( "the value of the magnitude (euclidian norm) is "
  326. << abs(o0));
  327. BOOST_TEST_MESSAGE( "the value of the (Cayley) norm is "
  328. << norm(o0));
  329. BOOST_TEST_MESSAGE( "the value of the conjugate is "
  330. << conj(o0));
  331. BOOST_TEST_MESSAGE( "the value of the exponential is "
  332. << exp(o0));
  333. BOOST_TEST_MESSAGE( "the value of the cube is "
  334. << pow(o0,3));
  335. BOOST_TEST_MESSAGE( "the value of the cosinus is "
  336. << cos(o0));
  337. BOOST_TEST_MESSAGE( "the value of the sinus is "
  338. << sin(o0));
  339. BOOST_TEST_MESSAGE( "the value of the tangent is "
  340. << tan(o0));
  341. BOOST_TEST_MESSAGE( "the value of the hyperbolic cosinus is "
  342. << cosh(o0));
  343. BOOST_TEST_MESSAGE( "the value of the hyperbolic sinus is "
  344. << sinh(o0));
  345. BOOST_TEST_MESSAGE( "the value of the hyperbolic tangent is "
  346. << tanh(o0));
  347. #ifdef BOOST_NO_TEMPLATE_TEMPLATES
  348. BOOST_TEST_MESSAGE( "no template templates, can't compute cardinal functions");
  349. #else /* BOOST_NO_TEMPLATE_TEMPLATES */
  350. BOOST_TEST_MESSAGE( "the value of the Sinus Cardinal (of index pi) is "
  351. << sinc_pi(o0));
  352. BOOST_TEST_MESSAGE( "the value of "
  353. << "the Hyperbolic Sinus Cardinal (of index pi) is "
  354. << sinhc_pi(o0));
  355. #endif /* BOOST_NO_TEMPLATE_TEMPLATES */
  356. BOOST_TEST_MESSAGE(" ");
  357. float rho = ::std::sqrt(4096.0f);
  358. float theta = ::std::atan(1.0f);
  359. float phi1 = ::std::atan(1.0f);
  360. float phi2 = ::std::atan(1.0f);
  361. float phi3 = ::std::atan(1.0f);
  362. float phi4 = ::std::atan(1.0f);
  363. float phi5 = ::std::atan(1.0f);
  364. float phi6 = ::std::atan(1.0f);
  365. BOOST_TEST_MESSAGE( "The value of the octonion represented "
  366. << "in spherical form by "
  367. << "rho = " << rho << " , theta = " << theta
  368. << " , phi1 = " << phi1 << " , phi2 = " << phi2
  369. << " , phi3 = " << phi3 << " , phi4 = " << phi4
  370. << " , phi5 = " << phi5 << " , phi6 = " << phi6
  371. << " is "
  372. << ::boost::math::spherical(rho, theta,
  373. phi1, phi2, phi3, phi4, phi5, phi6));
  374. float rho1 = 1;
  375. float rho2 = 2;
  376. float rho3 = ::std::sqrt(2.0f);
  377. float rho4 = ::std::sqrt(8.0f);
  378. float theta1 = 0;
  379. float theta2 = ::std::atan(1.0f)*2;
  380. float theta3 = ::std::atan(1.0f);
  381. float theta4 = ::std::atan(::std::sqrt(3.0f));
  382. BOOST_TEST_MESSAGE( "The value of the octonion represented "
  383. << "in multipolar form by "
  384. << "rho1 = " << rho1 << " , theta1 = " << theta1
  385. << " , rho2 = " << rho2 << " , theta2 = " << theta2
  386. << "rho3 = " << rho3 << " , theta3 = " << theta3
  387. << " , rho4 = " << rho4 << " , theta4 = " << theta4
  388. << " is "
  389. << ::boost::math::multipolar(rho1, theta1, rho2, theta2,
  390. rho3, theta3, rho4, theta4));
  391. float r = ::std::sqrt(2.0f);
  392. float angle = ::std::atan(1.0f);
  393. float h1 = 3;
  394. float h2 = 4;
  395. float h3 = 5;
  396. float h4 = 6;
  397. float h5 = 7;
  398. float h6 = 8;
  399. BOOST_TEST_MESSAGE( "The value of the octonion represented "
  400. << "in cylindrical form by "
  401. << "r = " << r << " , angle = " << angle
  402. << " , h1 = " << h1 << " , h2 = " << h2
  403. << " , h3 = " << h3 << " , h4 = " << h4
  404. << " , h5 = " << h5 << " , h6 = " << h6
  405. << " is " << ::boost::math::cylindrical(r, angle,
  406. h1, h2, h3, h4, h5, h6));
  407. double real_1(1);
  408. ::std::complex<double> complex_1(1);
  409. ::std::complex<double> complex_i(0,1);
  410. ::boost::math::quaternion<double> quaternion_1(1);
  411. ::boost::math::quaternion<double> quaternion_i(0,1);
  412. ::boost::math::quaternion<double> quaternion_j(0,0,1);
  413. ::boost::math::quaternion<double> quaternion_k(0,0,0,1);
  414. ::boost::math::octonion<double> octonion_1(1);
  415. ::boost::math::octonion<double> octonion_i(0,1);
  416. ::boost::math::octonion<double> octonion_j(0,0,1);
  417. ::boost::math::octonion<double> octonion_k(0,0,0,1);
  418. ::boost::math::octonion<double> octonion_e_prime(0,0,0,0,1);
  419. ::boost::math::octonion<double> octonion_i_prime(0,0,0,0,0,1);
  420. ::boost::math::octonion<double> octonion_j_prime(0,0,0,0,0,0,1);
  421. ::boost::math::octonion<double> octonion_k_prime(0,0,0,0,0,0,0,1);
  422. BOOST_TEST_MESSAGE(" ");
  423. BOOST_TEST_MESSAGE( "Real 1: " << real_1
  424. << " ; Complex 1: " << complex_1
  425. << " ; Quaternion 1: " << quaternion_1
  426. << " ; Octonion 1: " << octonion_1 << " .");
  427. BOOST_TEST_MESSAGE( "Complex i: " << complex_i
  428. << " ; Quaternion i: " << quaternion_i
  429. << " ; Octonion i : " << octonion_i << " .");
  430. BOOST_TEST_MESSAGE( "Quaternion j: " << quaternion_j
  431. << " ; Octonion j: " << octonion_j << " .");
  432. BOOST_TEST_MESSAGE( "Quaternion k: " << quaternion_k
  433. << " ; Octonion k: " << octonion_k << " .");
  434. BOOST_TEST_MESSAGE( "Quaternion e\': " << octonion_e_prime << " .");
  435. BOOST_TEST_MESSAGE( "Quaternion i\': " << octonion_i_prime << " .");
  436. BOOST_TEST_MESSAGE( "Quaternion j\': " << octonion_j_prime << " .");
  437. BOOST_TEST_MESSAGE( "Quaternion k\': " << octonion_k_prime << " .");
  438. BOOST_TEST_MESSAGE(" ");
  439. BOOST_TEST_MESSAGE( octonion_1*octonion_1 << " ; "
  440. << octonion_1*octonion_i << " ; "
  441. << octonion_1*octonion_j << " ; "
  442. << octonion_1*octonion_k << " ; "
  443. << octonion_1*octonion_e_prime << " ; "
  444. << octonion_1*octonion_i_prime << " ; "
  445. << octonion_1*octonion_j_prime << " ; "
  446. << octonion_1*octonion_k_prime << " ; ");
  447. BOOST_TEST_MESSAGE( octonion_i*octonion_1 << " ; "
  448. << octonion_i*octonion_i << " ; "
  449. << octonion_i*octonion_j << " ; "
  450. << octonion_i*octonion_k << " ; "
  451. << octonion_i*octonion_e_prime << " ; "
  452. << octonion_i*octonion_i_prime << " ; "
  453. << octonion_i*octonion_j_prime << " ; "
  454. << octonion_i*octonion_k_prime << " ; ");
  455. BOOST_TEST_MESSAGE( octonion_j*octonion_1 << " ; "
  456. << octonion_j*octonion_i << " ; "
  457. << octonion_j*octonion_j << " ; "
  458. << octonion_j*octonion_k << " ; "
  459. << octonion_j*octonion_e_prime << " ; "
  460. << octonion_j*octonion_i_prime << " ; "
  461. << octonion_j*octonion_j_prime << " ; "
  462. << octonion_j*octonion_k_prime << " ; ");
  463. BOOST_TEST_MESSAGE( octonion_k*octonion_1 << " ; "
  464. << octonion_k*octonion_i << " ; "
  465. << octonion_k*octonion_j << " ; "
  466. << octonion_k*octonion_k << " ; "
  467. << octonion_k*octonion_e_prime << " ; "
  468. << octonion_k*octonion_i_prime << " ; "
  469. << octonion_k*octonion_j_prime << " ; "
  470. << octonion_k*octonion_k_prime << " ; ");
  471. BOOST_TEST_MESSAGE( octonion_e_prime*octonion_1 << " ; "
  472. << octonion_e_prime*octonion_i << " ; "
  473. << octonion_e_prime*octonion_j << " ; "
  474. << octonion_e_prime*octonion_k << " ; "
  475. << octonion_e_prime*octonion_e_prime << " ; "
  476. << octonion_e_prime*octonion_i_prime << " ; "
  477. << octonion_e_prime*octonion_j_prime << " ; "
  478. << octonion_e_prime*octonion_k_prime << " ; ");
  479. BOOST_TEST_MESSAGE( octonion_i_prime*octonion_1 << " ; "
  480. << octonion_i_prime*octonion_i << " ; "
  481. << octonion_i_prime*octonion_j << " ; "
  482. << octonion_i_prime*octonion_k << " ; "
  483. << octonion_i_prime*octonion_e_prime << " ; "
  484. << octonion_i_prime*octonion_i_prime << " ; "
  485. << octonion_i_prime*octonion_j_prime << " ; "
  486. << octonion_i_prime*octonion_k_prime << " ; ");
  487. BOOST_TEST_MESSAGE( octonion_j_prime*octonion_1 << " ; "
  488. << octonion_j_prime*octonion_i << " ; "
  489. << octonion_j_prime*octonion_j << " ; "
  490. << octonion_j_prime*octonion_k << " ; "
  491. << octonion_j_prime*octonion_e_prime << " ; "
  492. << octonion_j_prime*octonion_i_prime << " ; "
  493. << octonion_j_prime*octonion_j_prime << " ; "
  494. << octonion_j_prime*octonion_k_prime << " ; ");
  495. BOOST_TEST_MESSAGE( octonion_k_prime*octonion_1 << " ; "
  496. << octonion_k_prime*octonion_i << " ; "
  497. << octonion_k_prime*octonion_j << " ; "
  498. << octonion_k_prime*octonion_k << " ; "
  499. << octonion_k_prime*octonion_e_prime << " ; "
  500. << octonion_k_prime*octonion_i_prime << " ; "
  501. << octonion_k_prime*octonion_j_prime << " ; "
  502. << octonion_k_prime*octonion_k_prime << " ; ");
  503. BOOST_TEST_MESSAGE(" ");
  504. BOOST_TEST_MESSAGE("i\'*(e\'*j) : "
  505. << octonion_i_prime*(octonion_e_prime*octonion_j) << " ;");
  506. BOOST_TEST_MESSAGE("(i\'*e\')*j : "
  507. << (octonion_i_prime*octonion_e_prime)*octonion_j << " ;");
  508. BOOST_TEST_MESSAGE(" ");
  509. }
  510. BOOST_TEST_CASE_TEMPLATE_FUNCTION(multiplication_test, T)
  511. {
  512. #if BOOST_WORKAROUND(__GNUC__, < 3)
  513. #else /* BOOST_WORKAROUND(__GNUC__, < 3) */
  514. using ::std::numeric_limits;
  515. using ::boost::math::abs;
  516. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  517. BOOST_TEST_MESSAGE("Testing multiplication for "
  518. << string_type_name<T>::_() << ".");
  519. BOOST_REQUIRE_PREDICATE(::std::less_equal<T>(),
  520. (abs(::boost::math::octonion<T>(1,0,0,0,0,0,0,0)*
  521. ::boost::math::octonion<T>(1,0,0,0,0,0,0,0)-
  522. static_cast<T>(1)))
  523. (numeric_limits<T>::epsilon()));
  524. for (int idx = 1; idx < 8; ++idx)
  525. {
  526. ::boost::math::octonion<T> toto = index_i_element<T>(idx);
  527. BOOST_REQUIRE_PREDICATE(::std::less_equal<T>(),
  528. (abs(toto*toto+static_cast<T>(1)))
  529. (numeric_limits<T>::epsilon()));
  530. }
  531. }
  532. BOOST_TEST_CASE_TEMPLATE_FUNCTION(exp_test, T)
  533. {
  534. #if BOOST_WORKAROUND(__GNUC__, < 3)
  535. #else /* BOOST_WORKAROUND(__GNUC__, < 3) */
  536. using ::std::numeric_limits;
  537. using ::std::atan;
  538. using ::boost::math::abs;
  539. #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
  540. BOOST_TEST_MESSAGE("Testing exp for "
  541. << string_type_name<T>::_() << ".");
  542. for (int idx = 1; idx < 8; ++idx)
  543. {
  544. ::boost::math::octonion<T> toto =
  545. static_cast<T>(4)*atan(static_cast<T>(1))*index_i_element<T>(idx);
  546. BOOST_CHECK_PREDICATE(::std::less_equal<T>(),
  547. (abs(exp(toto)+static_cast<T>(1)))
  548. (2*numeric_limits<T>::epsilon()));
  549. }
  550. }
  551. boost::unit_test::test_suite * init_unit_test_suite(int, char *[])
  552. {
  553. ::boost::unit_test::unit_test_log.
  554. set_threshold_level(::boost::unit_test::log_messages);
  555. boost::unit_test::test_suite * test =
  556. BOOST_TEST_SUITE("octonion_test");
  557. BOOST_TEST_MESSAGE("Results of octonion test.");
  558. BOOST_TEST_MESSAGE(" ");
  559. BOOST_TEST_MESSAGE("(C) Copyright Hubert Holin 2003-2005.");
  560. BOOST_TEST_MESSAGE("Distributed under the Boost Software License, Version 1.0.");
  561. BOOST_TEST_MESSAGE("(See accompanying file LICENSE_1_0.txt or copy at");
  562. BOOST_TEST_MESSAGE("http://www.boost.org/LICENSE_1_0.txt)");
  563. BOOST_TEST_MESSAGE(" ");
  564. #define BOOST_OCTONION_COMMON_GENERATOR(fct) \
  565. test->add(BOOST_TEST_CASE_TEMPLATE(fct##_test, test_types));
  566. #define BOOST_OCTONION_COMMON_GENERATOR_NEAR_EPS(fct) \
  567. test->add(BOOST_TEST_CASE_TEMPLATE(fct##_test, near_eps_test_types));
  568. #define BOOST_OCTONION_TEST \
  569. BOOST_OCTONION_COMMON_GENERATOR(multiplication) \
  570. BOOST_OCTONION_COMMON_GENERATOR_NEAR_EPS(exp)
  571. BOOST_OCTONION_TEST
  572. #undef BOOST_OCTONION_TEST
  573. #undef BOOST_OCTONION_COMMON_GENERATOR
  574. #undef BOOST_OCTONION_COMMON_GENERATOR_NEAR_EPS
  575. #ifdef BOOST_OCTONION_TEST_VERBOSE
  576. test->add(BOOST_TEST_CASE(octonion_manual_test));
  577. #endif /* BOOST_OCTONION_TEST_VERBOSE */
  578. return test;
  579. }
  580. #undef DEFINE_TYPE_NAME