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