Program Listing for File sincos.hpp
↰ Return to documentation for file (include/pinocchio/math/sincos.hpp
)
//
// Copyright (c) 2015-2020 CNRS INRIA
// Copyright (c) 2015 Wandercraft, 86 rue de Paris 91400 Orsay, France.
//
#ifndef __pinocchio_math_sincos_hpp__
#define __pinocchio_math_sincos_hpp__
#include <cmath>
namespace pinocchio
{
// Forward declaration
template<typename S1, typename S2 = S1, typename S3 = S1> struct SINCOSAlgo;
template<typename S1, typename S2, typename S3>
void SINCOS(const S1 & a, S2 * sa, S3 * ca)
{
SINCOSAlgo<S1,S2,S3>::run(a,sa,ca);
}
template<typename S1, typename S2, typename S3>
struct SINCOSAlgo
{
static void run(const S1 & a, S2 * sa, S3 * ca)
{
using std::sin; using std::cos;
(*sa) = sin(a); (*ca) = cos(a);
}
};
template<>
struct SINCOSAlgo<double>
{
static void run(const double & a, double * sa, double * ca)
{
#ifdef __linux__
sincos(a,sa,ca);
#elif __APPLE__
__sincos(a,sa,ca);
#else // if sincos specialization does not exist
(*sa) = std::sin(a); (*ca) = std::cos(a);
#endif
}
};
template<>
struct SINCOSAlgo<float>
{
static void run(const float & a, float * sa, float * ca)
{
#ifdef __linux__
sincosf(a,sa,ca);
#elif __APPLE__
__sincosf(a,sa,ca);
#else // if sincosf specialization does not exist
(*sa) = std::sin(a); (*ca) = std::cos(a);
#endif
}
};
template<>
struct SINCOSAlgo<long double>
{
static void run(const long double & a, long double * sa, long double * ca)
{
#ifdef __linux__
sincosl(a,sa,ca);
#else // if sincosl specialization does not exist
(*sa) = std::sin(a); (*ca) = std::cos(a);
#endif
}
};
}
#endif //#ifndef __pinocchio_math_sincos_hpp__