I would like to evaluate a polynomial on a real time embedded system that has only 32 bit integer hardware. For this reason, I am trying to use fixed point arithmetic. How can I avoid overflows without also imposing ridiculous limitations on the parameters?
Suppose I have the coefficients a,b,c,d
and I want to evaluate
ax^3 + bx^2 + cx + d
for a certain range of x
.
Suppose the coefficients a,b,c,d
and the range for x
can be computed off-line and can be scaled to make whatever method I use to evaluate the polynomial work.
What can I do to avoid overflows but still have about 20 bits of precision in the result? If I do nothing, then even for small values of x (like 10,000) x^3 is 1,000,000,000,000 which won't fit in 32 bits.
To give an example, suppose I want to evaluate the polynomial
F(x) = ax^3
For x in range x=<0.0,1.0>
. I want F(0.0) = 0.0
and F(1.0) = 100.0
. But I also want the value of this function at 10,000
points in that range, so F(0.0001)
, F(0.0002)
etc.
If I want the result of F(x)
to always be accurate to the nearest integer, how should I evaluate F(x)
using only 32 bit integer math?