Mercurial > projects > ldc
comparison tests/mini/dotproduct.d @ 341:1bb99290e03a trunk
[svn r362] Started merging the old 'test' dir as well as the newer 'tangotests' dir into 'tests/mini' and 'tests/minicomplex'.
author | lindquist |
---|---|
date | Sun, 13 Jul 2008 02:51:19 +0200 |
parents | test/dotproduct.d@d9d5d59873d8 |
children |
comparison
equal
deleted
inserted
replaced
340:351c0077d0b3 | 341:1bb99290e03a |
---|---|
1 extern(C) int printf(char*, ...); | |
2 | |
3 struct vec3 | |
4 { | |
5 float x,y,z; | |
6 | |
7 float dot(ref vec3 v) | |
8 { | |
9 return x*v.x + y*v.y + z*v.z; | |
10 } | |
11 | |
12 void print(char[] n) | |
13 { | |
14 printf("%.*s = vec3(%.4f, %.4f, %.4f)\n", n.length, n.ptr, x,y,z); | |
15 } | |
16 } | |
17 | |
18 int main() | |
19 { | |
20 printf("Dot Product test\n"); | |
21 | |
22 const f = 0.7071067811865474617; | |
23 vec3 v = vec3(f,f,0); | |
24 vec3 w = vec3(f,0,f); | |
25 | |
26 v.print("v"); | |
27 w.print("w"); | |
28 | |
29 auto dp = v.dot(w); | |
30 printf("v ยท w = %f\n", dp); | |
31 assert(dp > 0.4999 && dp < 0.5001); | |
32 | |
33 printf(" SUCCESS\n"); | |
34 return 0; | |
35 } | |
36 |