Are there any template trigonometry functions?

P

PengYu.UT

Hi,

I'm wondering if there are any template trigonometry functions in C++.
I used the following code for that purpose. But if the library has it,
it will be better.

Thanks,
Peng

#include <cmath>

template <typename T>
struct arctan2;

template <>
struct arctan2<double> {
static double doit(double y, double x) { return atan2(y, x); }
};

template <>
struct arctan2<float> {
static float doit(float y, float x) { return atan2f(y, x); }
};

template <>
struct arctan2<double> {
static long double doit(long double y, long double x) { return
atan2l(y, x); }
};




Thanks,
Peng
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

Hi,

I'm wondering if there are any template trigonometry functions in C++.
I used the following code for that purpose. But if the library has it,
it will be better.

What do you need parametrised versions for when there are overloaded ones?

The standard defines the following for atan2:

float atan2(float, float)
double atan2(double, double)
long double atan2(long double, long double)
 
K

Kai-Uwe Bux

Hi,

I'm wondering if there are any template trigonometry functions in C++.
I used the following code for that purpose. But if the library has it,
it will be better.

Thanks,
Peng

#include <cmath>

template <typename T>
struct arctan2;

template <>
struct arctan2<double> {
static double doit(double y, double x) { return atan2(y, x); }
};

template <>
struct arctan2<float> {
static float doit(float y, float x) { return atan2f(y, x); }
};

template <>
struct arctan2<double> {
static long double doit(long double y, long double x) { return
atan2l(y, x); }
};

In addition to the double-versions, <cmath> provides overloads of the
math-functions for float and long double [26.5/5-6]. Thus, there are
already overloads for atan2 with the following signatures:

float atan2 ( float, float );
double atan2 ( double, double );
long double atan2 ( long double, long double );



Best

Kai-Uwe Bux
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,085
Latest member
cryptooseoagencies

Latest Threads

Top