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