forked from Open-Source-Community/iusegit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperations.h
130 lines (100 loc) · 2.2 KB
/
operations.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <math.h>
using namespace std;
#define PI 3.14159265
float _tan (float num1)
{
float result =tan(num1*PI/180);
return result;
}
float subtract(float num1, float num2)
{
float result = num1-num2 ;
return result;
}
float _sin(float rate)
{
float result,r;
r=rate/180;
int i=r;
if (i-r==0)
{
result=0;
}
else
{
result = sin ((rate*PI)/180);
}
return result;
}
double _log(double x)
{
return (log10(x));
}
double _log(double base, double x) {
return (double)(log(x) / log(base));
}
double powerfunction(double base, double power){
double f = base;
for (int i = 1; i < power; i++)
f *= base;
return f;
}
float factorial(float n)
{
float result=1;
for (float i =1;i<=n;i++){
result*=i;}
return result;
}
double _negate (double num){
return num*(-1);
}
double add (double n1 , double n2){
return n1+n2;
}
double root (double num){
return sqrt(num);
}
double divide(double n1 , n2){
if(n2!=0)
return n1/n2;
else cout<<"AN error";
return 0;
}
double absolute (double num){
return (num<0?-1*num:num);
}
unsigned long long factorial(double num){
unsigned long long fac=1;
for(int i = 1 ; i <= num ; i++)
fac*=i;
return fac;
}
long double ln(long double x)
{
//***********Variable Declarations************/
long double count = 0; //Keeps track of the count in the loop
long double totalValue = 0; //The summation of each polynomial evaluated
bool reciprocal = false; //Flag to use if greater than 2
long double precision = 9; //The the highest order of polynomial to use.
if (x > 2.0) //Use the rule -ln(1/x) == ln(x) to keep accuracy
{
x = 1 / x; //Change to using 1/x rather than x
reciprocal = true; //Flag as true (sign change is later)
}
while (count < precision)
{
totalValue += pow(-1, count + 1) * (pow((x-1),count)/count);
count++;
}
if (reciprocal == true)
totalValue * -1; //If reciprocal was used multiply by -1 to change sign
return totalValue;
}
double divide(double num1, double num2)
{
if(num2 == 0)
cout<<"Invalid, the second number must be > 0"<<endl;
double result = num1/num2;
return result;
}