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