pinocchio  2.3.1-dirty
sincos.hpp
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 <boost/type_traits.hpp>
10 #include <cmath>
11 
12 namespace pinocchio
13 {
14  // Forward declaration
15  template<typename S1, typename S2 = S1, typename S3 = S1, bool value = boost::is_floating_point<S1>::value & boost::is_floating_point<S2>::value & boost::is_floating_point<S3>::value> struct SINCOSAlgo;
16 
26  template<typename S1, typename S2, typename S3>
27  void SINCOS(const S1 & a, S2 * sa, S3 * ca)
28  {
30  }
31 
33  template<typename S1, typename S2, typename S3, bool>
34  struct SINCOSAlgo
35  {
36  static void run(const S2 & a, S2 * sa, S3 * ca)
37  {
38  (*sa) = std::sin(a); (*ca) = std::cos(a);
39  }
40  };
41 
43  template<>
44  struct SINCOSAlgo<double>
45  {
46  static void run(const double & a, double * sa, double * ca)
47  {
48 #ifdef __linux__
49  sincos(a,sa,ca);
50 #elif __APPLE__
51  __sincos(a,sa,ca);
52 #else // if sincos specialization does not exist
53  (*sa) = std::sin(a); (*ca) = std::cos(a);
54 #endif
55  }
56  };
57 
59  template<>
60  struct SINCOSAlgo<float>
61  {
62  static void run(const float & a, float * sa, float * ca)
63  {
64 #ifdef __linux__
65  sincosf(a,sa,ca);
66 #elif __APPLE__
67  __sincosf(a,sa,ca);
68 #else // if sincosf specialization does not exist
69  (*sa) = std::sin(a); (*ca) = std::cos(a);
70 #endif
71  }
72  };
73 
75  template<>
76  struct SINCOSAlgo<long double>
77  {
78  static void run(const long double & a, long double * sa, long double * ca)
79  {
80 #ifdef __linux__
81  sincosl(a,sa,ca);
82 #else // if sincosl specialization does not exist
83  (*sa) = std::sin(a); (*ca) = std::cos(a);
84 #endif
85  }
86  };
87 
89  template<typename S1, typename S2, typename S3>
90  struct SINCOSAlgo<S1, S2, S3, false >
91  {
92  static void run(const S1 & a, S2 * sa, S3 * ca)
93  {
94  (*sa) = sin(a); (*ca) = cos(a);
95  }
96  };
97 
98 }
99 
100 #endif //#ifndef __pinocchio_math_sincos_hpp__
Generic evaluation of sin/cos functions.
Definition: sincos.hpp:15
void SINCOS(const S1 &a, S2 *sa, S3 *ca)
Computes sin/cos values of a given input scalar.
Definition: sincos.hpp:27
Main pinocchio namespace.
Definition: treeview.dox:24