Jump to content
  • Advertisement
Sign in to follow this  
Sir Sapo

Problem with C++ math

This topic is 5462 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
Bah real men write their own. (which i still havn't fixed)

#include <iostream>
#include <math.h>

#define PIENOTCAKE 3.1415926535897932384626433832795

unsigned 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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!