GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/pinocchio/math/sincos.hpp Lines: 12 12 100.0 %
Date: 2024-04-26 13:14:21 Branches: 0 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> struct SINCOSAlgo;
15
16
  ///
17
  /// \brief Computes sin/cos values of a given input scalar.
18
  ///
19
  /// \tparam Scalar Type of the input/output variables
20
  ///
21
  /// \param[in] a The input scalar from which we evalute the sin and cos.
22
  /// \param[out] sa Variable containing the sin of a.
23
  /// \param[out] ca Variable containing the cos of a.
24
  ///
25
  template<typename S1, typename S2, typename S3>
26
886446
  void SINCOS(const S1 & a, S2 * sa, S3 * ca)
27
  {
28
886446
    SINCOSAlgo<S1,S2,S3>::run(a,sa,ca);
29
886446
  }
30
31
  /// \brief Generic evaluation of sin/cos functions.
32
  template<typename S1, typename S2, typename S3>
33
  struct SINCOSAlgo
34
  {
35
    static void run(const S1 & a, S2 * sa, S3 * ca)
36
    {
37
      using std::sin; using std::cos;
38
      (*sa) = sin(a); (*ca) = cos(a);
39
    }
40
  };
41
42
  /// \brief Specific evaluation of sin/cos for double type.
43
  template<>
44
  struct SINCOSAlgo<double>
45
  {
46
881446
    static void run(const double & a, double * sa, double * ca)
47
    {
48
#ifdef __linux__
49
881446
      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
881446
    }
56
  };
57
58
  /// \brief Specific evaluation of sin/cos for float type.
59
  template<>
60
  struct SINCOSAlgo<float>
61
  {
62
1000
    static void run(const float & a, float * sa, float * ca)
63
    {
64
#ifdef __linux__
65
1000
      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
1000
    }
72
  };
73
74
  /// \brief Specific evaluation of sin/cos for long double.
75
  template<>
76
  struct SINCOSAlgo<long double>
77
  {
78
1000
    static void run(const long double & a, long double * sa, long double * ca)
79
    {
80
#ifdef __linux__
81
1000
      sincosl(a,sa,ca);
82
#else // if sincosl specialization does not exist
83
      (*sa) = std::sin(a); (*ca) = std::cos(a);
84
#endif
85
1000
    }
86
  };
87
88
}
89
90
#endif //#ifndef __pinocchio_math_sincos_hpp__