Mercurial > projects > ldc
annotate test/dotproduct.d @ 86:fd32135dca3e trunk
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
Lots of bugfixes.
Added support for special foreach on strings.
Added std.array, std.utf, std.ctype and std.uni to phobos.
Changed all the .c files in the gen dir to .cpp (it *is* C++ after all)
author | lindquist |
---|---|
date | Sat, 03 Nov 2007 14:44:58 +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 |