-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vector.ooc
75 lines (62 loc) · 1.31 KB
/
Vector.ooc
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
import structs/[Array,ArrayList]
import FNumber
TupleN: class {
size: Int
values: ArrayList<FNumber>
init: func(=size) {
printf("Created a vector of size 3\n")
values = ArrayList<FNumber> new(size)
}
print: func {
printf("(")
for(i in 0..size - 1) {
values[i] print()
printf(" | ")
}
values[size - 1] print()
printf(")")
}
}
operator + (v1,v2: TupleN) -> TupleN {
if(v1 size != v2 size) {
Exception new("Trying to add vectors of different size!!!") throw()
}
ret := TupleN new(v1 size)
for(i in 0..v1 size) {
ret values[i] = v1 values[i] + v1 values[i]
}
return ret
}
operator - (v1,v2: TupleN) -> TupleN {
if(v1 size != v2 size) {
Exception new("Trying to add vectors of different size!!!") throw()
}
ret := TupleN new(v1 size)
for(i in 0..v1 size) {
ret values[i] = v1 values[i] - v1 values[i]
}
return ret
}
operator * (v1:TupleN, n: Int) -> TupleN {
ret := TupleN new(v1 size)
for(fn in v1 values) {
ret values add(fn * n)
}
return ret
}
operator / (v1:TupleN, n: Int) -> TupleN {
ret := TupleN new(v1 size)
for(fn in v1 values) {
ret values add(fn / n)
}
return ret
}
operator = (v1: TupleN, vals: Array<FNumber>) {
printf("cacou\n")
}
/*
operator as (data: FNumber*, size: Int) -> TupleN {
tn := TupleN new(size)
for(i in 0..size) { tn values add(data[i]) }
}
*/