Directory: | ./ |
---|---|
File: | include/pinocchio/math/sincos.hpp |
Date: | 2025-02-12 21:03:38 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 16 | 16 | 100.0% |
Branches: | 2 | 4 | 50.0% |
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 | 1668264 | void SINCOS(const S1 & a, S2 * sa, S3 * ca) | |
28 | { | ||
29 | 1668264 | SINCOSAlgo<S1, S2, S3>::run(a, sa, ca); | |
30 | 1668264 | } | |
31 | |||
32 | /// \brief Generic evaluation of sin/cos functions. | ||
33 | template<typename S1, typename S2, typename S3> | ||
34 | struct SINCOSAlgo | ||
35 | { | ||
36 | 762 | static void run(const S1 & a, S2 * sa, S3 * ca) | |
37 | { | ||
38 | using std::cos; | ||
39 | using std::sin; | ||
40 |
1/2✓ Branch 2 taken 762 times.
✗ Branch 3 not taken.
|
762 | (*sa) = sin(a); |
41 |
1/2✓ Branch 2 taken 762 times.
✗ Branch 3 not taken.
|
762 | (*ca) = cos(a); |
42 | 762 | } | |
43 | }; | ||
44 | |||
45 | /// \brief Specific evaluation of sin/cos for double type. | ||
46 | template<> | ||
47 | struct SINCOSAlgo<double> | ||
48 | { | ||
49 | 1642144 | static void run(const double & a, double * sa, double * ca) | |
50 | { | ||
51 | #ifdef __linux__ | ||
52 | 1642144 | 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 | 1642144 | } | |
60 | }; | ||
61 | |||
62 | /// \brief Specific evaluation of sin/cos for float type. | ||
63 | template<> | ||
64 | struct SINCOSAlgo<float> | ||
65 | { | ||
66 | 1000 | static void run(const float & a, float * sa, float * ca) | |
67 | { | ||
68 | #ifdef __linux__ | ||
69 | 1000 | 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 | 1000 | } | |
77 | }; | ||
78 | |||
79 | /// \brief Specific evaluation of sin/cos for long double. | ||
80 | template<> | ||
81 | struct SINCOSAlgo<long double> | ||
82 | { | ||
83 | 1000 | static void run(const long double & a, long double * sa, long double * ca) | |
84 | { | ||
85 | #ifdef __linux__ | ||
86 | 1000 | 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 | 1000 | } | |
92 | }; | ||
93 | |||
94 | } // namespace pinocchio | ||
95 | |||
96 | #endif // #ifndef __pinocchio_math_sincos_hpp__ | ||
97 |