
on Mon Aug 29 2011, alfC
On Monday, August 29, 2011 1:02:00 AM UTC-7, John Maddock wrote:
evaluate a polynomial approximation to the function:
To consider a trivial example, if T*T isn't a T, then one can't even
result = A + B* T + C * T^2 + D * T^3...
to give a concrete example, the root finding algorithm that started this thread uses a polynomial approximation to the function to greatly speed up finding the root (we can find the polynomial approximation and it's root algebraically once we have evaluated enough points in the function). It's this insight that makes the algorithm converge so rapidly compared to the alternatives, but requiring that T*T != T breaks the underlying assumptions not only in how it's implemented, but in how it actually works algorithmically.
The easy answer is that A, B, C and D are different types then. the types of A, B, C and D can be deduced from the type of T and the type of the result R, which are know at that point.
I think (and John can correct me if I'm mistaken) that the problem is that it's an iterative algorithm (and even if it isn't, you can imagine it is; many such functions are iterative). You have to go through that calculation a number of times that can only be known at runtime, each time feeding the last result back into the input, until it converges. So how do you know what the result type should be? At compile-time, you don't! And even if you could declare it, would it be meaningful? -- Dave Abrahams BoostPro Computing http://www.boostpro.com