Mercurial > projects > dstress
annotate run/mini/arrayops4.d @ 1628:c6ef09dfba4d
add mini test set from ldc project
author | Moritz Warning <moritzwarning@web.de> |
---|---|
date | Mon, 10 Jan 2011 19:47:18 +0100 |
parents | |
children |
rev | line source |
---|---|
1628
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
1 void main() |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
2 { |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
3 auto a = new float[1024]; |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
4 auto b = new float[1024]; |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
5 auto c = new float[1024]; |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
6 |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
7 for (auto i=0; i<1024; i++) |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
8 { |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
9 a[i] = i; |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
10 b[i] = i*2; |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
11 c[i] = i*4; |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
12 } |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
13 |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
14 a[] = b[] + c[] / 2; |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
15 |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
16 foreach(i,v; a) |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
17 { |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
18 assert(eq(v, b[i] + c[i] / 2)); |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
19 } |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
20 } |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
21 |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
22 float abs(float x) |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
23 { |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
24 return x<0?-x:x; |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
25 } |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
26 bool eq(float a, float b) |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
27 { |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
28 return abs(a-b) <= float.epsilon; |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
29 } |