-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·106 lines (101 loc) · 3.6 KB
/
main.cpp
File metadata and controls
executable file
·106 lines (101 loc) · 3.6 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
/*
* Copyright (c) 2023, Sebastian (https://github.com/ProtoSebastian)
*
*/
#include "defs.hpp"
#include <iostream>
#include <cstdint>
#include <cinttypes>
#include <cmath>
#include <cstring>
int main(int argc, char** argv) {
char *strbuf0=nullptr, *strbuf1=nullptr; // my employment chances dropping to zero:
// print license
printf(" Copyright (c) 2023, Sebastian (https://github.com/ProtoSebastian)\n\n");
frac a(1,3), b(1,5), na(-1,3), nb(-1,5), c, d(60, 120);
printf("a=%s (+%f)\nb=%s (+%f)\n", a.make_cstring(&strbuf0), a.to_double(), b.make_cstring(&strbuf1), b.to_double());
c=a*b;
printf("a*b=%s (%+f)\n", c.make_cstring(&strbuf0), c.to_double());
c=a/b;
printf("a/b=%s (%+f)\n", c.make_cstring(&strbuf0), c.to_double());
c=b/a;
printf("b/a=%s (%+f)\n", c.make_cstring(&strbuf0), c.to_double());
printf("pow(a, b)=%+f\n", pow(a, b));
printf("pow(b, a)=%+f\n", pow(b, a));
c=pow(a, 2);
printf("pow(a, 2)=%s (%+f)\n", c.make_cstring(&strbuf0), c.to_double());
c=pow(b, 2);
printf("pow(b, 2)=%s (%+f)\n", c.make_cstring(&strbuf0), c.to_double());
c=pow(a, 3);
printf("pow(a, 3)=%s (%+f)\n", c.make_cstring(&strbuf0), c.to_double());
c=pow(b, 3);
printf("pow(b, 3)=%s (%+f)\n", c.make_cstring(&strbuf0), c.to_double());
c=a+b;
printf("a+b=%s (%+f)\n", c.make_cstring(&strbuf0), c.to_double());
c=a-b;
printf("a-b=%s (%+f)\n", c.make_cstring(&strbuf0), c.to_double());
c=b-a;
printf("b-a=%s (%+f)\n\n\n", c.make_cstring(&strbuf0), c.to_double());
printf("na=%s (%+f)\nnb=%s (%+f)\n", na.make_cstring(&strbuf0), na.to_double(), nb.make_cstring(&strbuf1), nb.to_double());
c=na*nb;
printf("na*nb=%s (%+f)\n", c.make_cstring(&strbuf0), c.to_double());
c=na/nb;
printf("na/nb=%s (%+f)\n", c.make_cstring(&strbuf0), c.to_double());
c=nb/na;
printf("nb/na=%s (%+f)\n", c.make_cstring(&strbuf0), c.to_double());
printf("pow(na, nb)=%+f\n", pow(na, nb));
printf("pow(nb, na)=%+f\n", pow(nb, na));
c=pow(na, 2);
printf("pow(na, 2)=%s (%+f)\n", c.make_cstring(&strbuf0), c.to_double());
c=pow(nb, 2);
printf("pow(nb, 2)=%s (%+f)\n", c.make_cstring(&strbuf0), c.to_double());
c=pow(na, 3);
printf("pow(na, 3)=%s (%+f)\n", c.make_cstring(&strbuf0), c.to_double());
c=pow(nb, 3);
printf("pow(nb, 3)=%s (%+f)\n", c.make_cstring(&strbuf0), c.to_double());
c=na+nb;
printf("na+nb=%s (%+f)\n", c.make_cstring(&strbuf0), c.to_double());
c=na-nb;
printf("na-nb=%s (%+f)\n", c.make_cstring(&strbuf0), c.to_double());
c=nb-na;
printf("nb-na=%s (%+f)\n", c.make_cstring(&strbuf0), c.to_double());
printf("d=%s (%+f)\n", d.make_cstring(&strbuf0), d.to_double());
d=d.simplify();
printf("d (simplified)=%s (%+f)\n", d.make_cstring(&strbuf0), d.to_double());
printf("GCD(+60, +120): +%" PRIu64 "\n", std::gcd<uint64_t>(60, 120));
/*uint64_t *primes1=prime_factors(60), *primes2=prime_factors(120), *commprimes;
if(primes1[0]>1ULL) {
printf("prime factors of 60 = {");
for(uint64_t i=1ULL;i<primes1[0];i++) {
printf("%" PRIu64, primes1[i]);
if(i!=primes1[0]-1)
printf(", ");
if(primes2[0]>1ULL) {
printf("}\n");
printf("prime factors of 120 = {");
for(uint64_t i=1ULL;i<primes2[0];i++) {
printf("%" PRIu64, primes2[i]);
if(i!=primes2[0]-1ULL)
printf(", ");
}
printf("}\n");
}
if((primes1[0]>1ULL)&&(primes2[0]>1ULL)) {
commprimes=common_elements(primes1, primes2);
if(commprimes[0]>1ULL) {
printf("common prime factors of 60 & 120 = {");
for(uint64_t i=1ULL;i<commprimes[0];i++) {
printf("%" PRIu64, commprimes[i]);
if(i!=commprimes[0]-1ULL)
printf(", ");
}
printf("}\n");
}
}
free(primes1);
free(primes2);
free(commprimes);*/
free(strbuf0);
free(strbuf1);
return 0;
}