-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
54 lines (41 loc) · 954 Bytes
/
test.cpp
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
#include <iostream>
class Vector {
protected:
float a,b,c;
public:
Vector(float a, float b, float c) {
this->a = a;
this->b = b;
this->c = c;
}
float dot(Vector other) {
return this->a * other.a + this->b * other.b + this->c * other.c;
}
Vector cross(Vector other) {
return Vector(
this->b * other.c - this->c * other.b,
this->c * other.a - this->a * other.c,
this->a * other.b - this->b * other.a
);
}
void print() {
std::cout << "[ " << this->a << ", " << this->b << ", " << this->c << " ]" << std::endl;
}
};
int main() {
Vector v1(1,2,3);
Vector v2(9,8,7);
unsigned int loops = 1e9;
unsigned int counter = 0;
v1.print();
v2.print();
std::cout << "looping " << loops << " times" << std::endl;
for(unsigned int i=0; i < loops; i++) {
v1.dot(v2);
v1.cross(v2);
counter++;
}
std::cout << "counter = " << counter << std::endl;
std::cout << v1.dot(v2) << std::endl;
v1.cross(v2).print();
}