Having trouble implementing the concept of an derivative with an array of doubles

I am working on a class called polynomial, and one of the things I need to do in the class is find the derivative of polynomials. I use an array of doubles to represent the polynomials, such that the index corresponds to the power of 'x' and the data at that index corresponds to the coefficient. For example;

a0(x^0)+a1(x^1)+a2(x^2)...+an-1(x^n-1)+an(x^n)

is represented in an array of doubles as:

double fx[n];

fx[0] = a0
fx[1] = a1
...
fx[n] = an

To implement a derivative I am using the power rule, basically multiplying the index by the coefficient and store that in another array with the index decremented by one.

f'(x^3+3x^2+6x+2) = 3x^2+6x+6. <- another polynomial

Here is my code thus far. The relevant members are data* fx which holds the coefficients of the polynomial, and the polynomial* deriv which is supposed to point to that polynomials derivative. I am implementing a derivative chain down to x^1 in a recursive way, using the private constructor polynomial(const polynomial&, unsigned);

If I removed the fixed flag the elements that are showing up as zeros show up as rather odd numbers instead, something like 2.714e-308 or something similar. This is really odd and I don't know exactly why.

I am getting a warning about using this instruction deriv->solve(). I have a default unsigned parameter that is intended to be used to set the precision of another feature I haven't implemented. I am getting the warning:

[warning]converting to 'unsigned int' from 'double'

.

I don't really know what that means or if that is somehow effecting my code. If someone could help me implement the same concept in a better way I would appreciate it, as I suspect it is the cause of my problem somehow.

Thank you for any help. I am really stuck and could use a point in the right direction.

I realized just after you posted that my loop wasn't running enough times. I left polyDegree undecremented in the function call (so now its one larger) and changed my deriv constructor to the following. :

On line two - -6.000 should be - 2.000. Also, the last line output is incorrect as well, the second number should be a negative 24. I seem to have an issue with the first iteration of the loop but I am not sure what that issue is.

Also, when you say that the compiler will use zero, does this mean the function will be called with zero and my precision variable will be overwritten? Is this something I need to worry about?

Considering that you have - -6.000 instead of just + 6.000 suggest a problem in your printing function.

> Also, when you say that the compiler will use zero, does this mean the function will be called with zero and my precision variable will be overwritten? Is this something I need to worry about?
You ask for an integer, but passed a rational. The number will be truncated.
¿How does that affect your program? The variable is called precision but it's passed to a derive function (that we know ``exact'') that's called solve. Beats me.

I don't know how I didn't see the casting issue with solve(). Its like really obvious, but I completely looked over it for some reason... thank you. I am going to tentatively mark this thread as 'solved'.