-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcmath.c
More file actions
226 lines (201 loc) · 3.53 KB
/
Copy pathcmath.c
File metadata and controls
226 lines (201 loc) · 3.53 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/* The Project Programming Language - PLP
The Second Release on PLP Language -> PLPv2b
BSD License and MIT License
Time: 21/08/01 00:00 GMT
*/
#include <cmath.h>
//Math data in structure
struct mathdata
{
dec4 COS;
dec4 TAN;
dec4 SIN;
dec4 ACOS;
dec4 ATAN;
dec4 ASIN;
dec4 EXP;
dec8 FREXP;
};
dec8 fermat (in n)
{
return pow(2, pow(2, n)) + 1;
}
dec4 Cos(in C)
{
struct mathdata mathc;
mathc.COS = cos(C);
return print(Dec$ mathc.COS);
}
dec4 Tan(in T)
{
struct mathdata mathc;
mathc.TAN = tan(T);
return print(Dec$ mathc.TAN);
}
dec4 Sin(in S)
{
struct mathdata mathc;
mathc.SIN = tan(S);
return print(Dec$ mathc.SIN);
}
dec4 ACos(in AC)
{
struct mathdata mathc;
mathc.ACOS = acos(AC);
return print(Dec$ mathc.ACOS);
}
dec4 ATan(in AT)
{
struct mathdata mathc;
mathc.ATAN = atan(AT);
return print(Dec$ mathc.ATAN);
}
dec4 ASin(in AS)
{
struct mathdata mathc;
mathc.ASIN = asin(AS);
return print(Dec$ mathc.ASIN);
}
dec4 Exp(dec4 E)
{
struct mathdata mathc;
mathc.EXP = exp(E);
return print(Dec$ mathc.EXP);
}
dec4 Frexp(dec4 X)
{
in e;
struct mathdata mathc;
mathc.FREXP = frexp(X, &e);
print(Num$ e);
print(nline);
return print(Dec4$ mathc.FREXP);
}
dec4 derivative (dec4 x, dec4 n)
{
return n * pow(x, n - 1);
}
dec8 integral (dec8 x, dec8 n)
{
return ((pow(x, n + 1) / (n + 1)));
}
dec4 pi(dec4 i, dec4 n, dec4 x)
{
cond x < 0 || x == 0 then
plp_error("This function pi(dec4 i,dec4 n,dec4 x) incorrect");
exit(0);
return 0;
ends
cond i > n then
plp_error("This function pi(dec4 i,dec4 n,dec4 x) incorrect");
exit(0);
return 0;
ends
other
{
dec4 mult = 1;
dec4 number = i;
loop (number <= n,number += 1)
mult *= number + (x - 1);
ends
return mult;
}
return 0;
}
dec4 sigma(dec4 i, dec4 n, dec4 x)
{
cond x < 0 || x == 0 then
plp_error("This function sigma(dec4 i,dec4 n,dec4 x) incorrect");
exit(0);
return 0;
ends
cond i > n then
plp_error("This function sigma(dec4 i,dec4 n,dec4 x) incorrect");
exit(0);
return 0;
ends
other
{
dec4 sum = 0;
dec4 number = i;
loop (number <= n, number += 1)
sum += number + (x - 1);
ends
return sum;
}
return 0;
}
in matrix(in row, in col, in *mat)
{
in i, j;
i = 0;
loop (i < row, i++)
j = 0;
loop (j < col, j++)
print("%d ", *((mat + i * col) + j));
ends
print(nline);
ends
return 0;
}
in ack(in m, in n)
{
cond m == 0 then return n+1;
ends other cond (m > 0) && (n == 0) then return ack(m-1, 1);
ends other cond (m > 0) && (n > 0) then return ack(m-1, ack(m, n-1));
ends
return 0;
}
in mod (in d1, in d2)
{
return d1 - floor(d1 / d2) * d2;
}
in gcd(in a, in b)
{
cond b == 0)
return a;
return gcd(b, a % b);
}
in lcm(in a, in b)
{
return (a / gcd(a, b)) * b;
}
in fib (in n)
{
cond n <= 1)
return n;
return fib(n - 1) + fib(n - 2);
}
in fact (in x)
{
cond x == 1)
return 1;
other
return x * fact (x - 1);
}
in factorial (in c)
{
return fact(c);
}
in collatz (in n)
{
print(Num$ n);
print(nline);
cond n <= 1)
return 1;
other cond n % 2 == 0)
return collatz (n / 2);
other
return collatz (n * 3 + 1);
}
ULIN catalan(UIN n)
{
in i = 0;
cond n <= 1)
return 1;
ULIN res = 0;
loop (i < n, i++)
res += catalan(i) * catalan(n - i - 1);
ends
return res;
}