473,395 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Are there any template trigonometry functions?

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

Jul 7 '07 #1
2 1814
On 2007-07-07 16:25, Pe*******@gmail.com wrote:
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)
--
Erik Wikström
Jul 7 '07 #2
Pe*******@gmail.com wrote:
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, <cmathprovides 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
Jul 7 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: vpadial | last post by:
Hello, I want to build a library to help exporting c++ functions to a scripting languagge. The scripting language provides a function to register functions like: ANY f0() ANY f1(ANY) ANY...
9
by: Ann Huxtable | last post by:
I have the following code segment - which compiles fine. I'm just worried I may get run time probs - because it looks like the functions are being overloaded by the return types?. Is this Ok: ? ...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
5
by: StephQ | last post by:
This is from a thread that I posted on another forum some days ago. I didn't get any response, so I'm proposing it in this ng in hope of better luck :) The standard explanation is that pointer...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.