Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stack Of Tasks
pinocchio
Commits
fb18132b
Verified
Commit
fb18132b
authored
Oct 25, 2018
by
Justin Carpentier
Browse files
math/sincos: add overloading of sincos for {float,double, long double}
parent
f9415524
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/math/sincos.hpp
View file @
fb18132b
//
// Copyright (c) 2015-201
6
CNRS
// Copyright (c) 2015-201
8
CNRS
INRIA
// Copyright (c) 2015 Wandercraft, 86 rue de Paris 91400 Orsay, France.
//
// This file is part of Pinocchio
...
...
@@ -21,12 +21,82 @@
#include <cmath>
namespace
se3
{
/// Forward declaration
template
<
typename
Scalar
>
struct
SINCOSAlgo
;
///
/// \brief Computes sin/cos values of a given input scalar.
///
/// \tparam Scalar Type of the input/output variables
///
/// \param[in] a The input scalar from which we evalute the sin and cos.
/// \param[inout] sa Variable containing the sin of a.
/// \param[inout] ca Variable containing the cos of a.
///
template
<
typename
Scalar
>
void
SINCOS
(
const
Scalar
&
a
,
Scalar
*
sa
,
Scalar
*
ca
)
{
SINCOSAlgo
<
Scalar
>::
run
(
a
,
sa
,
ca
);
}
/// Generic evaluation of sin/cos functions.
template
<
typename
Scalar
>
struct
SINCOSAlgo
{
static
void
run
(
const
Scalar
&
a
,
Scalar
*
sa
,
Scalar
*
ca
)
{
(
*
sa
)
=
std
::
sin
(
a
);
(
*
ca
)
=
std
::
cos
(
a
);
}
};
/// Specific evaluation of sin/cos for double type.
template
<
>
struct
SINCOSAlgo
<
double
>
{
static
void
run
(
const
double
&
a
,
double
*
sa
,
double
*
ca
)
{
#ifdef __linux__
#define SINCOS sincos
sincos
(
a
,
sa
,
ca
);
#elif __APPLE__
#define SINCOS __sincos
__sincos
(
a
,
sa
,
ca
);
#else // if sincos specialization does not exist
#define SINCOS(a,sa,ca) (*sa) = std::sin(a); (*ca) = std::cos(a)
(
*
sa
)
=
std
::
sin
(
a
);
(
*
ca
)
=
std
::
cos
(
a
);
#endif
}
};
/// Specific evaluation of sin/cos for float type.
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
}
};
/// Specific evaluation of sin/cos for long double.
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 __math_sincos_hpp__
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment