Mercurial > projects > ldc
annotate test/dotproduct.d @ 117:56a21f3e5d3e trunk
[svn r121] Finished ModuleInfo implementation.
Static ctors/dtors now work according to spec.
Changed class vtable types slightly in some cases. Overridden functions now always take the the type of the first class declaring the method as this parameter. This helps when using headers (w. implementation somewhere else)
author | lindquist |
---|---|
date | Mon, 26 Nov 2007 04:49:23 +0100 |
parents | 0c5f410d973c |
children | d9d5d59873d8 |
rev | line source |
---|---|
1 | 1 struct vec3 |
2 { | |
3 float x,y,z; | |
4 | |
5 float dot(ref vec3 v) | |
6 { | |
7 return x*v.x + y*v.y + z*v.z; | |
8 } | |
9 | |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
10 void print(char[] n) |
1 | 11 { |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
12 printf("%.*s = vec3(%.4f, %.4f, %.4f)\n", n.length, n.ptr, x,y,z); |
1 | 13 } |
14 } | |
15 | |
16 int main() | |
17 { | |
18 printf("Dot Product test\n"); | |
19 | |
66
0c5f410d973c
[svn r70] Fixed bug where correct calling convention was not set on calling aggregate methods
lindquist
parents:
4
diff
changeset
|
20 const f = 0.7071067811865474617; |
1 | 21 vec3 v = vec3(f,f,0); |
22 vec3 w = vec3(f,0,f); | |
23 | |
24 v.print("v"); | |
66
0c5f410d973c
[svn r70] Fixed bug where correct calling convention was not set on calling aggregate methods
lindquist
parents:
4
diff
changeset
|
25 w.print("w"); |
1 | 26 |
27 auto dp = v.dot(w); | |
28 printf("v ยท w = %f\n", dp); | |
29 assert(dp > 0.4999 && dp < 0.5001); | |
30 | |
31 printf(" SUCCESS\n"); | |
32 return 0; | |
33 } | |
34 |