You have touched on a subject that is near and dear to our hearts here. Our support engineers are typically electrical engineers and we tend to like math.

As far as polynomials go, the Rabbit should perform very well. We put together a short polynomial test using the pow() function from our math library, MATH.LIB. We ran the program on a BL2500 running at about 29 MHz with a Rabbit 3000 processor. In our calculations it took about 1/500th of a second to calculate the value of a 5th order polynomial.

Solution = a^5 + b^4 + c^3 + d^2 + e

That came out to about 2 ms on the BL2500’s 29 MHz processor and if you need that to be quicker, we can always look at faster devices up to about 60 MHz. It’s nice to know that they don’t call them Rabbit processors for nothing. For an 8-bit processor, the Rabbit is very good at floating point mathematics.

I think you will find that setting up calculations is very easy as well using our math functions.

solution = pow(a,5) + pow(b,4) + pow(c,3) + pow(d,2) + e;

Remember that a faster Rabbit processor will execute the code much faster as well.

Here is the code I used for my test:

/* A polynomial is a series of coefficients raised to different powers. In this case we are calculating the value of a Fifth Order Polynomial. solution = a^5 + b^4 + c^3 + d^2 + e^1 or the equivalent: solution = a^5 + b^4 + c^3 + d^2 + e */ main() { //Coefficients and solution float a,b,c,d,e, solution; //Used for timing the calculation unsigned long time_0, time_final; a = 3.14; //Pi b = -3.14; //negative Pi c = 2.718; //e d = -2.718; //negative e e = 6.022; //Avogadro's number x 10^23 time_0 = MS_TIMER; //Set start solution = pow(a,5) + pow(b,4) + pow(c,3) + pow(d,2) + e; time_final = MS_TIMER; //Set finish time printf("solution = %f\n",solution); printf("Total calculation time = %lu milliseconds\n",(time_final - time_0)); }

Obviously one calculation is not enough to characterize the performance of the Rabbit and I would amend the code to make the same calculation 1000 times to provide a more accurate sense of the processor’s ability.

For more information on the math functions click on **Help** in the main menu and then select **HTML Function Reference**, and then choose **Floating Point Math**. You will find a large collection of useful functions including trig functions like sin(), tan(), etc.

To look at nitty-gritty details about these functions press **CTRL-H** while in the Dynamic C program. Then scroll down on the right side of the **Library Function Lookup** window until you find the MATH.LIB option. From there you can browse through the advanced math functions we have available. If you are curious about how these are implemented you can click the **Edit** button to view the source code and the comments.

=========================================================================================================

We had a lot of response to the above information. Most of the responses made a minor change to our polynomial which is a more mathematically rigorous definition and I will include it here:

solution = a*x^4 + b*x^3 + c*x^2 + d*x + e

We also got plenty of tips on faster methods to evaluate the polynomial like the one shown here:

solution = ((((a*x+b)*x+c)*x+d)*x+e);

Another method of performing the same calculation would be:

f = a*(x*x*x*x);

f += b*(x*x*x);

f += c*(x*x);

f += d*x;

solution = f + e;

Here is a short program that compares three different methods of calculating a polynomial.

main() { //Coefficients and solution float a,b,c,d,e,f,x, solution, i; //Used for timing the calculation unsigned long time_0; float etime0, etime1; a = 3.14; //Pi b = -3.14; //negative Pi c = 2.718; //e d = -2.718; //negative e e = 6.022; //Avagadoro's number x 10^23 x = -6.022; //negative Avagadoro's number x 10^23 //First we time a for loop without a calculation to get a baseline time_0 = MS_TIMER; //Set start time for (i=0; i<1000; i++ ); etime1 = (float)(MS_TIMER-time_0); // elapsed time w/o calculation printf("METHOD ONE\n"); time_0 = MS_TIMER; //Set start time for (i=0; i<1000; i++ ) { solution = (a * pow(x,4)) + (b * pow(x,3)) + (c * pow(x,2)) + (d * x) + e; } etime0 = (float)(MS_TIMER-time_0); // elapsed time with calculation etime0 = (etime0-etime1)/1000.0; // calculate ms/iteration printf("solution = %f\n",solution); printf("Total iteration time = %f milliseconds\n", etime0); printf("\n\nMETHOD TWO\n"); time_0 = MS_TIMER; //Set start time for (i=0; i<1000; i++ ) { f = a*(x*x*x*x); f += b*(x*x*x); f += c*(x*x); f += d*x; solution = f + e; } etime0 = (float)(MS_TIMER-time_0); // elapsed time with calculation etime0 = (etime0-etime1)/1000.0; // calculate ms/iteration printf("solution = %f\n",solution); printf("Total iteration time = %f milliseconds\n", etime0); printf("\n\nMETHOD THREE\n"); time_0 = MS_TIMER; //Set start time for (i=0; i<1000; i++ ) { solution = ((((a*x+b)*x+c)*x+d)*x+e); } etime0 = (float)(MS_TIMER-time_0); // elapsed time with calculation etime0 = (etime0-etime1)/1000.0; // calculate ms/iteration printf("solution = %f\n",solution); printf("Total iteration time = %f milliseconds\n", etime0); }

I think you will find that while each answer produces the same result, but they execute at very different speeds.

Running the program shown here with an RCM 4300 the output produced is:

METHOD ONE solution = 4936.138100 Total iteration time = 0.510000 milliseconds METHOD TWO solution = 4936.138100 Total iteration time = 0.097000 milliseconds METHOD THREE solution = 4936.137600 Total iteration time = 0.053000 milliseconds

Last updated: Aug 23, 2017