1 #!/usr/local/bin/rune -x
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.
10 alias stdio.File *stdout = stdio.stdout;
14 main(int ac, char **av)
16 # The iteration with floats will work but the error is so
17 # large an extra 44 loops will occur.
21 # With doubles it has enough precision and we can get an idea
22 # of the error that built up.
26 # With ldoubles it definitely has enough, and the error is
27 # significantly lower.
38 for (iter = 0.0F; iter < 100.0F; iter += 0.001F) {
39 stdout->format("Iteration %7.3f\n", iter);
42 stdout->format("Final count=%d fullprec %1.16f\n", count, iter);
51 for (iter = 0.0; iter < 100.0; iter += 0.001) {
52 stdout->format("Iteration %7.3f\n", iter);
55 stdout->format("Final count=%d fullprec %1.16f\n", count, iter);
64 for (iter = 0.0X; iter < 100.0X; iter += 0.001X) {
65 stdout->format("Iteration %7.3f\n", iter);
68 stdout->format("Final count=%d fullprec %1.16f\n", count, iter);