Rune - Fix array passing, optimize constant array indices
[rune.git] / tests / format2.d
1 #!/usr/local/bin/rune -x
2 #
3 # Test floating point iterations via File.format.  Caller should generally
4 # grep for 'Final'.  Our increments purposefully do not divide nicely into
5 # a base-2 FP representation, so errors will build up.
6
7 import "sys";
8 import <stdio>;
9
10 alias stdio.File *stdout = stdio.stdout;
11
12 public
13 int
14 main(int ac, char **av)
15 {
16         # The iteration with floats will work but the error is so
17         # large an extra 44 loops will occur.
18         #
19         float_test();
20
21         # With doubles it has enough precision and we can get an idea
22         # of the error that built up.
23         #
24         double_test();
25
26         # With ldoubles it definitely has enough, and the error is
27         # significantly lower.
28         #
29         ldouble_test();
30 }
31
32 void
33 float_test()
34 {
35         float   iter;
36         int count;
37
38         for (iter = 0.0F; iter < 100.0F; iter += 0.001F) {
39                 stdout->format("Iteration %7.3f\n", iter);
40                 ++count;
41         }
42         stdout->format("Final count=%d fullprec %1.16f\n", count, iter);
43 }
44
45 void
46 double_test()
47 {
48         double  iter;
49         int count;
50
51         for (iter = 0.0; iter < 100.0; iter += 0.001) {
52                 stdout->format("Iteration %7.3f\n", iter);
53                 ++count;
54         }
55         stdout->format("Final count=%d fullprec %1.16f\n", count, iter);
56 }
57
58 void
59 ldouble_test()
60 {
61         ldouble iter;
62         int count;
63
64         for (iter = 0.0X; iter < 100.0X; iter += 0.001X) {
65                 stdout->format("Iteration %7.3f\n", iter);
66                 ++count;
67         }
68         stdout->format("Final count=%d fullprec %1.16f\n", count, iter);
69 }