Skip to content

Instantly share code, notes, and snippets.

@sinannar
Created February 22, 2012 22:35
Show Gist options
  • Save sinannar/1888027 to your computer and use it in GitHub Desktop.
Save sinannar/1888027 to your computer and use it in GitHub Desktop.
that is a driver code of library mathFromSinan.h
#include <stdio.h>
#include "mathFromSinan.h"
int factorialForInt(const int __input_Value )
{
if( __input_Value == 0 || __input_Value == 1 )
return 1;
else
return __input_Value * factorialForInt(__input_Value-1);
}
double factorialForDouble(const double __input_Value )
{
if( __input_Value == 0 || __input_Value == 1 )
return 1;
else
return __input_Value * factorialForDouble(__input_Value-1);
}
double power(double _base,int _power)
{
double _temp = 1.0;
int i;
if(_power == 0)
return 1;
for(i=0;i<_power;++i)
_temp *= _base;
return _temp;
}
double ePowerForInt(int __input_Value)
{
int i;
double temp = 0;
for(i=0 ;i<__LIMIT_FOR_CALCULATION ;++i)
temp += (power(__input_Value,i) / factorialForInt(i));
return temp;
}
double ePowerForDouble(double __input_Value)
{
int i;
double temp = 0;
for(i=0 ;i<__LIMIT_FOR_CALCULATION ;++i)
temp += (power(__input_Value,i) / factorialForInt(i));
return temp;
}
double sinus(double _radyan_Degree)
{
int i;
double temp = 0;
for(i=0 ;i<__LIMIT_FOR_CALCULATION ;++i)
temp += ( ( power(-1,i) * power(_radyan_Degree,2*i+1) ) / ( factorialForInt(2*i+1) ) );
return temp;
}
double cosinus(double _radyan_Degree)
{
int i;
double temp = 0;
for(i=0 ;i<__LIMIT_FOR_CALCULATION ;++i)
temp += ( ( power(-1,i) * power(_radyan_Degree,2*i) ) / ( factorialForInt(2*i) ) );
return temp;
}
double tangent(double _radyan_Degree)
{
return sinus(_radyan_Degree) / cosinus(_radyan_Degree);
}
double cotangent(double _radyan_Degree)
{
return cosinus(_radyan_Degree) / sinus(_radyan_Degree);
}
#ifndef __MATH__LIBRARY__FROM__SINAN__NAR__
#define __MATH__LIBRARY__FROM__SINAN__NAR__
#define __LIMIT_FOR_CALCULATION 17
#include<stdio.h>
int factorialForInt(const int __input_Value );
double factorialForDouble(const double __input_Value );
double power(double _base,int _power);
double ePowerForInt(int __input_Value);
double ePowerForDouble(double __input_Value);
double sinus(double _radyan_Degree);
double cosinus(double _radyan_Degree);
double tangent(double _radyan_Degree);
double cotangent(double _radyan_Degree);
#endif
#include <stdio.h>
#include <math.h>
#include "mathFromSinan.h"
int main(void)
{
printf("\n");
printf("sinus from my own library\n");
printf("%.10f\n",sinus(0.5));
printf("from math.h library\n");
printf("%.10f\n\n",sin(0.5));
printf("cosinus from my own library\n");
printf("%.10f\n",cosinus(0.5));
printf("from math.h library\n");
printf("%.10f\n\n",cos(0.5));
printf("tangent from my own library\n");
printf("%.10f\n",tangent(0.5));
printf("from math.h library\n");
printf("%.10f\n\n",tan(0.5));
printf("cotangent from my own library\n");
printf("%.10f\n",cotangent(0.5));
printf("from math.h library\n");
printf("%.10f\n",cos(0.5)/sin(0.5));
printf("\n");
return 0;
}
@sinannar
Copy link
Author

Using McLauren and Taylor series method to implement sinus,cosinus and so on...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment