I'm looking for comments on whether it would be useful, whether it won't be overly confusing (as the example can show, you can make a loop that contains an apparently pointless assignment that does change the rest) and whether people will consider it interesting. I'm not releasing the code for the dyn<> class yet, I'm going to hack it a bit more before I do. One of the problems (probably quite apparent from the outputs and the expressions) is that it fails in spectacularly unclear ways as well and that it can't combine expressions easily yet.
The output from the example:
Code: Select all
candy@blackbox:~/dyn$ g++ -o test test.cc
candy@blackbox:~/dyn$ ./test
0 0 0 -2
0.000000 0.000000 0.000000 -3.141593
25 0 25 23
25.000000 0.000000 25.000000 21.858407
25 0 25 23
25.000000 0.000000 25.000000 21.858407
25 29568 29593 29591
25.000000 29568.000000 29593.000000 29589.858407
25 14784 14809 14807
25.000000 14784.000000 14809.000000 14805.858407
25 9856 9881 9879
25.000000 9856.000000 9881.000000 9877.858407
25 7392 7417 7415
25.000000 7392.000000 7417.000000 7413.858407
25 5913 5938 5936
25.000000 5913.600000 5938.600000 5935.458407
25 4928 4953 4951
25.000000 4928.000000 4953.000000 4949.858407
25 4224 4249 4247
25.000000 4224.000000 4249.000000 4245.858407
25 3696 3721 3719
25.000000 3696.000000 3721.000000 3717.858407
25 3285 3310 3308
25.000000 3285.333333 3310.333333 3307.191741
25 2956 2981 2979
25.000000 2956.800000 2981.800000 2978.658407
25 2688 2713 2711
25.000000 2688.000000 2713.000000 2709.858407
candy@blackbox:~/dyn$
Code: Select all
#include <stdio.h>
#include "dynamic"
int main() {
dyn<int> w, x, y(29568);
dyn<int> a = w * w,
b = y / x,
z = a + b,
c = z - dyn<int>(2);
// dyn<double> d = w;
// dyn<double> e = x;
// dyn<double> f = y;
dyn<double> d, e, f(29568);
dyn<double> g = d * d,
h = f / e,
i = g + h,
j = i - dyn<double>(3.141592653589793);
printf("%d %d %d %d\n", (int)a, (int)b, (int)z, (int)c);
printf("%f %f %f %f\n", (double)g, (double)h, (double)i, (double)j);
w = 5;
d = 5;
printf("%d %d %d %d\n", (int)a, (int)b, (int)z, (int)c);
printf("%f %f %f %f\n", (double)g, (double)h, (double)i, (double)j);
for (int l = 0; l<12; l++) {
x = l;
e = l;
printf("%d %d %d %d\n", (int)a, (int)b, (int)z, (int)c);
printf("%f %f %f %f\n", (double)g, (double)h, (double)i, (double)j);
}
}