add tan function in Array world

This commit is contained in:
Jason Newton 2011-02-03 14:34:40 +01:00
parent 1eae6d0fb9
commit d028262e06
4 changed files with 40 additions and 0 deletions

View File

@ -705,6 +705,26 @@ struct functor_traits<scalar_sin_op<Scalar> >
};
};
/** \internal
* \brief Template functor to compute the tan of a scalar
* \sa class CwiseUnaryOp, Cwise::tan()
*/
template<typename Scalar> struct scalar_tan_op {
EIGEN_EMPTY_STRUCT_CTOR(scalar_tan_op)
inline const Scalar operator() (const Scalar& a) const { return tan(a); }
typedef typename packet_traits<Scalar>::type Packet;
inline Packet packetOp(const Packet& a) const { return internal::ptan(a); }
};
template<typename Scalar>
struct functor_traits<scalar_tan_op<Scalar> >
{
enum {
Cost = 5 * NumTraits<Scalar>::MulCost,
PacketAccess = packet_traits<Scalar>::HasTan
};
};
/** \internal
* \brief Template functor to raise a scalar to a power
* \sa class CwiseUnaryOp, Cwise::pow

View File

@ -237,6 +237,10 @@ Packet psin(const Packet& a) { return sin(a); }
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
Packet pcos(const Packet& a) { return cos(a); }
/** \internal \returns the tan of \a a (coeff-wise) */
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
Packet ptan(const Packet& a) { return tan(a); }
/** \internal \returns the exp of \a a (coeff-wise) */
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
Packet pexp(const Packet& a) { return exp(a); }

View File

@ -93,6 +93,20 @@ sin() const
}
/** \returns an expression of the coefficient-wise tan of *this.
*
* Example: \include Cwise_tan.cpp
* Output: \verbinclude Cwise_tan.out
*
* \sa cos(), sin()
*/
inline const CwiseUnaryOp<internal::scalar_tan_op<Scalar>, Derived>
tan() const
{
return derived();
}
/** \returns an expression of the coefficient-wise power of *this to the given exponent.
*
* Example: \include Cwise_pow.cpp

View File

@ -0,0 +1,2 @@
Array3d v(M_PI, M_PI/2, M_PI/3);
cout << v.tan() << endl;