Created
February 22, 2012 22:35
-
-
Save sinannar/1888027 to your computer and use it in GitHub Desktop.
that is a driver code of library mathFromSinan.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using McLauren and Taylor series method to implement sinus,cosinus and so on...