Line |
Branch |
Exec |
Source |
1 |
|
|
// |
2 |
|
|
// Copyright (c) 2018-2019 INRIA |
3 |
|
|
// |
4 |
|
|
|
5 |
|
|
#include "pinocchio/fwd.hpp" |
6 |
|
|
#include "pinocchio/math/sincos.hpp" |
7 |
|
|
#include <cstdlib> |
8 |
|
|
|
9 |
|
|
#include "utils/macros.hpp" |
10 |
|
|
|
11 |
|
|
#include <boost/test/unit_test.hpp> |
12 |
|
|
#include <boost/utility/binary.hpp> |
13 |
|
|
|
14 |
|
|
namespace |
15 |
|
|
{ |
16 |
|
|
template<typename Scalar> |
17 |
|
|
Scalar sinCosTolerance(); |
18 |
|
|
|
19 |
|
|
template<> |
20 |
|
✗ |
inline float sinCosTolerance<float>() |
21 |
|
|
{ |
22 |
|
✗ |
return 1e-7f; |
23 |
|
|
} |
24 |
|
|
|
25 |
|
|
template<> |
26 |
|
✗ |
inline double sinCosTolerance<double>() |
27 |
|
|
{ |
28 |
|
✗ |
return 1e-15; |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
template<> |
32 |
|
✗ |
inline long double sinCosTolerance<long double>() |
33 |
|
|
{ |
34 |
|
✗ |
return 1e-19; |
35 |
|
|
} |
36 |
|
|
} // namespace |
37 |
|
|
|
38 |
|
|
template<typename Scalar> |
39 |
|
✗ |
void testSINCOS(int n) |
40 |
|
|
{ |
41 |
|
✗ |
for (int k = 0; k < n; ++k) |
42 |
|
|
{ |
43 |
|
|
Scalar sin_value, cos_value; |
44 |
|
✗ |
Scalar alpha = (Scalar)std::rand() / (Scalar)RAND_MAX; |
45 |
|
✗ |
pinocchio::SINCOS(alpha, &sin_value, &cos_value); |
46 |
|
|
|
47 |
|
✗ |
Scalar sin_value_ref = std::sin(alpha), cos_value_ref = std::cos(alpha); |
48 |
|
|
|
49 |
|
✗ |
BOOST_CHECK_CLOSE_FRACTION(sin_value, sin_value_ref, sinCosTolerance<Scalar>()); |
50 |
|
✗ |
BOOST_CHECK_CLOSE_FRACTION(cos_value, cos_value_ref, sinCosTolerance<Scalar>()); |
51 |
|
|
} |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE) |
55 |
|
|
|
56 |
|
✗ |
BOOST_AUTO_TEST_CASE(test_sincos) |
57 |
|
|
{ |
58 |
|
|
#ifndef NDEBUG |
59 |
|
✗ |
const int n = 1e3; |
60 |
|
|
#else |
61 |
|
|
const int n = 1e6; |
62 |
|
|
#endif |
63 |
|
✗ |
testSINCOS<float>(n); |
64 |
|
✗ |
testSINCOS<double>(n); |
65 |
|
✗ |
testSINCOS<long double>(n); |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
BOOST_AUTO_TEST_SUITE_END() |
69 |
|
|
|