sincos.cpp
Go to the documentation of this file.
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<> inline float sinCosTolerance<float>()
20  {
21  return 1e-7f;
22  }
23 
24  template<> inline double sinCosTolerance<double>()
25  {
26  return 1e-15;
27  }
28 
29  template<> inline long double sinCosTolerance<long double>()
30  {
31  return 1e-19;
32  }
33 }
34 
35 
36 template<typename Scalar>
37 void testSINCOS(int n)
38 {
39  for(int k = 0; k < n; ++k)
40  {
41  Scalar sin_value, cos_value;
42  Scalar alpha = (Scalar)std::rand()/(Scalar)RAND_MAX;
43  pinocchio::SINCOS(alpha,&sin_value,&cos_value);
44 
45  Scalar sin_value_ref = std::sin(alpha),
46  cos_value_ref = std::cos(alpha);
47 
48  BOOST_CHECK_CLOSE_FRACTION(sin_value, sin_value_ref, sinCosTolerance<Scalar>());
49  BOOST_CHECK_CLOSE_FRACTION(cos_value, cos_value_ref, sinCosTolerance<Scalar>());
50  }
51 }
52 
53 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
54 
56 {
57 #ifndef NDEBUG
58  const int n = 1e3;
59 #else
60  const int n = 1e6;
61 #endif
62  testSINCOS<float>(n);
63  testSINCOS<double>(n);
64  testSINCOS<long double>(n);
65 }
66 
67 BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(test_sincos)
Definition: sincos.cpp:55
SE3::Scalar Scalar
Definition: conversions.cpp:13
void SINCOS(const S1 &a, S2 *sa, S3 *ca)
Computes sin/cos values of a given input scalar.
Definition: sincos.hpp:26
void testSINCOS(int n)
Definition: sincos.cpp:37


pinocchio
Author(s):
autogenerated on Tue Jun 1 2021 02:45:04