Line |
Branch |
Exec |
Source |
1 |
|
|
// |
2 |
|
|
// Copyright (c) 2015-2020 CNRS INRIA |
3 |
|
|
// Copyright (c) 2015 Wandercraft, 86 rue de Paris 91400 Orsay, France. |
4 |
|
|
// |
5 |
|
|
|
6 |
|
|
#ifndef __pinocchio_math_sincos_hpp__ |
7 |
|
|
#define __pinocchio_math_sincos_hpp__ |
8 |
|
|
|
9 |
|
|
#include <cmath> |
10 |
|
|
|
11 |
|
|
namespace pinocchio |
12 |
|
|
{ |
13 |
|
|
// Forward declaration |
14 |
|
|
template<typename S1, typename S2 = S1, typename S3 = S1> |
15 |
|
|
struct SINCOSAlgo; |
16 |
|
|
|
17 |
|
|
/// |
18 |
|
|
/// \brief Computes sin/cos values of a given input scalar. |
19 |
|
|
/// |
20 |
|
|
/// \tparam Scalar Type of the input/output variables |
21 |
|
|
/// |
22 |
|
|
/// \param[in] a The input scalar from which we evalute the sin and cos. |
23 |
|
|
/// \param[out] sa Variable containing the sin of a. |
24 |
|
|
/// \param[out] ca Variable containing the cos of a. |
25 |
|
|
/// |
26 |
|
|
template<typename S1, typename S2, typename S3> |
27 |
|
66981 |
void SINCOS(const S1 & a, S2 * sa, S3 * ca) |
28 |
|
|
{ |
29 |
|
66981 |
SINCOSAlgo<S1, S2, S3>::run(a, sa, ca); |
30 |
|
66981 |
} |
31 |
|
|
|
32 |
|
|
/// \brief Generic evaluation of sin/cos functions. |
33 |
|
|
template<typename S1, typename S2, typename S3> |
34 |
|
|
struct SINCOSAlgo |
35 |
|
|
{ |
36 |
|
|
static void run(const S1 & a, S2 * sa, S3 * ca) |
37 |
|
|
{ |
38 |
|
|
using std::cos; |
39 |
|
|
using std::sin; |
40 |
|
|
(*sa) = sin(a); |
41 |
|
|
(*ca) = cos(a); |
42 |
|
|
} |
43 |
|
|
}; |
44 |
|
|
|
45 |
|
|
/// \brief Specific evaluation of sin/cos for double type. |
46 |
|
|
template<> |
47 |
|
|
struct SINCOSAlgo<double> |
48 |
|
|
{ |
49 |
|
66981 |
static void run(const double & a, double * sa, double * ca) |
50 |
|
|
{ |
51 |
|
|
#ifdef __linux__ |
52 |
|
66981 |
sincos(a, sa, ca); |
53 |
|
|
#elif __APPLE__ |
54 |
|
|
__sincos(a, sa, ca); |
55 |
|
|
#else // if sincos specialization does not exist |
56 |
|
|
(*sa) = std::sin(a); |
57 |
|
|
(*ca) = std::cos(a); |
58 |
|
|
#endif |
59 |
|
66981 |
} |
60 |
|
|
}; |
61 |
|
|
|
62 |
|
|
/// \brief Specific evaluation of sin/cos for float type. |
63 |
|
|
template<> |
64 |
|
|
struct SINCOSAlgo<float> |
65 |
|
|
{ |
66 |
|
✗ |
static void run(const float & a, float * sa, float * ca) |
67 |
|
|
{ |
68 |
|
|
#ifdef __linux__ |
69 |
|
✗ |
sincosf(a, sa, ca); |
70 |
|
|
#elif __APPLE__ |
71 |
|
|
__sincosf(a, sa, ca); |
72 |
|
|
#else // if sincosf specialization does not exist |
73 |
|
|
(*sa) = std::sin(a); |
74 |
|
|
(*ca) = std::cos(a); |
75 |
|
|
#endif |
76 |
|
|
} |
77 |
|
|
}; |
78 |
|
|
|
79 |
|
|
/// \brief Specific evaluation of sin/cos for long double. |
80 |
|
|
template<> |
81 |
|
|
struct SINCOSAlgo<long double> |
82 |
|
|
{ |
83 |
|
✗ |
static void run(const long double & a, long double * sa, long double * ca) |
84 |
|
|
{ |
85 |
|
|
#ifdef __linux__ |
86 |
|
✗ |
sincosl(a, sa, ca); |
87 |
|
|
#else // if sincosl specialization does not exist |
88 |
|
|
(*sa) = std::sin(a); |
89 |
|
|
(*ca) = std::cos(a); |
90 |
|
|
#endif |
91 |
|
|
} |
92 |
|
|
}; |
93 |
|
|
|
94 |
|
|
} // namespace pinocchio |
95 |
|
|
|
96 |
|
|
#endif // #ifndef __pinocchio_math_sincos_hpp__ |
97 |
|
|
|