Problem with C++ math
I have been programming with Java for a while and never ran into any problems using its math functions, but when I switched over to C++ I cant get any of them to work. Can anyone tell me what to include and how to use cosine , tangent , sine , atan ,etc.
First of all, you need to #include <cmath>
The functions are pretty straight forward. I googled this. It seems like a pretty good reference.
The functions are pretty straight forward. I googled this. It seems like a pretty good reference.
Bah real men write their own. (which i still havn't fixed)
The Serious Answer:
Cmath
#include <iostream>#include <math.h>#define PIENOTCAKE 3.1415926535897932384626433832795unsigned int factorial(unsigned int number){ unsigned int holder = number; unsigned int i = number; while (i>0) { if (i == 1) { break; } i--; holder *=i; } return holder;}long double getsigma(long double n, long double x){ //long double retvalue; //retvalue = ((pow(-1, n))/factorial(2*n + 1))*pow(x,2*n + 1); return ((pow(-1, n))/factorial(2*n + 1))*pow(x,2*n + 1);}int main(int argc, char *argv[]){ int i = 1; long double totaler; totaler = getsigma(0,PIENOTCAKE/3); while (i<15) { totaler += getsigma(i,PIENOTCAKE/3); i++; } std::cout << "Sine of PI/3: "<<totaler<<std::endl; system("pause"); return 0;}
The Serious Answer:
Cmath
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement